`@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
npm install @cch137/shuttle@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.
Float32, Float64, Int8, Int16, Int32, Uint8, Uint16, Uint32, BigInt64, and BigUint64.
Uint8Array, Uint16Array, and Uint32Array.
bash
npm install @cch137/shuttle
`
Usage
$3
`typescript
import Shuttle from "@cch137/shuttle";
`
$3
`typescript
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],
});
`
$3
`typescript
const deserializedData = Shuttle.parse(serializedData, options);
console.log(deserializedData);
`
API
$3
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.
$3
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
`typescript
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);
``