Giter VIP home page Giter VIP logo

sugar-json's Introduction

Sugar JSON

JSON plugin for Sugar JS

Usage

Unless you using Sugar in extended mode this plugin is pretty much useless.

See relevant parts of docs:

sugarjs.com/quickstart/#/ChoosingAMode

Do not use extended mode if you are developing a library or other form of middleware. This is due to both awareness of the global scope described above as well as potential conflicts with versioning if other versions of Sugar exist. Extended mode should only be used by end users.

sugarjs.com/docs/#/objectPrototype

If you're feeling adventurous (and you generally have control over the code in your project) you can force Sugar to extend Object.prototype at your own risk using the objectPrototype flag

sugarjs.com/extending

The decision to have a modified global state is one that the end user or team should be well aware of. Failing to do this leads to issues that can be difficult to track down.

tl;dr; using extend is dangerous for middleware and libraries, and extending objectPrototype is always dangerous

(don't tell people on stack overflow that you have done this unless you are very thick skinned)

Having said all that, if you are both adventurous, and in control, you can now easily convert from plain js objects to json strings and back with ease, in a chainable way...

Configure Sugar to extend prototypes, including Object.prototype

require('sugar').extend({
  objectPrototype: true
})

require('sugar-json')

... define an object ...

let obj = {cool: 'beans'}

... turn it into string, do some replacements, then turn it back to object ...

let res = obj.stringify().replace('a', 'i').replace('cool', 'human').objectify()

... test it out ...

console.log(res)
// -> { human: 'beins' }

sugar-json's People

Contributors

andrewplummer avatar billymoon avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.