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

objecttonbt

v1.3.2

Published

Convert an object to Nbt.

Downloads

2

Readme

objecttonbt

Covert an object to a the Named Binary Tag file format.

This is a way to store data in a compressed way instead of useing json.

This implements what is said here!

Usage

First you must import the function to your code.

For Javascript

import { objectToNbt } from 'objecttonbt';

To convert an object just run the function with an object as an input.

const test = {};
objectToNbt(test);

It will always return a Buffer instance.

const test = {};
objectToNbt(test); // Should return Buffer <10, 0, 0, 0>

const test2 = {
    value: 10;
};
objectToNbt(test2); // Should return Buffer <10, 0, 0, 3, 5, 0, 118, 97, 108, 117, 101, 10, 0, 0, 0, 0>

Types

You can specify what type tag the value is going to be.

You can do this by making it a string an puting a specific character at the end.

Byte

const byte = {
    b: '10b';
}
objectToNbt(byte);

Short

const short = {
    s: '20s';
}
objectToNbt(short);

Int

const int = {
    i: 30; // Do not put an i at the end just a number value
}
objectToNbt(int);

Long

const long1 = {
    l: '40l';
}
objectToNbt(long1);
const long2 = {
    l: 40n; // You can use BigInts for longs
}
objectToNbt(long2);

Float

const float1 = {
    f: '50.1f';
}
objectToNbt(float1);
const float2 = {
    f: 60.2; // Number values that are floats will be converted to floats
}
objectToNbt(float2);

Double

const double = {
    d: '70.3d',
};
objectToNbt(double);

Arrays

If there are diffent types in an array it will cause an error.

Always make sure ever element in an array is the same type.

Byte Array

const byteArray = {
    ba: new Int8Array([35, -43, 76]),
};
objectToNbt(byteArray);

Int Array

const intArray = {
    ia: new Int32Array([-3214, 543, 7654]),
};
objectToNbt(intArray);

Long Array

const longArray = {
    la: new BigInt64Array([423n, -54645120n, 53453130n]),
};
objectToNbt(longArray);

Other

The data can only be long as the max buffer length.

Functions, Symbols, null, and undefined will default to an empty nameless int.