ordered-binary 1.2.2 → 1.2.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/README.md +5 -0
- package/dist/index.cjs +0 -2
- package/index.d.ts +23 -0
- package/index.js +0 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -32,3 +32,8 @@ The main module exports these functions:
|
|
|
32
32
|
`toBufferKey(jsPrimitive)` - This accepts a string, number, or boolean as the argument, and returns a `Buffer`.
|
|
33
33
|
|
|
34
34
|
`fromBufferKey(bufferKey, multiple)` - This accepts a Buffer and returns a JavaScript primitive value. This can also parse buffers that hold multiple values delimited by a byte `30`, by setting the second argument to true (in which case it will return an array).
|
|
35
|
+
|
|
36
|
+
And these constants:
|
|
37
|
+
|
|
38
|
+
`MINIMUM_KEY` - The minimum key supported (`null`, which is represented as single zero byte)
|
|
39
|
+
`MAXIMUM_KEY` - A maximum key larger than any supported primitive (single 0xff byte)
|
package/dist/index.cjs
CHANGED
|
@@ -20,8 +20,6 @@ control character types:
|
|
|
20
20
|
|
|
21
21
|
const float64Array = new Float64Array(2);
|
|
22
22
|
const int32Array = new Int32Array(float64Array.buffer, 0, 4);
|
|
23
|
-
new Uint8Array(float64Array.buffer, 2, 6);
|
|
24
|
-
new Uint8Array(float64Array.buffer, 0, 8);
|
|
25
23
|
let nullTerminate = false;
|
|
26
24
|
let textEncoder;
|
|
27
25
|
try {
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type Key = Key[] | string | symbol | number | boolean | Uint8Array;
|
|
2
|
+
/** Writes a key (a primitive value) to the target buffer, starting at the given position */
|
|
3
|
+
export function writeKey(key: Key, target: Uint8Array, position: number, inSequence?: boolean): number;
|
|
4
|
+
/** Reads a key from the provided buffer, from the given range */
|
|
5
|
+
export function readKey(buffer: Uint8Array, start: number, end: number, inSequence?: boolean): Key;
|
|
6
|
+
/** Converts key to a Buffer. This is generally much slower than using writeKey since it involves a full buffer allocation, and should be avoided for performance sensitive code. */
|
|
7
|
+
export function toBufferKey(key: Key): Buffer;
|
|
8
|
+
/** Coverts Buffer to Key */
|
|
9
|
+
export function fromBufferKey(source: Buffer): Key;
|
|
10
|
+
/** Compares two keys, returning -1 if `a` comes before `b` in the ordered binary representation of the keys, or 1 if `a` comes after `b`, or 0 if they are equivalent */
|
|
11
|
+
export function compareKeys(a: Key, b: Key): number;
|
|
12
|
+
/** The minimum key, with the "first" binary representation (one byte of zero) */
|
|
13
|
+
export const MINIMUM_KEY: null
|
|
14
|
+
/** A maximum key, with a binary representation after all other JS primitives (one byte of 0xff) */
|
|
15
|
+
export const MAXIMUM_KEY: Uint8Array
|
|
16
|
+
/** Enables null termination, ensuring that writing keys to buffers will end with a padding of zeros at the end to complete the following 32-bit word */
|
|
17
|
+
export function enableNullTermination(): void;
|
|
18
|
+
/** An object that holds the functions for encapsulation as a single encoder */
|
|
19
|
+
export const encoder: {
|
|
20
|
+
writeKey: typeof writeKey,
|
|
21
|
+
readKey: typeof readKey,
|
|
22
|
+
enableNullTermination: typeof enableNullTermination,
|
|
23
|
+
}
|
package/index.js
CHANGED
|
@@ -16,8 +16,6 @@ control character types:
|
|
|
16
16
|
|
|
17
17
|
const float64Array = new Float64Array(2)
|
|
18
18
|
const int32Array = new Int32Array(float64Array.buffer, 0, 4)
|
|
19
|
-
const uint8Array6 = new Uint8Array(float64Array.buffer, 2, 6)
|
|
20
|
-
const uint8Array8 = new Uint8Array(float64Array.buffer, 0, 8)
|
|
21
19
|
let nullTerminate = false
|
|
22
20
|
let textEncoder
|
|
23
21
|
try {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ordered-binary",
|
|
3
3
|
"author": "Kris Zyp",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.5",
|
|
5
5
|
"description": "Conversion of JavaScript primitives to and from Buffer with binary order matching natural primitive order",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"test": "mocha tests -u tdd"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
|
+
"main": "dist/index.cjs",
|
|
17
18
|
"module": "index.js",
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/node": "latest",
|
|
32
33
|
"chai": "^4",
|
|
33
|
-
"mocha": "^9.
|
|
34
|
+
"mocha": "^9.2.0",
|
|
34
35
|
"rollup": "^2.61.1"
|
|
35
36
|
}
|
|
36
37
|
}
|