@nxtedition/lib 19.4.0 → 19.4.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.
Files changed (3) hide show
  1. package/couch.js +4 -1
  2. package/package.json +1 -1
  3. package/sequence.js +30 -0
package/couch.js CHANGED
@@ -952,7 +952,10 @@ class ErrorHandler extends undici.DecoratorHandler {
952
952
 
953
953
  this.#error = new Error(statusText ?? statusCode)
954
954
 
955
- this.#contentType = parseContentType(this.#headers['content-type'] ?? '')?.type
955
+ this.#contentType = this.#headers['content-type']
956
+ ? parseContentType(this.#headers['content-type'] ?? '')?.type
957
+ : null
958
+
956
959
  if (this.#contentType !== 'application/json' && this.#contentType !== 'plain/text') {
957
960
  throw this.#error
958
961
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "19.4.0",
3
+ "version": "19.4.2",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/sequence.js CHANGED
@@ -2,9 +2,27 @@ import assert from 'node:assert'
2
2
 
3
3
  export const ID_SEP = '~'
4
4
 
5
+ // https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
6
+ const cyrb53 = (str, seed = 0) => {
7
+ let h1 = 0xdeadbeef ^ seed
8
+ let h2 = 0x41c6ce57 ^ seed
9
+ for (let i = 0, ch; i < str.length; i++) {
10
+ ch = str.charCodeAt(i)
11
+ h1 = Math.imul(h1 ^ ch, 2654435761)
12
+ h2 = Math.imul(h2 ^ ch, 1597334677)
13
+ }
14
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507)
15
+ h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909)
16
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507)
17
+ h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909)
18
+
19
+ return 4294967296 * (2097151 & h2) + (h1 >>> 0)
20
+ }
21
+
5
22
  export class Sequence {
6
23
  #value
7
24
  #parts = []
25
+ #identity
8
26
 
9
27
  constructor(value) {
10
28
  try {
@@ -40,6 +58,18 @@ export class Sequence {
40
58
  }
41
59
  }
42
60
 
61
+ get identity() {
62
+ if (this.#identity == null) {
63
+ let str
64
+ for (let n = 0; n < this.#parts.length; n += 2) {
65
+ str += this.#parts[n]
66
+ }
67
+ this.#identity = cyrb53(str, this.#parts.length)
68
+ }
69
+
70
+ return this.#identity
71
+ }
72
+
43
73
  get length() {
44
74
  return this.#parts.length / 2
45
75
  }