Giter Club home page Giter Club logo

stringy's Introduction

Stringy.js

Stringy.js will stringify your circular JS objects without complaint. Unfortunately it currently fails if the object hierarchy exceeds 30 total items.

Usage

var b = {foo: {bar: null}}

b.foo.bar = b // it's circular!

console.log("Filtering: ", b)
console.log(stringy.stringify(b)) // works!
console.log(JSON.stringify(b)) // exception

stringy's People

Contributors

highruned avatar

Stargazers

Kugell avatar Alι Aryαɴ avatar Anthony Qldp avatar Michael Wang 汪東陽 avatar Erik Astorga avatar Ralf Stich avatar Michael Allen Smith avatar Danylo Fedorov avatar Juan Vazquez avatar Anatoliy avatar Andy Chen avatar Murat Hosver avatar Serjoscha avatar  avatar  avatar kev zettler avatar kk avatar  avatar

Watchers

Eliza Zadura avatar

stringy's Issues

License is missing

I do not want to have any dependencies in my project so I do not want to import NPM PACKAGES ... but I can't copy-paste your code because it lacks a license ...

I will still use your code but I will not be able to ship it with my project...

or I can probably use the Stack OverFlow example (because it is under CC BY-SA 3.0):

function censor(censor) {
  var i = 0;

  return function(key, value) {
    if(i !== 0 && typeof(censor) === 'object' && typeof(value) == 'object' && censor == value) 
      return '[Circular]'; 

    if(i >= 29) // seems to be a harded maximum of 30 serialized objects?
      return '[Unknown]';

    ++i; // so we know we aren't using the original object anymore

    return value;  
  }
}

var b = {foo: {bar: null}};

b.foo.bar = b;

console.log("Censoring: ", b);

console.log("Result: ", JSON.stringify(b, censor(b)));

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.