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

@hiogawa/json-extra

v0.0.2-pre.5

Published

Simple and trivial alternative for [`@brillout/json-serializer`](https://github.com/brillout/json-serializer/), [`superjson`](https://github.com/blitz-js/superjson), etc...

Downloads

53

Readme

json-extra

Simple and trivial alternative for @brillout/json-serializer, superjson, etc...

Core ideas are based on @brillout/json-serializer but it employs an array-based encoding for special values, which makes it easy to support custom types and also provides human-readibility for custom containers.

example1

See ./misc/example.mjs

const input = [
  // standard json value
  null,
  true,
  123,
  "string",
  ["array"],
  { k: "v" },

  // special constants
  undefined,
  Infinity,
  -Infinity,
  NaN,
  0,
  -0,

  // extra types
  new Date("2023-08-17"),
  1234n,
  /^\d+/gms,

  // extra containers
  new Map([
    [0, new Date(0)],
    [1n, new Set([/a/g])],
  ]),
  new Set([0, new Date(0), new Map([[1n, /a/g]])]),

  // escape encoding collision
  ["!NaN", "collision"],
];
[
  null,
  true,
  123,
  "string",
  ["array"],
  {
    "k": "v"
  },
  ["!undefined", 0],
  ["!Infinity", 0],
  ["!-Infinity", 0],
  ["!NaN", 0],
  0,
  ["!-0", 0],
  ["!Date", "2023-08-17T00:00:00.000Z"],
  ["!BigInt", "1234"],
  ["!RegExp", ["^\\d+", "gms"]],
  [
    "!Map",
    [
      [0, ["!Date", "1970-01-01T00:00:00.000Z"]],
      [
        ["!BigInt", "1"],
        ["!Set", [["!RegExp", ["a", "g"]]]]
      ]
    ]
  ],
  [
    "!Set",
    [
      0,
      ["!Date", "1970-01-01T00:00:00.000Z"],
      [
        "!Map",
        [
          [
            ["!BigInt", "1"],
            ["!RegExp", ["a", "g"]]
          ]
        ]
      ]
    ]
  ],
  ["!", "!NaN", "collision"]
]
[
  null,
  true,
  123,
  "string",
  ["array"],
  {
    "k": "v"
  },
  "!undefined",
  "!Infinity",
  "!-Infinity",
  "!NaN",
  0,
  0,
  "!Date:2023-08-17T00:00:00.000Z",
  "!BigInt:1234",
  "!RegExp:/^\\d+/gms",
  "!Map:[\n  [\n    0,\n    \"!Date:1970-01-01T00:00:00.000Z\"\n  ],\n  [\n    \"!BigInt:1\",\n    \"!Set:[\\n  \\\"!RegExp:/a/g\\\"\\n]\"\n  ]\n]",
  "!Set:[\n  0,\n  \"!Date:1970-01-01T00:00:00.000Z\",\n  \"!Map:[\\n  [\\n    \\\"!BigInt:1\\\",\\n    \\\"!RegExp:/a/g\\\"\\n  ]\\n]\"\n]",
  ["!!NaN", "collision"]
]
{
  "json": [
    null,
    true,
    123,
    "string",
    ["array"],
    {
      "k": "v"
    },
    null,
    "Infinity",
    "-Infinity",
    "NaN",
    0,
    "-0",
    "2023-08-17T00:00:00.000Z",
    "1234",
    "/^\\d+/gms",
    [
      [0, "1970-01-01T00:00:00.000Z"],
      ["1", ["/a/g"]]
    ],
    [0, "1970-01-01T00:00:00.000Z", [["1", "/a/g"]]],
    ["!NaN", "collision"]
  ],
  "meta": {
    "values": {
      "6": ["undefined"],
      "7": ["number"],
      "8": ["number"],
      "9": ["number"],
      "11": ["number"],
      "12": ["Date"],
      "13": ["bigint"],
      "14": ["regexp"],
      "15": [
        "map",
        {
          "0.1": ["Date"],
          "1.0": ["bigint"],
          "1.1": [
            "set",
            {
              "0": ["regexp"]
            }
          ]
        }
      ],
      "16": [
        "set",
        {
          "1": ["Date"],
          "2": [
            "map",
            {
              "0.0": ["bigint"],
              "0.1": ["regexp"]
            }
          ]
        }
      ]
    },
    "referentialEqualities": {
      "15.1.0": ["16.2.0.0"]
    }
  }
}

example2: cyclic reference

See ./misc/reference.mjs

const parent = { children: new Map() };
const child1 = { parent };
const child2 = { parent, siblings: new Set([child1]) };
parent.children.set("foo", child1);
parent.children.set("bar", child2);
{
  "children": [
    "!Map",
    [
      [
        "foo",
        {
          "parent": ["!", 0]
        }
      ],
      [
        "bar",
        {
          "parent": ["!", 0],
          "siblings": ["!Set", [["!", 3]]]
        }
      ]
    ]
  ]
}
[
  {
    "children": 1
  },
  ["Map", 2, 3, 4, 5],
  "foo",
  {
    "parent": 0
  },
  "bar",
  {
    "parent": 0,
    "siblings": 6
  },
  ["Set", 3]
]