ordered-binary 1.4.0 → 1.4.1

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 @@
1
+ {"parent":null,"pid":240712,"argv":["/home/kzyp/.nvm/versions/node/v20.0.0/bin/node","/home/kzyp/dev/ordered-binary/node_modules/mocha/bin/mocha","--ui","tdd","--reporter","/home/kzyp/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/222.4167.35.plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js","/home/kzyp/dev/ordered-binary/tests/test.js"],"execArgv":[],"cwd":"/home/kzyp/dev/ordered-binary","time":1688411366364,"ppid":240701,"coverageFilename":"/home/kzyp/dev/ordered-binary/.nyc_output/5b6bd808-0399-4ee6-9395-344688761dfa.json","externalId":"","uuid":"5b6bd808-0399-4ee6-9395-344688761dfa","files":[]}
@@ -0,0 +1 @@
1
+ {"processes":{"5b6bd808-0399-4ee6-9395-344688761dfa":{"parent":null,"children":[]}},"files":{},"externalIds":{}}
package/dist/index.cjs CHANGED
@@ -69,7 +69,7 @@ function writeKey(key, target, position, inSequence) {
69
69
  }
70
70
  } else {
71
71
  if (target.utf8Write)
72
- position += target.utf8Write(key, position);
72
+ position += target.utf8Write(key, position, 0xffffffff);
73
73
  else
74
74
  position += textEncoder.encodeInto(key, target.subarray(position)).written;
75
75
  if (position > target.length - 4)
@@ -288,20 +288,19 @@ function finishUtf8(byte1, src) {
288
288
  } else if ((byte1 & 0xf8) === 0xf0) {
289
289
  // 4 bytes
290
290
  if (pendingSurrogate) {
291
- byte1 = pendingSurrogate;
292
- pendingSurrogate = null;
293
- position += 3;
294
- return byte1
291
+ byte1 = pendingSurrogate;
292
+ pendingSurrogate = null;
293
+ position += 3;
294
+ return byte1
295
295
  }
296
296
  const byte2 = src[position++] & 0x3f;
297
297
  const byte3 = src[position++] & 0x3f;
298
298
  const byte4 = src[position++] & 0x3f;
299
299
  let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
300
300
  if (unit > 0xffff) {
301
- unit -= 0x10000;
302
- unit = 0xdc00 | (unit & 0x3ff);
303
- pendingSurrogate = ((unit >>> 10) & 0x3ff) | 0xd800;
304
- position -= 4; // reset so we can return the next part of the surrogate pair
301
+ pendingSurrogate = 0xdc00 | (unit & 0x3ff);
302
+ unit = (((unit - 0x10000) >>> 10) & 0x3ff) | 0xd800;
303
+ position -= 4; // reset so we can return the next part of the surrogate pair
305
304
  }
306
305
  return unit
307
306
  } else {
@@ -309,7 +308,23 @@ function finishUtf8(byte1, src) {
309
308
  }
310
309
  }
311
310
 
312
- const readString = eval(makeStringBuilder());
311
+ const readString =
312
+ typeof process !== 'undefined' && process.isBun ? // the eval in bun doesn't properly closure on position, so we
313
+ // have to manually update it
314
+ (function(reading) {
315
+ let { setPosition, getPosition, readString } = reading;
316
+ return (source) => {
317
+ setPosition(position);
318
+ let value = readString(source);
319
+ position = getPosition();
320
+ return value;
321
+ };
322
+ })((new Function('fromCharCode', 'let position; let readString = ' + makeStringBuilder() +
323
+ ';return {' +
324
+ 'setPosition(p) { position = p },' +
325
+ 'getPosition() { return position },' +
326
+ 'readString }'))(fromCharCode)) :
327
+ eval(makeStringBuilder());
313
328
 
314
329
  function compareKeys(a, b) {
315
330
  // compare with type consistency that matches binary comparison
package/index.js CHANGED
@@ -65,7 +65,7 @@ export function writeKey(key, target, position, inSequence) {
65
65
  }
66
66
  } else {
67
67
  if (target.utf8Write)
68
- position += target.utf8Write(key, position)
68
+ position += target.utf8Write(key, position, 0xffffffff)
69
69
  else
70
70
  position += textEncoder.encodeInto(key, target.subarray(position)).written
71
71
  if (position > target.length - 4)
@@ -284,20 +284,19 @@ function finishUtf8(byte1, src) {
284
284
  } else if ((byte1 & 0xf8) === 0xf0) {
285
285
  // 4 bytes
286
286
  if (pendingSurrogate) {
287
- byte1 = pendingSurrogate
288
- pendingSurrogate = null
289
- position += 3
290
- return byte1
287
+ byte1 = pendingSurrogate
288
+ pendingSurrogate = null
289
+ position += 3
290
+ return byte1
291
291
  }
292
292
  const byte2 = src[position++] & 0x3f
293
293
  const byte3 = src[position++] & 0x3f
294
294
  const byte4 = src[position++] & 0x3f
295
295
  let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4
296
296
  if (unit > 0xffff) {
297
- unit -= 0x10000
298
- unit = 0xdc00 | (unit & 0x3ff)
299
- pendingSurrogate = ((unit >>> 10) & 0x3ff) | 0xd800
300
- position -= 4 // reset so we can return the next part of the surrogate pair
297
+ pendingSurrogate = 0xdc00 | (unit & 0x3ff)
298
+ unit = (((unit - 0x10000) >>> 10) & 0x3ff) | 0xd800
299
+ position -= 4 // reset so we can return the next part of the surrogate pair
301
300
  }
302
301
  return unit
303
302
  } else {
@@ -305,7 +304,23 @@ function finishUtf8(byte1, src) {
305
304
  }
306
305
  }
307
306
 
308
- const readString = eval(makeStringBuilder())
307
+ const readString =
308
+ typeof process !== 'undefined' && process.isBun ? // the eval in bun doesn't properly closure on position, so we
309
+ // have to manually update it
310
+ (function(reading) {
311
+ let { setPosition, getPosition, readString } = reading;
312
+ return (source) => {
313
+ setPosition(position);
314
+ let value = readString(source);
315
+ position = getPosition();
316
+ return value;
317
+ };
318
+ })((new Function('fromCharCode', 'let position; let readString = ' + makeStringBuilder() +
319
+ ';return {' +
320
+ 'setPosition(p) { position = p },' +
321
+ 'getPosition() { return position },' +
322
+ 'readString }'))(fromCharCode)) :
323
+ eval(makeStringBuilder())
309
324
 
310
325
  export function compareKeys(a, b) {
311
326
  // compare with type consistency that matches binary comparison
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ordered-binary",
3
3
  "author": "Kris Zyp",
4
- "version": "1.4.0",
4
+ "version": "1.4.1",
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": {
package/tests/test.js CHANGED
@@ -46,6 +46,7 @@ suite('key buffers', () => {
46
46
  assert.strictEqual(fromBufferKey(toBufferKey('')), '')
47
47
  assert.strictEqual(fromBufferKey(toBufferKey('\x00')), '\x00')
48
48
  assert.strictEqual(fromBufferKey(toBufferKey('\x03test\x01\x00')), '\x03test\x01\x00')
49
+ assert.strictEqual(fromBufferKey(toBufferKey('prance 🧚🏻‍♀️🩷')), 'prance 🧚🏻‍♀️🩷')
49
50
  })
50
51
  test('string comparison', () => {
51
52
  assertBufferComparison(toBufferKey('4'), toBufferKey('5'))