1.0.2 • Published 11 months ago

array-encode-decode v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Array Encode / Decode

A versatile package for creating, encoding, and decoding arrays of various dimensions.

Installation

npm install array-encode-decode

Available Methods

MethodDescription
create1DCreates a 1-Dimensional array along the x-axis
create2DCreates a 2-Dimensional array along the x and y axes
create3DCreates a 3-Dimensional array along the x, y, and z axes
encodeEncodes an array and returns its run-length encoded representation along with its metadata (optional)
decodeDecodes a run-length encoded array and its metadata to its original form

Usage

Import the package as follows:

const ArrayEncoderDecoder = require("array-encode-decode");

Creating a 1D array

The create1D method creates a 1-dimensional array of a specified size along the x-axis. The values field is optional. If not provided, the array will be populated with the default value - 0.

let x = 10;  // size along the x-axis
let value = 2;  // example value (optional)
let array1D = ArrayEncoderDecoder.create1D(x, value);

Creating a 2D array

The create2D method creates a 2-dimensional array of a specified size along the x and y axes. The values field is optional. If not provided, the array will be populated with the default value - 0.

let x = 5;  // size along the x-axis
let y = 4;  // size along the y-axis
let value = 3;   // example value (optional)
let array2D = ArrayEncoderDecoder.create2D(x, y, value);

Creating a 3D array

The create3D method creates a 3-dimensional array of a specified size along the x, y, and z axes. The values field is optional. If not provided, the array will be populated with the default value - 0.

let x = 3;  // size along the x-axis
let y = 2;  // size along the y-axis
let z = 1;   // size along the z-axis
let value = 4;   // example value (optional)
let array3D = ArrayEncoderDecoder.create3D(x, y, z, value);

Encoding an Array

let inputArray = ArrayEncoderDecoder.create3D(3, 2, 1);
let encodedArray = ArrayEncoderDecoder.encode(inputArray);
console.log("Encoded Array Size:", ArrayEncoderDecoder.displayBytes(JSON.stringify(encodedArray).length));

Decoding an Array

let decodedArray = ArrayEncoderDecoder.decode(encodedArray);
console.log("Decoded Array:", decodedArray);

License

MIT

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago