string-to-obj
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

String-to-Obj

Build Status codecov license GitHub version

String to object properties parser for javascript

This module takes a string of key-value/value and transforms it to an object.

Depends:

⇢ lodash >= 4.17.4

Example:

const strToObject = require('str-to-obj');

const parser = new strToObject({
    trim: true,
    delimiters: {
        values: {
            default: ','
        },
        keyValue: ':'
    },
    blackhole: 'context'
});
console.log(parser.parse('tags:"db backup,systems" is:open is:active authors:johndoe,janedoe application crashes'));

/* Outputs:
[object Object] { 
  tags: ['db backup', 'systems'],
  is: ['open', 'active'],
  authors: ['johndoe', 'janedoe'],
  context: ['application', 'crashes']
}
*/

// if you are using `key=value` format:

const parser = new strToObject({
    delimiters: {
        keyValue: '='
    },
    blackhole: 'context'
});
console.log(parser.parse('tags="db backup,systems" is=open is=active authors=johndoe,janedoe application crashes'));

// will still output the same...

Dependencies (1)

Dev Dependencies (14)

Package Sidebar

Install

npm i string-to-obj

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • vjcagay
  • richmondwang