remarks
v0.3.4
Published
JSON comments handling
Downloads
4
Readme
Remarks
Simple two-way conversion and maintenance of JSON comments
Installation
npm install --save remarks
Sample usage
/* Optionally takes a JSON string that should be an array */
var remarks;
// Example using knex
knex('post').select().where('id', id)
.then(post => new Remarks(post.comments))
.then(r => remarks = r);
// meanwhile, some time later...
remarks.add({ name: 'seikho', comment: 'i love remarks' });
knex('post')
.update({ comments: remarks.toString() })
.where('id', 'id');
.then(() => console.log('updated'));
API
constructor
constructor(json?: string)
add
Add a comment to the list of comments
function add(comment: T): void;
parse
Re-populate the array with entirely new comments
function parse(json: string): void;
toArray
Return a copy of the comments array
function toArray(): Array<T>;
toString
Return the comments as a JSON string
function toString(): string;
License
MIT