1.0.1 • Published 12 months ago

@jihyunlab/web-buffer v1.0.1

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

@jihyunlab/web-buffer

Version Downloads Last commit License Linter code style: prettier\ Build Lint Prettier codecov

@jihyunlab/web-buffer provides data conversion capabilities in web application environments where Node.js's Buffer class cannot be used.

Installation

npm i @jihyunlab/web-buffer

Usage

You can create a buffer and convert data based on encoding type.\ Encoding types are provided for Hex, Base64, Base64URL, UTF-8, and Uint8Array data.

import { WebBuffer } from '@jihyunlab/web-buffer';

const buffer = WebBuffer.from(
  'jihyunlab',
  'utf8' /* hex, base64, base64url, utf8, uint8array */
);

const hex = buffer.toString('hex');
console.log(hex); // 6a696879756e6c6162

const base64 = buffer.toString('base64');
console.log(base64); // amloeXVubGFi

const base64Url = buffer.toString('base64url');
console.log(base64Url); // amloeXVubGFi

const utf8 = buffer.toString('utf8');
console.log(utf8); // jihyunlab

const uint8Array = buffer.toUint8Array();
console.log(uint8Array); // Uint8Array(9) [106, 105, 104, 121, 117, 110, 108, 97, 98]

Uint8Array data can create buffer without defining an encoding type.

const buffer = WebBuffer.from(
  new Uint8Array([106, 105, 104, 121, 117, 110, 108, 97, 98])
);

UTF-8 data can be converted without defining the encoding type.

const utf8 = buffer.toString();

Credits

Authored and maintained by JihyunLab <info@jihyunlab.com>

License

Open source licensed as MIT.