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

tson-serializer

v1.0.3

Published

Type-safe JSON serializer

Downloads

3

Readme

Features

  • Type Safety
  • Reference Relationship
  • Referenced ArrayBuffer in ArrayBufferView
  • Circular Reference
  • Extensible

Supported Types

The types listed below are supported by default.

Primitive values

Value properties

Fundamental objects

Numbers & dates

Text processing

Indexed Collections

Keyed collections

Structured data

Custom Types

const TSON=require('..');
class SuperMaxUltraBigUnlimitedNumber{
    constructor(x,y){
        this.x=BigInt(x);
        this.y=BigInt(y);
    }
};
const dumper=(value)=>value.x+'.'+value.y;
const loader=(data)=>new SuperMaxUltraBigUnlimitedNumber(...data.split('.'));
const matcher=(value)=>value instanceof SuperMaxUltraBigUnlimitedNumber;
const recursive=false;
TSON.register(SuperMaxUltraBigUnlimitedNumber, loader, dumper, matcher, recursive);

const raw=new SuperMaxUltraBigUnlimitedNumber("1234567891012345678910111","98765432109876543210222");
const tson=TSON.stringify(raw);
const result=TSON.parse(tson);
console.log('RAW',raw);
console.log('Result',result);
console.log('Text',tson);


// RAW SuperMaxUltraBigUnlimitedNumber {
//   x: 1234567891012345678910111n,
//   y: 98765432109876543210222n
// }
// Result SuperMaxUltraBigUnlimitedNumber {
//   x: 1234567891012345678910111n,
//   y: 98765432109876543210222n
// }
// Text {"type":"SuperMaxUltraBigUnlimitedNumber","data":"1234567891012345678910111.98765432109876543210222"}

Examples

const arrayBuffer=new ArrayBuffer(5);
const uint8Array=new Uint8Array(arrayBuffer,1,4);
uint8Array[0]=0x66;
uint8Array[1]=0xCC;
uint8Array[2]=0xFF;

const circle={
    circle:null as any,
    date:new Date(),
    arrayBuffer,
    uint8Array,
    set:new Set([arrayBuffer,uint8Array]),
    map:new Map([[arrayBuffer,uint8Array]])
}
circle.circle=circle;
const text=TSON.stringify(circle,null,2);
const result=TSON.parse(text);
console.log('Raw',circle);
console.log('Result',result);
console.log('Text',text);
  • Raw
Raw <ref *1> {
  circle: [Circular *1],
  date: 2022-05-22T04:37:07.505Z,
  arrayBuffer: ArrayBuffer { [Uint8Contents]: <00 66 cc ff 00>, byteLength: 5 },
  uint8Array: Uint8Array(4) [ 102, 204, 255, 0 ],
  set: Set(2) {
    ArrayBuffer { [Uint8Contents]: <00 66 cc ff 00>, byteLength: 5 },
    Uint8Array(4) [ 102, 204, 255, 0 ]
  },
  map: Map(1) {
    ArrayBuffer { [Uint8Contents]: <00 66 cc ff 00>, byteLength: 5 } => Uint8Array(4) [ 102, 204, 255, 0 ]
  }
}
  • Result
Result <ref *1> {
  circle: [Circular *1],
  date: 2022-05-22T04:37:07.505Z,
  arrayBuffer: ArrayBuffer { [Uint8Contents]: <00 66 cc ff 00>, byteLength: 5 },
  uint8Array: Uint8Array(4) [ 102, 204, 255, 0 ],
  set: Set(2) {
    ArrayBuffer { [Uint8Contents]: <00 66 cc ff 00>, byteLength: 5 },
    Uint8Array(4) [ 102, 204, 255, 0 ]
  },
  map: Map(1) {
    ArrayBuffer { [Uint8Contents]: <00 66 cc ff 00>, byteLength: 5 } => Uint8Array(4) [ 102, 204, 255, 0 ]
  }
}
  • Text
Text {
  "type": "Object",
  "data": {
    "circle": {
      "type": "$ref",
      "data": []
    },
    "date": {
      "type": "Date",
      "data": "2022-05-22T04:37:07.505Z"
    },
    "arrayBuffer": {
      "type": "ArrayBuffer",
      "data": [
        0,
        102,
        204,
        255,
        0
      ]
    },
    "uint8Array": {
      "type": "Uint8Array",
      "data": {
        "buffer": {
          "type": "$ref",
          "data": [
            "arrayBuffer"
          ]
        },
        "offset": {
          "type": "number",
          "data": 1
        },
        "length": {
          "type": "number",
          "data": 4
        }
      }
    },
    "set": {
      "type": "Set",
      "data": [
        {
          "type": "$ref",
          "data": [
            "arrayBuffer"
          ]
        },
        {
          "type": "$ref",
          "data": [
            "uint8Array"
          ]
        }
      ]
    },
    "map": {
      "type": "Map",
      "data": [
        {
          "type": "Array",
          "data": [
            {
              "type": "$ref",
              "data": [
                "arrayBuffer"
              ]
            },
            {
              "type": "$ref",
              "data": [
                "uint8Array"
              ]
            }
          ]
        }
      ]
    }
  }
}

License

MIT License