@nxtedition/lib 28.0.5 → 28.0.6

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 (2) hide show
  1. package/package.json +2 -2
  2. package/sequence.js +55 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "28.0.5",
3
+ "version": "28.0.6",
4
4
  "license": "UNLICENSED",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
@@ -92,5 +92,5 @@
92
92
  "pino": ">=7.0.0",
93
93
  "rxjs": "^7.0.0"
94
94
  },
95
- "gitHead": "f778b4c525a240411f681137d8dd0fe19031c7b0"
95
+ "gitHead": "008526f8d31968edaa2e642998deaa3880a34bb8"
96
96
  }
package/sequence.js CHANGED
@@ -26,14 +26,14 @@ export class Sequence {
26
26
  #identity
27
27
  #count = 0
28
28
 
29
- // TODO (perf): Optimize
30
29
  /**
31
30
  *
32
31
  * @param {string|Sequence|null|undefined} a
33
32
  * @param {string|Sequence|null|undefined} b
34
33
  * @param {boolean} [strict=true]
35
- * @returns
34
+ * @returns {-1|0|1}
36
35
  */
36
+ /** @deprecated */
37
37
  static compare(a, b, strict) {
38
38
  if (!a && !b) {
39
39
  return 0
@@ -58,6 +58,17 @@ export class Sequence {
58
58
  return a.compare(b, strict)
59
59
  }
60
60
 
61
+ /**
62
+ *
63
+ * @param {string|Sequence|null|undefined} a
64
+ * @param {string|Sequence|null|undefined} b
65
+ * @param {boolean} [strict=true]
66
+ * @returns {boolean}
67
+ */
68
+ static has(a, b, strict) {
69
+ return Sequence.compare(a, b, strict) >= 0
70
+ }
71
+
61
72
  /**
62
73
  *
63
74
  * @param {string} seq
@@ -75,6 +86,10 @@ export class Sequence {
75
86
  }
76
87
  }
77
88
 
89
+ /**
90
+ * @param {null|undefined|string|Sequence|Array<string|number|{id:string,sequence:number}>>} value
91
+ * @param {null|undefined|number|Array<string|{id:string}>>} [identity]
92
+ */
78
93
  constructor(value, identity) {
79
94
  try {
80
95
  if (!value) {
@@ -174,6 +189,9 @@ export class Sequence {
174
189
  }
175
190
  }
176
191
 
192
+ /**
193
+ * @returns {number}
194
+ */
177
195
  get identity() {
178
196
  if (this.#identity == null) {
179
197
  if (this.#parts.length === 0) {
@@ -190,6 +208,9 @@ export class Sequence {
190
208
  return this.#identity
191
209
  }
192
210
 
211
+ /**
212
+ * @returns {number}
213
+ */
193
214
  get count() {
194
215
  if (this.#count == null) {
195
216
  let count = 0
@@ -201,10 +222,17 @@ export class Sequence {
201
222
  return this.#count
202
223
  }
203
224
 
225
+ /**
226
+ * @returns {number}
227
+ */
204
228
  get length() {
205
229
  return this.#parts.length / 2
206
230
  }
207
231
 
232
+ /**
233
+ * @param {number} index
234
+ * @returns {number}
235
+ */
208
236
  at(index) {
209
237
  if (!Number.isInteger(index)) {
210
238
  throw new TypeError('index must be an integer')
@@ -216,6 +244,10 @@ export class Sequence {
216
244
  return this.#parts[index * 2 + 1]
217
245
  }
218
246
 
247
+ /**
248
+ * @param {number} index
249
+ * @param {number} sequence
250
+ */
219
251
  set(index, sequence) {
220
252
  if (!Number.isInteger(index)) {
221
253
  throw new TypeError('index must be an integer')
@@ -236,6 +268,7 @@ export class Sequence {
236
268
  }
237
269
  }
238
270
 
271
+ /** @deprecated */
239
272
  compare(other, strict) {
240
273
  if (strict === undefined) {
241
274
  strict = true
@@ -256,7 +289,7 @@ export class Sequence {
256
289
  throw new TypeError('strict must be a boolean')
257
290
  }
258
291
 
259
- if (strict && other.identity && this.identity && other.identity !== this.identity) {
292
+ if (strict && (other.identity || this.identity) && other.identity !== this.identity) {
260
293
  throw new Error('Cannot compare sequences with different identities')
261
294
  }
262
295
 
@@ -273,6 +306,19 @@ export class Sequence {
273
306
  return 0
274
307
  }
275
308
 
309
+ /**
310
+ *
311
+ * @param {string|Sequence|null|undefined} other
312
+ * @param {boolean} [strict=true]
313
+ * @returns {boolean}
314
+ */
315
+ has(other, strict = true) {
316
+ return this.compare(other, strict) >= 0
317
+ }
318
+
319
+ /**
320
+ * @returns {string}
321
+ */
276
322
  toString() {
277
323
  if (!this.#value) {
278
324
  let count = 0
@@ -286,10 +332,16 @@ export class Sequence {
286
332
  return this.#value
287
333
  }
288
334
 
335
+ /**
336
+ * @returns {string}
337
+ */
289
338
  [Symbol.toStringTag]() {
290
339
  return this.toString()
291
340
  }
292
341
 
342
+ /**
343
+ * @returns {string}
344
+ */
293
345
  [util.inspect.custom](depth, options, inspect) {
294
346
  return `Sequence: "${this.toString()}"`
295
347
  }