char-bag

1.0.11 • Public • Published

char-bag

A simple, lightweight, and fast character bag implementation for Javascript. It is designed to be used in a Node.js environment, but can be used in the browser as well.

Installation

npm install char-bag

Usage without normalization

const Transformer = require('char-bag');

const transformer = new Transformer();

const encoded = transformer.encode('Hello World!');

console.log(encoded);

Output

[
  [72, 101, 108, 108, 111],
  [87, 111, 114, 108, 100, 33],
];

Usage with normalization

const Transformer = require('char-bag');

const transformer = new Transformer({
  normalized: true,
});

const encoded = transformer.encode('Hello World!');

console.log(encoded);

Output

[
  [-0.4375, -0.2109375, -0.15625, -0.15625, -0.1328125],
  [-0.3203125, -0.1328125, -0.109375, -0.15625, -0.21875, -0.7421875],
];

Usage Flattened

const Transformer = require('char-bag');

const transformer = new Transformer({
  flatten: true,
});

const encoded = transformer.encode('Hello World!');

console.log(encoded);

Output

[
  72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33
];

Decode Example

const Transformer = require('char-bag');

const transformer = new Transformer({
  normalized: true,
});

const decoded = transformer.decode([
  [-0.4375, -0.2109375, -0.15625, -0.15625, -0.1328125],
  [-0.3203125, -0.1328125, -0.109375, -0.15625, -0.21875, -0.7421875],
]);

console.log(decoded);

Output

'Hello World!';

Readme

Keywords

Package Sidebar

Install

npm i char-bag

Weekly Downloads

4

Version

1.0.11

License

ISC

Unpacked Size

8.21 kB

Total Files

5

Last publish

Collaborators

  • lucasbardoux