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-immutable-bn

v0.4.5

Published

[![Build Status](https://travis-ci.org/avocode/json-immutable.svg)](https://travis-ci.org/avocode/json-immutable)

Downloads

3

Readme

JsonImmutable

Build Status

Immutable.JS structure-aware JSON serializer/deserializer built around the native JSON API.

Motivation

By using the native JSON API, Immutable.JS structures are serialized as plain objects and arrays with no type information. The goal was to preserve both Immutable.JS Iterable types (maps, lists, etc.) and Record types. immutable.Map supports and preserves key types while plain JavaScript object keys are coerced to strings. These types should also preserved.

Usage

Plain Objects and Primitive Types

const data = { 'a': 'b', 'c': 123, 'd': true }

// Serialize
const json = serialize(data)
// json == '{"a":"b","c":123,"d":true}'

// Deserialize
const result = deserialize(json)

Native Object Types

const data = { 'created_at': new Date('2016-09-08'), 'pattern': /iamnative/g }

// Serialize
const json = serialize(data)
// json == '{"created_at":{"__date":"2016-09-08T00:00:00Z"},"pattern":{"__regexp":"/iamnative/g"}}'

// Deserialize
const result = deserialize(json)

bignumber.js Types

let x = new BigNumber('1111222233334444555566');

// Serialize
const json = serialize(x)
// json == '{"__bignumber":1111222233334444555566}'

// Deserialize
const result = deserialize(json)

Immutable Records

const SampleRecord = immutable.Record(
  { 'a': 3, 'b': 4 },
  'SampleRecord'
)

const data = {
  'x': SampleRecord({ 'a': 5 }),
}

// Serialize
const json = serialize(data)
// json == '{"x":{"__record":"SampleRecord","data":{"a":5}}}'

// Deserialize
const result = deserialize(json, {
  recordTypes: {
    'SampleRecord': SampleRecord
  }
})

Record types can be named. This is utilized by the serializer/deserializer to revive immutable.Record objects. See the SampleRecord name passed into immutable.Record() as the second argument.

NOTE: When an unknown record type is encountered during deserialization, an error is thrown.

General Immutable Structures

const data = {
  'x': immutable.Map({
    'y': immutable.List.of(1, 2, 3)
  }),
}

// Serialization
const json = serialize(data)
// json == '{"x":{"__iterable":"Map","data":[["y",{"__iterable":"List","data":[1,2,3]"}]]}}'

// Deserialize
const result = deserialize(json)
  • Immutable structures, plain objects and primitive data can be safely composed together.

  • immutable.Map key type information is preserved as opposed to the bare JSON API.

NOTE: When an unknown Immutable iterable type is encountered during deserialization, an error is thrown. The supported types are List, Map, OrderedMap, Set, OrderedSet and Stack.

API

  • serialize()

    Arguments:

    • data: The data to serialize.
    • options={}: Serialization options.
      • pretty=false: Whether to pretty-print the result (2 spaces).

    Return value:

    • string: The JSON representation of the input (data).
  • deserialize()

    Arguments:

    • json: A JSON representation of data.
    • options={}: Deserialization options.
      • recordTypes={}: immutable.Record factories.

    Return value:

    • any: Deserialized data.

Streaming API

  • createSerializationStream()

    Arguments:

    • data: The data to serialize.
    • options={}: Serialization options.
      • pretty=false: Whether to pretty-print the result (2 spaces).
      • bigChunks=false: Whether the serialized data should only be split into chunks based on the reader speed. By default, each data structure level is processed in its own event loop microtask which.
        • NOTE: When bigChunks=true, a (possibly substantial) portion of the data is serialized synchronously.

    Return value:

    • stream.PassThrough<!Buffer>: A readable stream emitting the JSON representation of the input (data).

Running Tests

  1. Clone the repository.
  2. npm install
  3. npm test