@nxtedition/lib 21.4.2 → 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 +35 -9
package/package.json
CHANGED
package/sequence.js
CHANGED
|
@@ -54,16 +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)
|
|
63
|
-
|
|
64
|
+
this.#identity = null
|
|
65
|
+
} else if (typeof part === 'number') {
|
|
66
|
+
assert(Number.isFinite(part) && part >= 0)
|
|
67
|
+
assert(Number.isFinite(identity))
|
|
68
|
+
this.#parts.push('', part)
|
|
69
|
+
} else if (part != null) {
|
|
64
70
|
assert(Number.isFinite(part.sequence) && part.sequence >= 0)
|
|
65
71
|
assert(typeof part.id === 'string' && part.id.length > 0)
|
|
66
72
|
this.#parts.push(part.id, part.sequence)
|
|
73
|
+
this.#identity = null
|
|
74
|
+
} else {
|
|
75
|
+
assert(false, part)
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
} else if (typeof value === 'string') {
|
|
@@ -77,6 +86,10 @@ export class Sequence {
|
|
|
77
86
|
this.#parts.push(id, sequence)
|
|
78
87
|
}
|
|
79
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
|
|
80
93
|
} else {
|
|
81
94
|
assert(false)
|
|
82
95
|
}
|
|
@@ -100,11 +113,15 @@ export class Sequence {
|
|
|
100
113
|
|
|
101
114
|
get identity() {
|
|
102
115
|
if (this.#identity == null) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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)
|
|
106
124
|
}
|
|
107
|
-
this.#identity = cyrb53(str, this.#parts.length)
|
|
108
125
|
}
|
|
109
126
|
|
|
110
127
|
return this.#identity
|
|
@@ -128,16 +145,25 @@ export class Sequence {
|
|
|
128
145
|
}
|
|
129
146
|
}
|
|
130
147
|
|
|
131
|
-
compare(other) {
|
|
148
|
+
compare(other, strict) {
|
|
149
|
+
if (strict === undefined) {
|
|
150
|
+
strict = true
|
|
151
|
+
}
|
|
152
|
+
|
|
132
153
|
assert(other instanceof Sequence)
|
|
154
|
+
assert(typeof strict === 'boolean')
|
|
155
|
+
|
|
156
|
+
if (strict && other.identity && this.identity) {
|
|
157
|
+
assert.strictEqual(other.identity, this.identity)
|
|
158
|
+
}
|
|
133
159
|
|
|
134
160
|
if (this.#parts.length !== other.#parts.length) {
|
|
135
161
|
return this.#parts.length - other.#parts.length
|
|
136
162
|
}
|
|
137
163
|
|
|
138
|
-
for (let n = 0; n < this.#parts.length; n
|
|
139
|
-
if (this.#parts[n] !== other.#parts[n]) {
|
|
140
|
-
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
|
|
141
167
|
}
|
|
142
168
|
}
|
|
143
169
|
|