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

arson

v0.2.6

Published

ARbitrary Structured Object Notation

Downloads

3,047

Readme

arson Build Status Greenkeeper badge

ARbitrary Structured Object Notation

Not to be confused with the criminal act of deliberately setting fire to property!

JSON is great until you need to encode an object with circular references:

var obj = {};
obj.self = obj;
JSON.stringify(obj); // throws

Throwing an exception is lame, but even worse is muddling along as if everything is ok:

var a = {};
var b = { foo: 42 };
a.x = a.y = b;
var c = JSON.parse(JSON.stringify(a));
assert.strictEqual(c.x, c.y); // fails

We need an object notation that supports circular and repeated references.

That's where ARSON comes in:

var a = {};
var b = { foo: 42 };
a.x = a.y = b;
var c = ARSON.parse(ARSON.stringify(a));
assert.strictEqual(c.x, c.y); // no problem!

ARSON is compact, often even more compact than JSON, because repeated objects are defined only once:

var a = {};
var b = { foo: 42 };
a.x = a.y = b;
ARSON.stringify(a); // [{"x":1,"y":1},{"foo":2},42] vs.
                    // {"x":{"foo":42},"y":{"foo":42}}

But that's not all! ARSON can also encode undefined, thanks to the fact that [][-1] is always undefined:

> ARSON.encode({foo:undefined})
'[{"foo":-1}]'
> ARSON.decode(_)
{ foo: undefined }

It can also encode array holes:

> ARSON.encode(Array(3).concat([4, 5]))
'[[-2,-2,-2,1,2],4,5]'
> ARSON.decode(_)
[ , , , 4, 5 ]

Buffers:

> ARSON.encode(new Buffer("asdf"))
'[["Buffer","YXNkZg==","base64"]]'
> ARSON.decode(_)
<Buffer 61 73 64 66>

Dates:

> ARSON.encode(new Date)
'[["Date","2016-02-02T00:25:36.886Z"]]'
> ARSON.decode(_)
Mon Feb 01 2016 19:25:36 GMT-0500 (EST)

RegExps:

> ARSON.encode(/asdf/img)
'[["RegExp","asdf","img"]]'
> ARSON.decode(_)
/asdf/gim

Sets:

> s = new Set
Set {}
> s.add(s)
Set { Set { Set { [Object] } } }
> ARSON.encode(s)
'[["Set",0]]'
> ARSON.decode(_)
Set { Set { Set { [Object] } } }
> _.has(_)
true

and Maps:

> m = new Map
Map {}
> m.set(1234, m)
Map { 1234 => Map { 1234 => Map { 1234 => [Object] } } }
> m.set(m, 5678)
Map {
  1234 => Map {
    1234 => Map {
      1234 => [Object],
      [Object] => 5678
    },
    Map {
      1234 => [Object],
      [Object] => 5678
    } => 5678
  },
  Map {
    1234 => Map {
      1234 => [Object],
      [Object] => 5678
    },
    Map {
      1234 => [Object],
      [Object] => 5678
    } => 5678
  } => 5678
}
> ARSON.encode(m)
'[["Map",1,2],[3,0],[0,4],1234,5678]'
> ARSON.decode(_)
Map {
  1234 => Map {
    1234 => Map {
      1234 => [Object],
      [Object] => 5678
    },
    Map {
      1234 => [Object],
      [Object] => 5678
    } => 5678
  },
  Map {
    1234 => Map {
      1234 => [Object],
      [Object] => 5678
    },
    Map {
      1234 => [Object],
      [Object] => 5678
    } => 5678
  } => 5678
}
> _.get(_.get(1234)) === 5678
true