@nxtedition/lib 21.5.0 → 21.5.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.
- package/package.json +1 -1
- package/sequence.js +25 -10
package/package.json
CHANGED
package/sequence.js
CHANGED
|
@@ -54,21 +54,25 @@ export class Sequence {
|
|
|
54
54
|
if (!value) {
|
|
55
55
|
this.#value = '0'
|
|
56
56
|
} else if (Array.isArray(value)) {
|
|
57
|
+
this.#identity = identity
|
|
57
58
|
for (const part of value) {
|
|
58
59
|
if (typeof part === 'string') {
|
|
59
60
|
const [sequenceStr, id] = part.split(ID_SEP)
|
|
60
61
|
const sequence = parseInt(sequenceStr)
|
|
61
62
|
assert(Number.isFinite(sequence) && sequence >= 0)
|
|
62
63
|
this.#parts.push(id, sequence)
|
|
64
|
+
this.#identity = null
|
|
63
65
|
} else if (typeof part === 'number') {
|
|
64
66
|
assert(Number.isFinite(part) && part >= 0)
|
|
65
67
|
assert(Number.isFinite(identity))
|
|
66
68
|
this.#parts.push('', part)
|
|
67
|
-
|
|
68
|
-
} else {
|
|
69
|
+
} else if (part != null) {
|
|
69
70
|
assert(Number.isFinite(part.sequence) && part.sequence >= 0)
|
|
70
71
|
assert(typeof part.id === 'string' && part.id.length > 0)
|
|
71
72
|
this.#parts.push(part.id, part.sequence)
|
|
73
|
+
this.#identity = null
|
|
74
|
+
} else {
|
|
75
|
+
assert(false, part)
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
} else if (typeof value === 'string') {
|
|
@@ -82,6 +86,10 @@ export class Sequence {
|
|
|
82
86
|
this.#parts.push(id, sequence)
|
|
83
87
|
}
|
|
84
88
|
this.#value = value
|
|
89
|
+
} else if (value instanceof Sequence) {
|
|
90
|
+
this.#value = value.#value
|
|
91
|
+
this.#parts = value.#parts.slice()
|
|
92
|
+
this.#identity = value.#identity
|
|
85
93
|
} else {
|
|
86
94
|
assert(false)
|
|
87
95
|
}
|
|
@@ -105,11 +113,15 @@ export class Sequence {
|
|
|
105
113
|
|
|
106
114
|
get identity() {
|
|
107
115
|
if (this.#identity == null) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
if (this.#parts.length === 0) {
|
|
117
|
+
this.#identity = 0
|
|
118
|
+
} else {
|
|
119
|
+
let str
|
|
120
|
+
for (let n = 0; n < this.#parts.length; n += 2) {
|
|
121
|
+
str += this.#parts[n]
|
|
122
|
+
}
|
|
123
|
+
this.#identity = cyrb53(str, this.#parts.length)
|
|
111
124
|
}
|
|
112
|
-
this.#identity = cyrb53(str, this.#parts.length)
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
return this.#identity
|
|
@@ -140,15 +152,18 @@ export class Sequence {
|
|
|
140
152
|
|
|
141
153
|
assert(other instanceof Sequence)
|
|
142
154
|
assert(typeof strict === 'boolean')
|
|
143
|
-
|
|
155
|
+
|
|
156
|
+
if (strict && other.identity && this.identity) {
|
|
157
|
+
assert.strictEqual(other.identity, this.identity)
|
|
158
|
+
}
|
|
144
159
|
|
|
145
160
|
if (this.#parts.length !== other.#parts.length) {
|
|
146
161
|
return this.#parts.length - other.#parts.length
|
|
147
162
|
}
|
|
148
163
|
|
|
149
|
-
for (let n = 0; n < this.#parts.length; n
|
|
150
|
-
if (this.#parts[n] !== other.#parts[n]) {
|
|
151
|
-
return this.#parts[n] < other.#parts[n] ? -1 : 1
|
|
164
|
+
for (let n = 0; n < this.#parts.length; n += 2) {
|
|
165
|
+
if (this.#parts[n + 1] !== other.#parts[n + 1]) {
|
|
166
|
+
return this.#parts[n + 1] < other.#parts[n + 1] ? -1 : 1
|
|
152
167
|
}
|
|
153
168
|
}
|
|
154
169
|
|