1.0.1 • Published 4 years ago

parse-object v1.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

parse-object

Support parsing string contains object-liked syntax that can not be parsed by JSON.parse()

NPM JavaScript Style Guide

Sometimes, you receive string that has value like "{ sort: { date: 'DES' } }" and you want to parse it into an object. First solution would be, of course, JSON.parse(). However, your string is not valid JSON-formatted string so JSON.parse() will fail to parse it. That is the reason why I made this parse-object module.

Install

npm install --save parse-object

Usage

const parse = require('parse-object');

const str = "{ sort: { date: 'DES' } }";
console.log(parse(str)); // { sort: { date: 'DES' } }
console.log(JSON.parse(str)); // raise error

parse-object can also parse any output from JSON.stringify()

const parse = require('parse-object');

const stringified = JSON.stringify({ name: "me", id: 123456 });
console.log(parse(stringified)); //  { name: "me", id: 123456 }
1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago