minimalistic, dead-simple object collection library
Go to file
Geoff Doty 9e6a3e5324 added dump() to export data to json file 2018-04-15 17:59:09 -04:00
dist added dump() to export data to json file 2018-04-15 17:59:09 -04:00
docs updated readme 2018-04-07 00:11:28 -04:00
src added dump() to export data to json file 2018-04-15 17:59:09 -04:00
test initial commit 2018-04-02 00:35:22 -04:00
.gitignore initial commit 2018-04-02 00:35:22 -04:00
.jshintrc added jshint 2018-04-02 07:21:54 -04:00
CONTRIBUTING.md updated docs 2018-04-02 07:21:19 -04:00
LICENSE updated docs 2018-04-02 07:21:19 -04:00
README.md added dump() to export data to json file 2018-04-15 17:59:09 -04:00
gulpfile.js added build task (gulp) 2018-04-07 00:12:28 -04:00
package-lock.json added build task (gulp) 2018-04-07 00:12:28 -04:00
package.json added dump() to export data to json file 2018-04-15 17:59:09 -04:00

README.md

Record.js

A minimalistic object collection library

Record.js aims to provide a lite, 2kb, zero-dependency collection utility to help build simple in-memory or local storage data records. Records are stored as arrays in a JSON object.

Records can export raw JSON records, with no internals, via .dump()

WIP

Not done yet!

Getting Started

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 retrieval 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 returns entry(s) added
`.remove(id object)`
`.find(id object)`
.dump() saves records to JSON file

Length (Count Records)

As Records are just plain JavaScript Arrays, you can use .length to determine the number of results returned, for example:

let cats = pets.find({"type": "cat"}); // []
cats.length;  // 0

NOTICE: find is special, changes based on what you pass in, an id, an object, or nothing at all

Options

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

npm test

Support

Please open an issue for support.

Contributing

Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines, there minimalistic;)

License

MIT