Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.12 KB

README.md

File metadata and controls

44 lines (32 loc) · 1.12 KB

commentable-json

Quick Start

Installation

# Using npm
$ npm install @eloquentiastudios/commentable-json

# Using yarn
$ yarn add @eloquentiastudios/commentable-json

# Using pnpm
$ pnpm i @eloquentiastudios/commentable-json

Example Usage

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);

Supported Node.js Versions

Should work on any Node.js version that supports ESM modules (i.e. type="module" in package.json).

License

Uses the MIT license.

See LICENSE for more information.