diff --git a/README.md b/README.md index 6d6b876..d48a4f0 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,21 @@ Go kick the tires in [`dist/`](https://raw.githubusercontent.com/n2geoff/record. 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 diff --git a/docs/api.md b/docs/api.md index eddc85c..972dadf 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,103 +1,114 @@ -# Record.JS - -- [constructor][1] -- [add][2] -- [find][3] -- [remove][4] -- [count][5] - -## constructor - -**Parameters** - -- `init` **[array][6]** collection to start with -- `opts` **[object][7]** - - `opts.store` **[object][7]** localStorage ID to use - - `opts.debug` **[object][7]** show console logs - -**Examples** - -```javascript -// create a new record (in-memory) -let pets = new Record(); -``` - -## add - -Add record to collection creating an sudo unique id if -one not provided - -**Parameters** - -- `entry` **[Object][7]** object(s) you want to store - -**Examples** - -```javascript -// add pet to collection -let dog = pets.add({"name": "Yonkers", "age": 5}); - -// [{"id": "14rj345k9", "name": "Yonkers", "age": 5}] -``` - -Returns **[array][6]** record added - -## find - -Finds records in collection by id or object filter. - -**Parameters** - -- `key` **([string][8] \| [number][9])** (optional) by id, or object - -**Examples** - -```javascript -// find all -let all = collection.find(); -``` - -```javascript -// find by id -let record = collection.find(1); -``` - -```javascript -// filter by object -let dogs = collection.find({"type": "dog"}); -``` - -Returns **[array][6]** matching records - -## remove - -- **See: [find][10]** - -Remove record(s) from collection. Leverages same functionality as `find` - -**Parameters** - -- `entry` **any** (optional) - -**Examples** - -```javascript -// remove all records by type -let removed = collection.remove({"type": "cat"}); -``` - -Returns **[array][6]** records removed - -## count - -Returns **[number][9]** count of records in collection - -[1]: #constructor - -[2]: #add - -[3]: #find - -[4]: #remove - -[5]: #count +### Record.js API + +- [constructor][1] +- [add][2] +- [find][3] +- [remove][4] +- [count][5] + +## constructor + +**Parameters** + +- `opts` **[object][6]** + - `opts.store` **[object][6]** localStorage ID to use + - `opts.debug` **[object][6]** show console logs +- `init` **[array][7]** collection to start with + +**Examples** + +```javascript +// create a new record (in-memory) +let pets = new Record(); +``` + +```javascript +// create a new record (localStorage) +let pets = new Record({"store": "pets"}); +``` + +## add + +Add record to collection creating an sudo unique id if +one not provided + +**Parameters** + +- `entry` **[Object][6]** object(s) you want to store + +**Examples** + +```javascript +// add pet to collection +let dog = pets.add({"name": "Yonkers", "age": 5}); +// > [{"id": "14rj345k9", "name": "Yonkers", "age": 5}] +``` + +Returns **[object][6]** entry added + +## find + +Finds records in collection by id or object filter. + +**Parameters** + +- `key` **([string][8] \| [number][9])** (optional) by id, or object + +**Examples** + +```javascript +// find all +let all = collection.find(); +``` + +```javascript +// find by id +let record = collection.find(1); +``` + +```javascript +// filter by object +let dogs = collection.find({"type": "dog"}); +``` + +Returns **[array][7]** matching records + +## remove + +Remove record(s) from collection. Leverages same functionality as `find` + +**Parameters** + +- `entry` **any** (optional) + +**Examples** + +```javascript +// remove all records by type +let removed = collection.remove({"type": "cat"}); +// > [] +``` + +Returns **[array][7]** records removed + +## count + +Returns **[number][9]** count of records in collection + +[1]: #constructor + +[2]: #add + +[3]: #find + +[4]: #remove + +[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