npm.io
0.3.4 • Published 11 years ago

remarks

Licence
MIT
Version
0.3.4
Deps
0
Vulns
0
Weekly
0

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

Keywords