# Using npm
$ npm install @eloquentiastudios/commentable-json
# Using yarn
$ yarn add @eloquentiastudios/commentable-json
# Using pnpm
$ pnpm i @eloquentiastudios/commentable-json
import { parseJsonWithComments, stringifyJsonWithComments } from '@eloquentiastudios/commentable-json';
const objectToBeCommented = {
foo: 'bar',
baz: 'qux',
};
const commentsForObject = {
_: 'This is a comment for the entire object',
foo: 'This is a comment for the foo property',
baz: 'This is a comment for the baz property',
}
const jsonWithComments = stringifyJsonWithComments(objectToBeCommented, commentsForObject);
// Parse the JSON with comments to get the original object
const parsedObject: typeof objectToBeCommented = parseJsonWithComments(jsonWithComments);
Should work on any Node.js version that supports ESM modules (i.e. type="module"
in package.json
).
Uses the MIT license.
See LICENSE for more information.