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

@cch137/shuttle

v0.2.4

Published

`@cch137/shuttle` is a lightweight TypeScript library designed for efficient serialization and deserialization of complex data structures. It supports various data types including numbers, strings, arrays, objects, sets, maps, and more. Shuttle also provi

Downloads

337

Readme

@cch137/shuttle

Overview

@cch137/shuttle is a lightweight TypeScript library designed for efficient serialization and deserialization of complex data structures. It supports various data types including numbers, strings, arrays, objects, sets, maps, and more. Shuttle also provides optional encryption and MD5 hashing for data integrity and security.

Features

  • Number and BigInt Encoding/Decoding: Supports various numeric types like Float32, Float64, Int8, Int16, Int32, Uint8, Uint16, Uint32, BigInt64, and BigUint64.
  • String Encoding/Decoding: Efficiently encodes and decodes strings.
  • Complex Data Structures: Supports arrays, objects, sets, and maps.
  • Binary Data: Handles Uint8Array, Uint16Array, and Uint32Array.
  • Date Handling: Encodes and decodes date objects, including handling invalid dates.
  • Optional Encryption: Provides encryption and decryption of serialized data using salts.
  • MD5 Hashing: Ensures data integrity with optional MD5 hashing.

Installation

npm install @cch137/shuttle

Usage

Importing the Library

import Shuttle from "@cch137/shuttle";

Serialize

const data = {
  name: "John Doe",
  age: 30,
  scores: [95, 87, 92],
  details: {
    married: false,
    address: "123 Main St",
  },
  bigNumber: BigInt("12345678901234567890"),
  birthDate: new Date("1990-01-01"),
};

const serializedData = Shuttle.serialize(data, {
  encoding: "utf-8",
  md5: true,
  salts: [12345],
});

Parse

const deserializedData = Shuttle.parse(serializedData, options);
console.log(deserializedData);

API

Shuttle.serialize(data: any, options?: ShuttleOptions & { salts?: number[] }): Uint8Array

Serializes the input data into a Uint8Array.

  • data: The data to serialize.
  • options: Optional settings.
    • encoding: The string encoding to use (default: utf-8).
    • md5: Whether to use MD5 hashing (default: false).
    • salts: An array of salts for encryption.

Shuttle.parse<T>(data: Uint8Array, options?: ShuttleOptions & { salts?: number[] }): T

Deserializes the input Uint8Array back into the original data.

  • data: The serialized data to parse.
  • options: Optional settings.
    • encoding: The string encoding to use (default: utf-8).
    • md5: Whether to verify data integrity using MD5 hashing (default: false).
    • salts: An array of salts for decryption.

Data Types

Shuttle supports the following data types:

  • Primitive Types: null, undefined, boolean, number, bigint, string.
  • Complex Types: Array, Object, Set, Map, Date.
  • Binary Data: Uint8Array, Uint16Array, Uint32Array.

Example

import Shuttle from "@cch137/shuttle";

const originalData = {
  name: "Alice",
  age: 25,
  friends: ["Bob", "Charlie"],
  scores: new Set([100, 98, 95]),
  metadata: new Map([
    ["key1", "value1"],
    ["key2", "value2"],
  ]),
  birthDate: new Date("1995-12-17"),
  bigIntVal: BigInt("9876543210987654321"),
};

const options = {
  encoding: "utf-8",
  md5: true,
  salts: [54321],
};

// Serialize the data
const serializedData = Shuttle.serialize(originalData, options);

// Deserialize the data
const deserializedData = Shuttle.parse(serializedData, options);

console.log(deserializedData);