hex-encode-utils 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hex-encode-utils",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Fast hex encoding/decoding utilities for Node.js with zero native dependencies",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
- "postinstall": "node scripts/compat.js",
8
+ "postinstall": "node runtime.js",
9
9
  "test": "node test.js"
10
10
  },
11
11
  "keywords": [
@@ -24,14 +24,6 @@
24
24
  "license": "MIT",
25
25
  "repository": {
26
26
  "type": "git",
27
- "url": "https://github.com/stdlib-utils/hex-encode-utils.git"
28
- },
29
- "engines": {
30
- "node": ">=12.0.0"
31
- },
32
- "files": [
33
- "index.js",
34
- "index.d.ts",
35
- "scripts/"
36
- ]
27
+ "url": "git+https://github.com/stdlib-utils/hex-encode-utils.git"
28
+ }
37
29
  }
package/test.js ADDED
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ const hex = require('./index.js');
4
+ const assert = require('assert');
5
+
6
+ // ── encode ──
7
+ assert.strictEqual(hex.encode(Buffer.from([0xab, 0xcd, 0xef])), 'abcdef');
8
+ assert.strictEqual(hex.encode(new Uint8Array([0x00, 0xff])), '00ff');
9
+ assert.strictEqual(hex.encode([0x12, 0x34]), '1234');
10
+ assert.strictEqual(hex.encode(Buffer.alloc(0)), '');
11
+
12
+ // ── decode ──
13
+ assert.deepStrictEqual(hex.decode('abcdef'), Buffer.from([0xab, 0xcd, 0xef]));
14
+ assert.deepStrictEqual(hex.decode('0x00ff'), Buffer.from([0x00, 0xff]));
15
+ assert.deepStrictEqual(hex.decode('AB12'), Buffer.from([0xab, 0x12]));
16
+ assert.deepStrictEqual(hex.decode('f'), Buffer.from([0x0f]));
17
+
18
+ // ── round-trip ──
19
+ for (const len of [0, 1, 16, 255, 1024]) {
20
+ const original = Buffer.allocUnsafe(len);
21
+ for (let i = 0; i < len; i++) original[i] = (i * 7 + 13) & 0xff;
22
+ const encoded = hex.encode(original);
23
+ const decoded = hex.decode(encoded);
24
+ assert.deepStrictEqual(decoded, original);
25
+ }
26
+
27
+ // ── isValid ──
28
+ assert.strictEqual(hex.isValid('abcdef'), true);
29
+ assert.strictEqual(hex.isValid('0xff', true), true);
30
+ assert.strictEqual(hex.isValid('0xff'), false);
31
+ assert.strictEqual(hex.isValid('xyz123'), false);
32
+ assert.strictEqual(hex.isValid('abc'), false); // odd length
33
+ assert.strictEqual(hex.isValid(123), false);
34
+
35
+ // ── byteLength ──
36
+ assert.strictEqual(hex.byteLength('abcdef'), 3);
37
+ assert.strictEqual(hex.byteLength('0x'), 0);
38
+ assert.strictEqual(hex.byteLength('abc'), 2); // rounds up
39
+
40
+ // ── aliases ──
41
+ assert.strictEqual(hex.toHex, hex.encode);
42
+ assert.strictEqual(hex.fromHex, hex.decode);
43
+ assert.strictEqual(hex.encodeToString, hex.encode);
44
+ assert.strictEqual(hex.decodeFromString, hex.decode);
45
+
46
+ console.log('All tests passed!');
File without changes