https://github.com/jihyunlab/web-buffer
JihyunLab Web buffer.
https://github.com/jihyunlab/web-buffer
base64 base64url buffer hex uint8array utf8 web
Last synced: 7 months ago
JSON representation
JihyunLab Web buffer.
- Host: GitHub
- URL: https://github.com/jihyunlab/web-buffer
- Owner: jihyunlab
- License: mit
- Created: 2024-07-13T01:05:05.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-17T09:26:31.000Z (about 1 year ago)
- Last Synced: 2025-03-04T07:01:59.134Z (7 months ago)
- Topics: base64, base64url, buffer, hex, uint8array, utf8, web
- Language: TypeScript
- Homepage:
- Size: 57.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jihyunlab/web-buffer
[](https://www.npmjs.com/package/@jihyunlab/web-buffer?activeTab=versions) [](https://www.npmjs.com/package/@jihyunlab/web-buffer) [](https://github.com/jihyunlab/web-buffer/graphs/commit-activity) [](https://github.com/jihyunlab/web-buffer/blob/master/LICENSE) [](https://eslint.org) [](https://github.com/prettier/prettier)\
[](https://github.com/jihyunlab/web-buffer/actions/workflows/build.yml) [](https://github.com/jihyunlab/web-buffer/actions/workflows/lint.yml) [](https://github.com/jihyunlab/web-buffer/actions/workflows/prettier.yml) [](https://codecov.io/gh/jihyunlab/web-buffer)@jihyunlab/web-buffer provides data conversion capabilities in web application environments where Node.js's Buffer class cannot be used.
## Installation
```bash
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); // 6a696879756e6c6162const base64 = buffer.toString('base64');
console.log(base64); // amloeXVubGFiconst base64Url = buffer.toString('base64url');
console.log(base64Url); // amloeXVubGFiconst utf8 = buffer.toString('utf8');
console.log(utf8); // jihyunlabconst 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 <>
## License
Open source [licensed as MIT](https://github.com/jihyunlab/web-buffer/blob/master/LICENSE).