npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json.decycled

v2.1.1

Published

Decycled versión for JSON.stringify, resolve circulars, Regexp, Errors and dates. Reverse by JSON.revive().

Downloads

286

Readme

JSON.decycled

license Build Status npm version Github release npm downloads

Languages:[EN,ES]

Add to JSON JS .decycled() and .revive() method. They are a version of JSON.stringify() and JSON.parse() respectively, but support objects with circular references, regular expressions, Error and Date objects and functions.

  • Nodes where exists cyclic redundancy [Circular: reference] value appears, reference is the point where begins the circular reference indicated in dot notation.
JSON.decycled (val [, functions] [, deep])

Return JSON of the JS object val

  • val (object) object to decycled.
  • functions (boolean): true to show properties that are a function reference. By default is false. This properties have the format [Function:nombre function] and are not attend by .revive() function.
  • deep (integer): depth of the object to be analyzed.
JSON.revive (*val*)

Transform JSON structure in a JS object. If JSON is the result of .decycled() function; Date, RegExp and Error objects will revive.

  • val (object) JSON to "revive" in a JS object.
require('json.decycled');

var obj = {
  a: {
    a1:{
      'String': "String",
      'undefined': undefined,
      'Number': 14,
      'null': null,
      'Boolean': true,
      'Date': new Date(),
      'Regexp': /x+/,
      'Error': new Error('Opss'),
      'Array': [1,2,3,4,5],
      'function': function Hello(){}
    },
    a2:{
      'List': [
        {x:'X1',y:'Y1',z:'Z1'},
        {x:'X2',y:'Y2',z:'Z2'},
        {x:'X3',y:'Y3',z:'Z3'}
      ]
    }
  },
  b: {},
  c: {}
};
obj.b.a = obj;
obj.a.a1['Recursion'] = obj.a.a1;
console.log(obj);
console.log(JSON.decycled(obj));
console.log(JSON.revive(JSON.decycled(obj)));

##Licence MIT


JSON.decycled (es)

Añade a JSON nativo de JS el método .decycled() y el método .revive(). Son una versión de JSON.stringify() y JSON.parse() respectivamente, pero compatible con objetos con referencias circulares, expresiones regulares, objetos de error, objetos date y funciones.

  • En los nodos donde exista redundancia cíclica aparecerá el valor [Circular: reference], donde reference es el punto donde comienza la referencia circular indicado en notación por puntos.
JSON.decycled (val [, functions] [, deep])

Devuelve un JSON del objeto JS val.

  • val (object) objeto a realizar el decycled.
  • functions (boolean): true para mostrar las propiedades que hacen referencia a funciones. Por defecto es false. Estas propiedades tendrán el formato [Function:nombre function] y no son atendidas por la función .revive().
  • deep (integer): profundidad del objeto a analizar.
JSON.revive (*val*)

Convierte la estructura JSON en un Objeto JS. Si la estructura JSON viene dada por la función .decycled() se recreará los objetos Date, RegExp y Error.

  • val (object) JSON a "revivir" en un objeto JS.
require('json.decycled');

var obj = {
  a: {
    a1:{
      'String': "String",
      'undefined': undefined,
      'Number': 14,
      'null': null,
      'Boolean': true,
      'Date': new Date(),
      'Regexp': /x+/,
      'Error': new Error('Opss'),
      'Array': [1,2,3,4,5],
      'function': function Hello(){}
    },
    a2:{
      'List': [
        {x:'X1',y:'Y1',z:'Z1'},
        {x:'X2',y:'Y2',z:'Z2'},
        {x:'X3',y:'Y3',z:'Z3'}
      ]
    }
  },
  b: {},
  c: {}
};
obj.b.a = obj;
obj.a.a1['Recursion'] = obj.a.a1;
console.log(obj);
console.log(JSON.decycled(obj));
console.log(JSON.revive(JSON.decycled(obj)));

##Licencia MIT