data-string-parser

0.1.5 • Public • Published

data-string-parser

Parses strings that looks like a series of key-value pairs separated with commas into shallow objects. It's handy for parsing data-attributes with multiple values. It handles definititions with or without double or single quotes, and it will automaticly cast numbers to numbers and false/true to booleans, if they aren't surrounded by quotes.

More details in the specifications generated from the test suite.

Usage

parseDataString('foo: bar, num: 1, isTrue: true, href: http://myserver');
// {foo: 'bar', num: 1, isTrue: true, href: 'http://myserver'}

UMD

The parser is wrapped with an UMD wrapper (https://github.com/umdjs/umd), so you can use it together with an AMD loader like Require.js, with node's require or just by including it in your scripts.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.5
    4
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.5
    4
  • 0.1.3
    2
  • 0.1.2
    2
  • 0.1.1
    1
  • 0.1.0
    2

Package Sidebar

Install

npm i data-string-parser

Weekly Downloads

11

Version

0.1.5

License

MIT

Last publish

Collaborators

  • nbostrom