From 8204d1b1a3be31603a0417ed953954061e2057a0 Mon Sep 17 00:00:00 2001 From: ayman Date: Sun, 28 Jul 2024 18:01:06 +0530 Subject: [PATCH 1/2] 0.0.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f6f13d..2d5fb07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uint8array-tools", - "version": "0.0.7", + "version": "0.0.8", "description": "A library for dealing with Uint8Arrays.", "homepage": "https://github.com/bitcoinjs/uint8array-tools#readme", "bugs": { From db4f3ce0f6826e9180eed877e9bc930729d93c04 Mon Sep 17 00:00:00 2001 From: ayman Date: Thu, 1 Aug 2024 19:08:37 +0530 Subject: [PATCH 2/2] chore: add examples in the readme --- README.md | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 867ffcd..50e6b42 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Note: `fromHex` and `compare` mimic the `Buffer.from('ff', 'hex')` and as well as in Node. ```js -import * as uint8arraytools from 'uint8array-tools'; -uint8arraytools.fromHex('ff'); +import * as uint8arraytools from "uint8array-tools"; +uint8arraytools.fromHex("ff"); // Uint8Array(1) [ 255 ] uint8arraytools.toHex(Uint8Array.from([0xff])); // 'ff' @@ -20,4 +20,21 @@ uint8arraytools.compare(Uint8Array.from([0xff]), Uint8Array.from([0xff])); // 0 uint8arraytools.compare(Uint8Array.from([0x01]), Uint8Array.from([0xff])); // -1 -``` \ No newline at end of file +uint8arraytools.fromUtf8("tools"); +// Uint8Array(5) [ 116, 111, 111, 108, 115 ] +uint8arraytools.toUtf8(Uint8Array.from([116, 111, 111, 108, 115])); +// tools +uint8arraytools.concat([Uint8Array.from([1]), Uint8Array.from([2])]); +// Uint8Array(2) [ 1, 2 ] +uint8arraytools.fromBase64("dG9vbHM="); +// Uint8Array(3) [ 182, 138, 37 ] +uint8arraytools.toBase64(Uint8Array.from([116, 111, 111, 108, 115])); +// dG9vbHM= + +const uint8array = new Uint8Array(2); +uint8arraytools.writeUInt16(uint8array, 0, 0xffff - 1, "LE"); +uint8array; +// Uint8Array(2) [ 254, 255 ] +uint8arraytools.readUInt16(uint8array, 0, "LE"); +// 65534 +```