ordered-binary 1.6.0 → 1.6.2

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Kris Zyp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,38 @@
1
+ [![npm version](https://img.shields.io/npm/dw/ordered-binary)](https://www.npmjs.org/package/ordered-binary)
2
+ [![npm version](https://img.shields.io/npm/v/ordered-binary.svg?style=flat-square)](https://www.npmjs.org/package/ordered-binary)
3
+ [![license](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)
4
+
5
+ The ordered-binary package provides a representation of JavaScript primitives, serialized into binary format (NodeJS Buffers or Uint8Arrays), such that the binary values are naturally ordered such that it matches the natural ordering or values. For example, since -2.0321 > -2.04, then `toBufferKey(-2.0321)` will be greater than `toBufferKey(-2.04)` as a binary representation, in left-to-right evaluation. This is particular useful for storing keys as binaries with something like LMDB or LevelDB, to avoid any custom sorting.
6
+
7
+ The ordered-binary package supports strings, numbers, booleans, symbols, null, as well as an array of primitives. Here is an example of ordering of primitive values:
8
+ ```
9
+ Buffer.from([0]) // buffers are left unchanged, and this is the minimum value
10
+ Symbol.for('even symbols')
11
+ -10 // negative supported
12
+ -1.1 // decimals supported
13
+ 400
14
+ 3E10
15
+ 'Hello'
16
+ ['Hello', 'World']
17
+ 'World'
18
+ 'hello'
19
+ ['hello', 1, 'world']
20
+ ['hello', 'world']
21
+ Buffer.from([0xff])
22
+ ```
23
+
24
+
25
+ The main module exports these functions:
26
+
27
+ `writeKey(key: string | number | boolean | null | Array, target: Buffer, position: integer, inSequence?: boolean)` - Writes the provide key to the target buffer
28
+
29
+ `readKey(buffer, start, end, inSequence)` - Reads the key from the buffer, given the provided start and end, as a primitive value
30
+
31
+ `toBufferKey(jsPrimitive)` - This accepts a string, number, or boolean as the argument, and returns a `Buffer`.
32
+
33
+ `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).
34
+
35
+ And these constants:
36
+
37
+ `MINIMUM_KEY` - The minimum key supported (`null`, which is represented as single zero byte)
38
+ `MAXIMUM_KEY` - A maximum key larger than any supported primitive (single 0xff byte)
@@ -0,0 +1,464 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /*
6
+ control character types:
7
+ 1 - metadata
8
+ 2 - symbols
9
+ 6 - false
10
+ 7 - true
11
+ 8- 16 - negative doubles
12
+ 16-24 positive doubles
13
+ 27 - String starts with a character 27 or less or is an empty string
14
+ 0 - multipart separator
15
+ > 27 normal string characters
16
+ */
17
+ /*
18
+ * Convert arbitrary scalar values to buffer bytes with type preservation and type-appropriate ordering
19
+ */
20
+
21
+ const float64Array = new Float64Array(2);
22
+ const int32Array = new Int32Array(float64Array.buffer, 0, 4);
23
+ const {lowIdx, highIdx} = (() => {
24
+ if (new Uint8Array(new Uint32Array([0xFFEE1100]).buffer)[0] === 0xFF) {
25
+ return { lowIdx: 1, highIdx: 0 };
26
+ }
27
+ return { lowIdx: 0, highIdx: 1 };
28
+ })();
29
+ let nullTerminate = false;
30
+ let textEncoder;
31
+ try {
32
+ textEncoder = new TextEncoder();
33
+ } catch (error) {}
34
+
35
+ /*
36
+ * Convert arbitrary scalar values to buffer bytes with type preservation and type-appropriate ordering
37
+ */
38
+ function writeKey(key, target, position, inSequence) {
39
+ let targetView = target.dataView;
40
+ if (!targetView)
41
+ targetView = target.dataView = new DataView(target.buffer, target.byteOffset, ((target.byteLength + 3) >> 2) << 2);
42
+ switch (typeof key) {
43
+ case 'string':
44
+ let strLength = key.length;
45
+ let c1 = key.charCodeAt(0);
46
+ if (!(c1 >= 28)) // escape character
47
+ target[position++] = 27;
48
+ if (strLength < 0x40) {
49
+ let i, c2;
50
+ for (i = 0; i < strLength; i++) {
51
+ c1 = key.charCodeAt(i);
52
+ if (c1 <= 4) {
53
+ target[position++] = 4;
54
+ target[position++] = c1;
55
+ } else if (c1 < 0x80) {
56
+ target[position++] = c1;
57
+ } else if (c1 < 0x800) {
58
+ target[position++] = c1 >> 6 | 0xc0;
59
+ target[position++] = c1 & 0x3f | 0x80;
60
+ } else if (
61
+ (c1 & 0xfc00) === 0xd800 &&
62
+ ((c2 = key.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
63
+ ) {
64
+ c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
65
+ i++;
66
+ target[position++] = c1 >> 18 | 0xf0;
67
+ target[position++] = c1 >> 12 & 0x3f | 0x80;
68
+ target[position++] = c1 >> 6 & 0x3f | 0x80;
69
+ target[position++] = c1 & 0x3f | 0x80;
70
+ } else {
71
+ target[position++] = c1 >> 12 | 0xe0;
72
+ target[position++] = c1 >> 6 & 0x3f | 0x80;
73
+ target[position++] = c1 & 0x3f | 0x80;
74
+ }
75
+ }
76
+ } else {
77
+ if (target.utf8Write)
78
+ position += target.utf8Write(key, position, target.byteLength - position);
79
+ else
80
+ position += textEncoder.encodeInto(key, target.subarray(position)).written;
81
+ if (position > target.length - 4)
82
+ throw new RangeError('String does not fit in target buffer')
83
+ }
84
+ break
85
+ case 'number':
86
+ float64Array[0] = key;
87
+ let lowInt = int32Array[lowIdx];
88
+ let highInt = int32Array[highIdx];
89
+ let length;
90
+ if (key < 0) {
91
+ targetView.setInt32(position + 4, ~((lowInt >>> 4) | (highInt << 28)));
92
+ targetView.setInt32(position + 0, (highInt ^ 0x7fffffff) >>> 4);
93
+ targetView.setInt32(position + 8, ((lowInt & 0xf) ^ 0xf) << 4, true); // just always do the null termination here
94
+ return position + 9
95
+ } else if ((lowInt & 0xf) || inSequence) {
96
+ length = 9;
97
+ } else if (lowInt & 0xfffff)
98
+ length = 8;
99
+ else if (lowInt || (highInt & 0xf))
100
+ length = 6;
101
+ else
102
+ length = 4;
103
+ // switching order to go to little endian
104
+ targetView.setInt32(position + 0, (highInt >>> 4) | 0x10000000);
105
+ targetView.setInt32(position + 4, (lowInt >>> 4) | (highInt << 28));
106
+ // if (length == 9 || nullTerminate)
107
+ targetView.setInt32(position + 8, (lowInt & 0xf) << 4, true);
108
+ return position + length;
109
+ case 'object':
110
+ if (key) {
111
+ if (Array.isArray(key)) {
112
+ for (let i = 0, l = key.length; i < l; i++) {
113
+ if (i > 0)
114
+ target[position++] = 0;
115
+ position = writeKey(key[i], target, position, true);
116
+ }
117
+ break
118
+ } else if (key instanceof Uint8Array) {
119
+ target.set(key, position);
120
+ position += key.length;
121
+ break
122
+ } else {
123
+ throw new Error('Unable to serialize object as a key: ' + JSON.stringify(key))
124
+ }
125
+ } else // null
126
+ target[position++] = 0;
127
+ break
128
+ case 'boolean':
129
+ targetView.setUint32(position++, key ? 7 : 6, true);
130
+ return position
131
+ case 'bigint':
132
+ let asFloat = Number(key);
133
+ if (BigInt(asFloat) > key) {
134
+ float64Array[0] = asFloat;
135
+ if (asFloat > 0) {
136
+ if (int32Array[lowIdx])
137
+ int32Array[lowIdx]--;
138
+ else {
139
+ int32Array[highIdx]--;
140
+ int32Array[lowIdx] = 0xffffffff;
141
+ }
142
+ } else {
143
+ if (int32Array[lowIdx] < 0xffffffff)
144
+ int32Array[lowIdx]++;
145
+ else {
146
+ int32Array[highIdx]++;
147
+ int32Array[lowIdx] = 0;
148
+ }
149
+ }
150
+ asFloat = float64Array[0];
151
+ }
152
+ let difference = key - BigInt(asFloat);
153
+ if (difference === 0n)
154
+ return writeKey(asFloat, target, position, inSequence)
155
+ writeKey(asFloat, target, position, inSequence);
156
+ position += 9; // always increment by 9 if we are adding fractional bits
157
+ let exponent = BigInt((int32Array[highIdx] >> 20 & 0x7ff) - 1079);
158
+ let nextByte = difference >> exponent;
159
+ target[position - 1] |= Number(nextByte);
160
+ difference -= nextByte << exponent;
161
+ let first = true;
162
+ while (difference || first) {
163
+ first = false;
164
+ exponent -= 7n;
165
+ let nextByte = difference >> exponent;
166
+ target[position++] = Number(nextByte) | 0x80;
167
+ difference -= nextByte << exponent;
168
+ }
169
+ return position;
170
+ case 'undefined':
171
+ return position
172
+ // undefined is interpreted as the absence of a key, signified by zero length
173
+ case 'symbol':
174
+ target[position++] = 2;
175
+ return writeKey(key.description, target, position, inSequence)
176
+ default:
177
+ throw new Error('Can not serialize key of type ' + typeof key)
178
+ }
179
+ if (nullTerminate && !inSequence)
180
+ targetView.setUint32(position, 0);
181
+ return position
182
+ }
183
+
184
+ let position;
185
+ function readKey(buffer, start, end, inSequence) {
186
+ position = start;
187
+ let controlByte = buffer[position];
188
+ let value;
189
+ if (controlByte < 24) {
190
+ if (controlByte < 8) {
191
+ position++;
192
+ if (controlByte == 6) {
193
+ value = false;
194
+ } else if (controlByte == 7) {
195
+ value = true;
196
+ } else if (controlByte == 0) {
197
+ value = null;
198
+ } else if (controlByte == 2) {
199
+ value = Symbol.for(readStringSafely(buffer, end));
200
+ } else
201
+ return Uint8Array.prototype.slice.call(buffer, start, end)
202
+ } else {
203
+ let dataView;
204
+ try {
205
+ dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, ((buffer.byteLength + 3) >> 2) << 2));
206
+ } catch(error) {
207
+ // if it is write at the end of the ArrayBuffer, we may need to retry with the exact remaining bytes
208
+ dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.buffer.byteLength - buffer.byteOffset));
209
+ }
210
+
211
+ let highInt = dataView.getInt32(position) << 4;
212
+ let size = end - position;
213
+ let lowInt;
214
+ if (size > 4) {
215
+ lowInt = position + 8 <= buffer.length ? dataView.getInt32(position + 4) : (
216
+ buffer[position + 4] << 24 |
217
+ buffer[position + 5] << 16 |
218
+ buffer[position + 6] << 8 |
219
+ buffer[position + 7]
220
+ );
221
+ highInt |= lowInt >>> 28;
222
+ if (size <= 6) { // clear the last bits
223
+ lowInt &= -0x10000;
224
+ }
225
+ lowInt = lowInt << 4;
226
+ if (size > 8) {
227
+ lowInt = lowInt | buffer[position + 8] >> 4;
228
+ }
229
+ } else
230
+ lowInt = 0;
231
+ if (controlByte < 16) {
232
+ // negative gets negated
233
+ highInt = highInt ^ 0x7fffffff;
234
+ lowInt = ~lowInt;
235
+ }
236
+ int32Array[highIdx] = highInt;
237
+ int32Array[lowIdx] = lowInt;
238
+ value = float64Array[0];
239
+ position += 9;
240
+ if (size > 9 && buffer[position] > 0) {
241
+ // convert the float to bigint, and then we will add precision as we enumerate through the
242
+ // extra bytes
243
+ value = BigInt(value);
244
+ let exponent = highInt >> 20 & 0x7ff;
245
+ let next_byte = buffer[position - 1] & 0xf;
246
+ value += BigInt(next_byte) << BigInt(exponent - 1079);
247
+ while ((next_byte = buffer[position]) > 0 && position++ < end) {
248
+ value += BigInt(next_byte & 0x7f) << BigInt((start - position) * 7 + exponent - 1016);
249
+ }
250
+ }
251
+ }
252
+ } else {
253
+ if (controlByte == 27) {
254
+ position++;
255
+ }
256
+ value = readStringSafely(buffer, end);
257
+ if (position < end) position--; // if have a null terminator for the string, count that as the array separator
258
+ }
259
+ while (position < end) {
260
+ if (buffer[position] === 0)
261
+ position++;
262
+ if (inSequence) {
263
+ encoder.position = position;
264
+ return value
265
+ }
266
+ let nextValue = readKey(buffer, position, end, true);
267
+ if (value instanceof Array) {
268
+ value.push(nextValue);
269
+ } else
270
+ value = [ value, nextValue ];
271
+ }
272
+ return value
273
+ }
274
+ const enableNullTermination = () => nullTerminate = true;
275
+
276
+ const encoder = {
277
+ writeKey,
278
+ readKey,
279
+ enableNullTermination,
280
+ };
281
+ let targetBuffer = [];
282
+ let targetPosition = 0;
283
+ const hasNodeBuffer = typeof Buffer !== 'undefined';
284
+ const ByteArrayAllocate = hasNodeBuffer ? Buffer.allocUnsafeSlow : Uint8Array;
285
+ const toBufferKey = (key) => {
286
+ let newBuffer;
287
+ if (targetPosition + 100 > targetBuffer.length) {
288
+ targetBuffer = new ByteArrayAllocate(8192);
289
+ targetPosition = 0;
290
+ newBuffer = true;
291
+ }
292
+ try {
293
+ let result = targetBuffer.slice(targetPosition, targetPosition = writeKey(key, targetBuffer, targetPosition));
294
+ if (targetPosition > targetBuffer.length) {
295
+ if (newBuffer)
296
+ throw new Error('Key is too large')
297
+ return toBufferKey(key)
298
+ }
299
+ return result
300
+ } catch(error) {
301
+ if (newBuffer)
302
+ throw error
303
+ targetPosition = targetBuffer.length;
304
+ return toBufferKey(key)
305
+ }
306
+ };
307
+ const fromBufferKey = (sourceBuffer) => {
308
+ return readKey(sourceBuffer, 0, sourceBuffer.length)
309
+ };
310
+ const fromCharCode = String.fromCharCode;
311
+ function makeStringBuilder() {
312
+ let stringBuildCode = '(source) => {';
313
+ let previous = [];
314
+ for (let i = 0; i < 0x30; i++) {
315
+ let v = fromCharCode((i & 0xf) + 97) + fromCharCode((i >> 4) + 97);
316
+ stringBuildCode += `
317
+ let ${v} = source[position++]
318
+ if (${v} > 4) {
319
+ if (${v} >= 0x80) ${v} = finishUtf8(${v}, source)
320
+ } else {
321
+ if (${v} === 4)
322
+ ${v} = source[position++]
323
+ else
324
+ return fromCharCode(${previous})
325
+ }
326
+ `;
327
+ previous.push(v);
328
+ if (i == 1000000) // this just exists to prevent rollup from doing dead code elimination on finishUtf8
329
+ finishUtf8();
330
+ }
331
+ stringBuildCode += `return fromCharCode(${previous}) + readString(source)}`;
332
+ return stringBuildCode
333
+ }
334
+
335
+ let pendingSurrogate;
336
+ function finishUtf8(byte1, src) {
337
+ if ((byte1 & 0xe0) === 0xc0) {
338
+ // 2 bytes
339
+ const byte2 = src[position++] & 0x3f;
340
+ return ((byte1 & 0x1f) << 6) | byte2
341
+ } else if ((byte1 & 0xf0) === 0xe0) {
342
+ // 3 bytes
343
+ const byte2 = src[position++] & 0x3f;
344
+ const byte3 = src[position++] & 0x3f;
345
+ return ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3
346
+ } else if ((byte1 & 0xf8) === 0xf0) {
347
+ // 4 bytes
348
+ if (pendingSurrogate) {
349
+ byte1 = pendingSurrogate;
350
+ pendingSurrogate = null;
351
+ position += 3;
352
+ return byte1
353
+ }
354
+ const byte2 = src[position++] & 0x3f;
355
+ const byte3 = src[position++] & 0x3f;
356
+ const byte4 = src[position++] & 0x3f;
357
+ let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
358
+ if (unit > 0xffff) {
359
+ pendingSurrogate = 0xdc00 | (unit & 0x3ff);
360
+ unit = (((unit - 0x10000) >>> 10) & 0x3ff) | 0xd800;
361
+ position -= 4; // reset so we can return the next part of the surrogate pair
362
+ }
363
+ return unit
364
+ } else {
365
+ return byte1
366
+ }
367
+ }
368
+
369
+ const readString =
370
+ typeof process !== 'undefined' && process.isBun ? // the eval in bun doesn't properly closure on position, so we
371
+ // have to manually update it
372
+ (function(reading) {
373
+ let { setPosition, getPosition, readString } = reading;
374
+ return (source) => {
375
+ setPosition(position);
376
+ let value = readString(source);
377
+ position = getPosition();
378
+ return value;
379
+ };
380
+ })((new Function('fromCharCode', 'let position; let pendingSurrogate; ' +
381
+ // finishUtf8 references `position`/`pendingSurrogate`, but new Function compiles
382
+ // in global scope and can't close over the module-level copies, so embed its
383
+ // source here to bind it to this function's local (synced) `position`.
384
+ 'let finishUtf8 = ' + finishUtf8.toString() + '; ' +
385
+ 'let readString = ' + makeStringBuilder() +
386
+ ';return {' +
387
+ 'setPosition(p) { position = p },' +
388
+ 'getPosition() { return position },' +
389
+ 'readString }'))(fromCharCode)) :
390
+ eval(makeStringBuilder());
391
+ function readStringSafely(source, end) {
392
+ if (source[end] > 0) {
393
+ let previous = source[end];
394
+ try {
395
+ // read string expects a null terminator, that is a 0 or undefined from reading past the end of the buffer, so we
396
+ // have to ensure that, but do so safely, restoring the buffer to its original state
397
+ source[end] = 0;
398
+ return readString(source)
399
+ } finally {
400
+ source[end] = previous;
401
+ }
402
+ } else return readString(source);
403
+ }
404
+ function compareKeys(a, b) {
405
+ // compare with type consistency that matches binary comparison
406
+ if (typeof a == 'object') {
407
+ if (!a) {
408
+ return b == null ? 0 : -1
409
+ }
410
+ if (a.compare) {
411
+ if (b == null) {
412
+ return 1
413
+ } else if (b.compare) {
414
+ return a.compare(b)
415
+ } else {
416
+ return -1
417
+ }
418
+ }
419
+ let arrayComparison;
420
+ if (b instanceof Array) {
421
+ let i = 0;
422
+ while((arrayComparison = compareKeys(a[i], b[i])) == 0 && i <= a.length) {
423
+ i++;
424
+ }
425
+ return arrayComparison
426
+ }
427
+ arrayComparison = compareKeys(a[0], b);
428
+ if (arrayComparison == 0 && a.length > 1)
429
+ return 1
430
+ return arrayComparison
431
+ } else if (typeof a == typeof b) {
432
+ if (typeof a === 'symbol') {
433
+ a = Symbol.keyFor(a);
434
+ b = Symbol.keyFor(b);
435
+ }
436
+ return a < b ? -1 : a === b ? 0 : 1
437
+ }
438
+ else if (typeof b == 'object') {
439
+ if (b instanceof Array)
440
+ return -compareKeys(b, a)
441
+ return 1
442
+ } else {
443
+ return typeOrder[typeof a] < typeOrder[typeof b] ? -1 : 1
444
+ }
445
+ }
446
+ const typeOrder = {
447
+ symbol: 0,
448
+ undefined: 1,
449
+ boolean: 2,
450
+ number: 3,
451
+ string: 4
452
+ };
453
+ const MINIMUM_KEY = null;
454
+ const MAXIMUM_KEY = new Uint8Array([0xff]);
455
+
456
+ exports.MAXIMUM_KEY = MAXIMUM_KEY;
457
+ exports.MINIMUM_KEY = MINIMUM_KEY;
458
+ exports.compareKeys = compareKeys;
459
+ exports.enableNullTermination = enableNullTermination;
460
+ exports.encoder = encoder;
461
+ exports.fromBufferKey = fromBufferKey;
462
+ exports.readKey = readKey;
463
+ exports.toBufferKey = toBufferKey;
464
+ exports.writeKey = writeKey;
@@ -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
+ /** Converts 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
+ }