@gxchain2/utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@gxchain2/utils

NPM Version License

Utils include the following classes:

  • Channel: Contains three implements
    • Channel: An asynchronous queue, order by the order in which the elements are pushed
    • HChannel: An asynchronous queue, order by customizable heap
    • PChannel: An asynchronous queue, order by element index(grow from 0) and index must be continuous
  • Compress: Provide some functions for compressing and decompressing data
  • FunctionalMap and FunctionalSet: Key customizable map and set

INSTALL

npm install @gxchain2/utils

USAGE

const channel = new Channel<string>();
channel.push('123');
channel.push('456');
setTimeout(() => {
  channel.push('789');
}, 1000);
setTimeout(() => {
  channel.push('101112');
}, 2000);
setTimeout(() => {
  channel.abort();
}, 3000);

(async () => {
  for await (const data of channel.generator()) {
    console.log('data:', data);
  }
  console.log('channel end');
})();
const bufferMap = new FunctionalMap<Buffer, string>((a: Buffer, b: Buffer) => a.compare(b));
bufferMap.set(Buffer.from('aaaaaa', 'hex'), 'aaaaaa');
console.log(bufferMap.get(Buffer.from('aaaaaa', 'hex')) === 'aaaaaa'); // true

License

GNU General Public License v3.0

Readme

Keywords

none

Package Sidebar

Install

npm i @gxchain2/utils

Weekly Downloads

1

Version

0.0.1

License

GPL-3.0-or-later

Unpacked Size

103 kB

Total Files

35

Last publish

Collaborators

  • lanhaoxiang
  • samlior