1.0.2 • Published 7 years ago

string-to-obj v1.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

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...