updated readme
This commit is contained in:
parent
c96a8ada50
commit
4bf15aa447
16
README.md
16
README.md
|
@ -8,9 +8,21 @@ Go kick the tires in [`dist/`](https://raw.githubusercontent.com/n2geoff/record.
|
||||||
|
|
||||||
Not done yet!
|
Not done yet!
|
||||||
|
|
||||||
## Docs
|
## API
|
||||||
|
|
||||||
- [docs](docs/api.md)
|
The public API is very simple, only really need 3 methods: `add`, `remove`, and `find`.
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
| --- | ---|
|
||||||
|
| `.add(object)` | Adds entry to collection and return entry added |
|
||||||
|
| `.remove(id|object)` | Removes entry(s) from collection and returns removed |
|
||||||
|
| `.find(id|object)` | find all, find by id, or find by filter, returns array of entries |
|
||||||
|
| `.count()` | returns number of records in collection |
|
||||||
|
|
||||||
|
> SEE: [API Documentation](docs/api.md)
|
||||||
|
|
||||||
|
### Options
|
||||||
|
- store: localStorage KEY to use.
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
|
|
37
docs/api.md
37
docs/api.md
|
@ -1,4 +1,4 @@
|
||||||
# Record.JS
|
### Record.js API
|
||||||
|
|
||||||
- [constructor][1]
|
- [constructor][1]
|
||||||
- [add][2]
|
- [add][2]
|
||||||
|
@ -10,10 +10,10 @@
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `init` **[array][6]** collection to start with
|
- `opts` **[object][6]**
|
||||||
- `opts` **[object][7]**
|
- `opts.store` **[object][6]** localStorage ID to use
|
||||||
- `opts.store` **[object][7]** localStorage ID to use
|
- `opts.debug` **[object][6]** show console logs
|
||||||
- `opts.debug` **[object][7]** show console logs
|
- `init` **[array][7]** collection to start with
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@
|
||||||
let pets = new Record();
|
let pets = new Record();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// create a new record (localStorage)
|
||||||
|
let pets = new Record({"store": "pets"});
|
||||||
|
```
|
||||||
|
|
||||||
## add
|
## add
|
||||||
|
|
||||||
Add record to collection creating an sudo unique id if
|
Add record to collection creating an sudo unique id if
|
||||||
|
@ -29,18 +34,17 @@ one not provided
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
- `entry` **[Object][7]** object(s) you want to store
|
- `entry` **[Object][6]** object(s) you want to store
|
||||||
|
|
||||||
**Examples**
|
**Examples**
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// add pet to collection
|
// add pet to collection
|
||||||
let dog = pets.add({"name": "Yonkers", "age": 5});
|
let dog = pets.add({"name": "Yonkers", "age": 5});
|
||||||
|
// > [{"id": "14rj345k9", "name": "Yonkers", "age": 5}]
|
||||||
// [{"id": "14rj345k9", "name": "Yonkers", "age": 5}]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[array][6]** record added
|
Returns **[object][6]** entry added
|
||||||
|
|
||||||
## find
|
## find
|
||||||
|
|
||||||
|
@ -67,12 +71,10 @@ let record = collection.find(1);
|
||||||
let dogs = collection.find({"type": "dog"});
|
let dogs = collection.find({"type": "dog"});
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[array][6]** matching records
|
Returns **[array][7]** matching records
|
||||||
|
|
||||||
## remove
|
## remove
|
||||||
|
|
||||||
- **See: [find][10]**
|
|
||||||
|
|
||||||
Remove record(s) from collection. Leverages same functionality as `find`
|
Remove record(s) from collection. Leverages same functionality as `find`
|
||||||
|
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
@ -84,9 +86,10 @@ Remove record(s) from collection. Leverages same functionality as `find`
|
||||||
```javascript
|
```javascript
|
||||||
// remove all records by type
|
// remove all records by type
|
||||||
let removed = collection.remove({"type": "cat"});
|
let removed = collection.remove({"type": "cat"});
|
||||||
|
// > []
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns **[array][6]** records removed
|
Returns **[array][7]** records removed
|
||||||
|
|
||||||
## count
|
## count
|
||||||
|
|
||||||
|
@ -101,3 +104,11 @@ Returns **[number][9]** count of records in collection
|
||||||
[4]: #remove
|
[4]: #remove
|
||||||
|
|
||||||
[5]: #count
|
[5]: #count
|
||||||
|
|
||||||
|
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
||||||
|
|
||||||
|
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
|
||||||
|
|
||||||
|
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
||||||
|
|
||||||
|
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||||
|
|
Loading…
Reference in New Issue