updated readme

This commit is contained in:
Geoff Doty 2018-04-07 00:11:28 -04:00
parent c96a8ada50
commit 4bf15aa447
2 changed files with 128 additions and 105 deletions

View File

@ -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

View File

@ -1,103 +1,114 @@
# Record.JS ### Record.js API
- [constructor][1] - [constructor][1]
- [add][2] - [add][2]
- [find][3] - [find][3]
- [remove][4] - [remove][4]
- [count][5] - [count][5]
## constructor ## constructor
**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**
```javascript ```javascript
// create a new record (in-memory) // create a new record (in-memory)
let pets = new Record(); let pets = new Record();
``` ```
## add ```javascript
// create a new record (localStorage)
Add record to collection creating an sudo unique id if let pets = new Record({"store": "pets"});
one not provided ```
**Parameters** ## add
- `entry` **[Object][7]** object(s) you want to store Add record to collection creating an sudo unique id if
one not provided
**Examples**
**Parameters**
```javascript
// add pet to collection - `entry` **[Object][6]** object(s) you want to store
let dog = pets.add({"name": "Yonkers", "age": 5});
**Examples**
// [{"id": "14rj345k9", "name": "Yonkers", "age": 5}]
``` ```javascript
// add pet to collection
Returns **[array][6]** record added let dog = pets.add({"name": "Yonkers", "age": 5});
// > [{"id": "14rj345k9", "name": "Yonkers", "age": 5}]
## find ```
Finds records in collection by id or object filter. Returns **[object][6]** entry added
**Parameters** ## find
- `key` **([string][8] \| [number][9])** (optional) by id, or object Finds records in collection by id or object filter.
**Examples** **Parameters**
```javascript - `key` **([string][8] \| [number][9])** (optional) by id, or object
// find all
let all = collection.find(); **Examples**
```
```javascript
```javascript // find all
// find by id let all = collection.find();
let record = collection.find(1); ```
```
```javascript
```javascript // find by id
// filter by object let record = collection.find(1);
let dogs = collection.find({"type": "dog"}); ```
```
```javascript
Returns **[array][6]** matching records // filter by object
let dogs = collection.find({"type": "dog"});
## remove ```
- **See: [find][10]** Returns **[array][7]** matching records
Remove record(s) from collection. Leverages same functionality as `find` ## remove
**Parameters** Remove record(s) from collection. Leverages same functionality as `find`
- `entry` **any** (optional) **Parameters**
**Examples** - `entry` **any** (optional)
```javascript **Examples**
// remove all records by type
let removed = collection.remove({"type": "cat"}); ```javascript
``` // remove all records by type
let removed = collection.remove({"type": "cat"});
Returns **[array][6]** records removed // > []
```
## count
Returns **[array][7]** records removed
Returns **[number][9]** count of records in collection
## count
[1]: #constructor
Returns **[number][9]** count of records in collection
[2]: #add
[1]: #constructor
[3]: #find
[2]: #add
[4]: #remove
[3]: #find
[5]: #count
[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