Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including parse-keys-and-values-from-object-literal-strings with all npm packages installed. Try it out:

var parseKeysAndValuesFromObjectLiteralStrings = require("parse-keys-and-values-from-object-literal-strings")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

parse-keys-and-values-from-object-literal-strings v1.0.1

This method will parse-keys-and-values-from-object-literal-strings

Parse Keys And Values From Object Literal Strings

This library will turn a string like this:

'{ yeah : bro, no : dawg }'

Into:

[
    {
        key : 'yeah',
        value : 'bro'
    },
    {
        key : 'no',
        value : 'dawg'
    }
]

Thats it! Pretty cool huh?

Install it like so: npm install --save-dev parse-keys-and-values-from-object-literal-strings

I use it in my custom attribute library but it could be used in other places as well.

Inspiration: I was implementing something like this for my custom attribute library:

<div on-event='{ click : handleClick, mouseover : handleMouseOver, mouseOut : handleMouseOut }'></div>

Knockout.js does it. Angular does it. Jade does it. Ember does it. Why cant I do it too? Anyways, I reverse engineered it from knockout.js source code. Sue me.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free