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

lzo-bjson

v1.0.3

Published

Data Serializer and Deserializer.

Downloads

2

Readme

LZO: Bjson

Data Serializer and Deserializer.

Sponsor Commitizen friendly TypeScript version Node.js version MIT Build Status - GitHub Actions

Installation

npm install lzo-bjson OR yarn add lzo-bjson

Usage

Just

import { Bjson } from 'lzo-bjson';

const bjson = new Bjson({});

const obj = bjson.stringify({ a: 1, b: 2, c: 3 });
const arr = bjson.stringify([1, 2, 3]);
const int = bjson.stringify(2023);
const bol = bjson.stringify(true);
const str = bjson.stringify('John Doe');

console.log(bjson.parse(obj), typeof bjson.parse(obj)); // { a: 1, b: 2, c: 3 } object
console.log(bjson.parse(arr), typeof bjson.parse(arr)); // [1, 2, 3] object
console.log(bjson.parse(int), typeof bjson.parse(int)); // 2023 number
console.log(bjson.parse(bol), typeof bjson.parse(bol)); // true boolean
console.log(bjson.parse(str), typeof bjson.parse(str)); // John Doe string
import { bjson } from 'lzo-bjson';

class Person {
  constructor(private name: string) {}

  public getName() {
    return this.name;
  }

  public setName(name: string) {
    this.name = name;
  }
}

const bjson = new Bjson({
  Person,
});

const person = new Person('John Doe');

const compressed = bjson.stringify(person); // Uint8Array
const decompressed = bjson.parse(compressed); // Person
console.log(decompressed.getName()); // John Doe

// ! Maintains class integrity

decompressed.setName('Jane Doe');
const compressed2 = bjson.stringify(decompressed); // Uint8Array
const decompressed2 = bjson.parse(compressed2); // Person
console.log(decompressed2.getName()); // Jane Doe

Maintaining Inheritance

import { bjson } from 'lzo-bjson';

class Person {
  constructor(protected name: string) {}

  public getName() {
    return this.name;
  }

  public setName(name: string) {
    this.name = name;
  }
}

class Hero extends Person {
  constructor(protected name: string, protected power: string) {
    super(name);
  }

  public getPower() {
    return this.power;
  }
}

const bjson = new Bjson({
  Person,
  Hero,
});

const person = new Hero('John Doe', 'Super Strength');

const compressed = bjson.stringify(person); // Uint8Array
const decompressed = bjson.parse<Hero>(compressed); // Person
console.log(decompressed.getName()); // John Doe
console.log(decompressed.getPower()); // Super Strength

API

Bjson.getMaxDepth(): number

Get the maximum depth of the object

Bjson.makeDeepCopy<T>(object: T): T

Make a deep copy of the object

Bjson.stringify<T>(value: T): Uint8Array

Stringify the object to Uint8Array

Bjson.parse<T>(json: Uint8Array): T

Parse the Uint8Array to object maintaining the prototype chain

Backers & Sponsors

Support this project by becoming a sponsor.

License

Licensed under the MIT. See the LICENSE file for details.