diff --git a/README.md b/README.md index d48a4f0..f3e3720 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,69 @@ # Record.js -> A minimalistic dead-simple object collection library +> A minimalistic object collection library -Go kick the tires in [`dist/`](https://raw.githubusercontent.com/n2geoff/record.js/master/dist/record.min.js) +**Record.js** aims to provide a lite, *2kb*, *no dependency* collection utility to help build simple in-memory or local storage data sets. Records are stored as `JSON`. + +> SOON: ability to export json collections ## WIP Not done yet! -## API +## Getting Started -The public API is very simple, only really need 3 methods: `add`, `remove`, and `find`. +- [Download Library](https://raw.githubusercontent.com/n2geoff/record.js/master/dist/record.min.js), then... + + +create a new record collection (in-memory) + + const pets = new Record(); + +add something to the collection + + pets.add({"name": "Fluffy", "type": "cat"}); + // [{"id": "123fk91j7", "name": "Fluffy", "type": "cat"}] + +an `id` field is auto-generated if not provided, this allows easy record retrival via + + pets.find("123fk91j7"); + // [{"id": "123fk91j7", "name": "Fluffy", "type": "cat"}] + +you can also find items via properties like + + pets.find({"type": "cat"}); + // [{"id": "123fk91j7", "name": "Fluffy", "type": "cat"}] + +and you can remove items via + + pets.remove("123fk91j7"); + // [{"id": "123fk91j7", "name": "Fluffy", "type": "cat"}] + +so, no records, right? + + pets.find(); + // [] + +### API + +The public API is very simple, you really only 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 | +|---|---| +| `.add(object)` | Adds entry to collection and returns entry(s) 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 | +| `.count()` | returns number of records in collection | -> SEE: [API Documentation](docs/api.md) +> NOTICE: `find` is special, changes based on what you pass in, an id, an object, or nothing at all +- Additional [API Documentation](docs/api.md) ### Options - - store: localStorage KEY to use. + +Records.js constructor supports a few options passed in as an `object` + + - store: localStorage KEY to use. This actives localStorage if available + - debug: may logout useful information, maybe not;) ## Tests