@difizen/libro-common 0.0.2-alpha.0
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/LICENSE +21 -0
- package/README.md +0 -0
- package/es/array.d.ts +368 -0
- package/es/array.d.ts.map +1 -0
- package/es/array.js +577 -0
- package/es/display-wrapper.d.ts +6 -0
- package/es/display-wrapper.d.ts.map +1 -0
- package/es/display-wrapper.js +12 -0
- package/es/index.d.ts +11 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +10 -0
- package/es/iter.d.ts +147 -0
- package/es/iter.d.ts.map +1 -0
- package/es/iter.js +162 -0
- package/es/json.d.ts +126 -0
- package/es/json.d.ts.map +1 -0
- package/es/json.js +274 -0
- package/es/path.d.ts +97 -0
- package/es/path.d.ts.map +1 -0
- package/es/path.js +60 -0
- package/es/polling/index.d.ts +3 -0
- package/es/polling/index.d.ts.map +1 -0
- package/es/polling/index.js +2 -0
- package/es/polling/poll.d.ts +193 -0
- package/es/polling/poll.d.ts.map +1 -0
- package/es/polling/poll.js +501 -0
- package/es/polling/protocol.d.ts +120 -0
- package/es/polling/protocol.d.ts.map +1 -0
- package/es/polling/protocol.js +13 -0
- package/es/posix.d.ts +2 -0
- package/es/posix.d.ts.map +1 -0
- package/es/posix.js +71 -0
- package/es/protocol/cell-protocol.d.ts +181 -0
- package/es/protocol/cell-protocol.d.ts.map +1 -0
- package/es/protocol/cell-protocol.js +1 -0
- package/es/protocol/index.d.ts +4 -0
- package/es/protocol/index.d.ts.map +1 -0
- package/es/protocol/index.js +3 -0
- package/es/protocol/notebook-protocol.d.ts +63 -0
- package/es/protocol/notebook-protocol.d.ts.map +1 -0
- package/es/protocol/notebook-protocol.js +41 -0
- package/es/protocol/output-protocol.d.ts +125 -0
- package/es/protocol/output-protocol.d.ts.map +1 -0
- package/es/protocol/output-protocol.js +1 -0
- package/es/sanitizer.d.ts +44 -0
- package/es/sanitizer.d.ts.map +1 -0
- package/es/sanitizer.js +659 -0
- package/es/url.d.ts +98 -0
- package/es/url.d.ts.map +1 -0
- package/es/url.js +134 -0
- package/es/utils.d.ts +57 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +124 -0
- package/package.json +62 -0
- package/src/array.ts +608 -0
- package/src/display-wrapper.tsx +11 -0
- package/src/index.ts +10 -0
- package/src/iter.ts +199 -0
- package/src/json.ts +321 -0
- package/src/path.ts +138 -0
- package/src/polling/index.ts +2 -0
- package/src/polling/poll.ts +508 -0
- package/src/polling/protocol.ts +145 -0
- package/src/posix.ts +75 -0
- package/src/protocol/cell-protocol.ts +215 -0
- package/src/protocol/index.ts +3 -0
- package/src/protocol/notebook-protocol.ts +73 -0
- package/src/protocol/output-protocol.ts +162 -0
- package/src/sanitizer.ts +944 -0
- package/src/url.ts +157 -0
- package/src/utils.ts +145 -0
package/es/array.js
ADDED
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the index of the first occurrence of a value in an array.
|
|
3
|
+
*
|
|
4
|
+
* @param array - The array-like object to search.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The value to locate in the array. Values are
|
|
7
|
+
* compared using strict `===` equality.
|
|
8
|
+
*
|
|
9
|
+
* @param start - The index of the first element in the range to be
|
|
10
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
11
|
+
* are taken as an offset from the end of the array.
|
|
12
|
+
*
|
|
13
|
+
* @param stop - The index of the last element in the range to be
|
|
14
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
15
|
+
* are taken as an offset from the end of the array.
|
|
16
|
+
*
|
|
17
|
+
* @returns The index of the first occurrence of the value, or `-1`
|
|
18
|
+
* if the value is not found.
|
|
19
|
+
*
|
|
20
|
+
* #### Notes
|
|
21
|
+
* If `stop < start` the search will wrap at the end of the array.
|
|
22
|
+
*
|
|
23
|
+
* #### Complexity
|
|
24
|
+
* Linear.
|
|
25
|
+
*
|
|
26
|
+
* #### Undefined Behavior
|
|
27
|
+
* A `start` or `stop` which is non-integral.
|
|
28
|
+
*
|
|
29
|
+
* #### Example
|
|
30
|
+
* ```typescript
|
|
31
|
+
*
|
|
32
|
+
* let data = ['one', 'two', 'three', 'four', 'one'];
|
|
33
|
+
* firstIndexOfArray(data, 'red'); // -1
|
|
34
|
+
* firstIndexOfArray(data, 'one'); // 0
|
|
35
|
+
* firstIndexOfArray(data, 'one', 1); // 4
|
|
36
|
+
* firstIndexOfArray(data, 'two', 2); // -1
|
|
37
|
+
* firstIndexOfArray(data, 'two', 2, 1); // 1
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function firstIndexOfArray(array, value) {
|
|
41
|
+
var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
42
|
+
var stop = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
|
|
43
|
+
var n = array.length;
|
|
44
|
+
var arrStart = start;
|
|
45
|
+
var arrStop = stop;
|
|
46
|
+
if (n === 0) {
|
|
47
|
+
return -1;
|
|
48
|
+
}
|
|
49
|
+
if (arrStart < 0) {
|
|
50
|
+
arrStart = Math.max(0, arrStart + n);
|
|
51
|
+
} else {
|
|
52
|
+
arrStart = Math.min(arrStart, n - 1);
|
|
53
|
+
}
|
|
54
|
+
if (arrStop < 0) {
|
|
55
|
+
arrStop = Math.max(0, arrStop + n);
|
|
56
|
+
} else {
|
|
57
|
+
arrStop = Math.min(arrStop, n - 1);
|
|
58
|
+
}
|
|
59
|
+
var span;
|
|
60
|
+
if (arrStop < arrStart) {
|
|
61
|
+
span = arrStop + 1 + (n - arrStart);
|
|
62
|
+
} else {
|
|
63
|
+
span = arrStop - arrStart + 1;
|
|
64
|
+
}
|
|
65
|
+
for (var i = 0; i < span; ++i) {
|
|
66
|
+
var j = (arrStart + i) % n;
|
|
67
|
+
if (array[j] === value) {
|
|
68
|
+
return j;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Find the index of the first value which matches a predicate.
|
|
76
|
+
*
|
|
77
|
+
* @param array - The array-like object to search.
|
|
78
|
+
*
|
|
79
|
+
* @param fn - The predicate function to apply to the values.
|
|
80
|
+
*
|
|
81
|
+
* @param start - The index of the first element in the range to be
|
|
82
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
83
|
+
* are taken as an offset from the end of the array.
|
|
84
|
+
*
|
|
85
|
+
* @param stop - The index of the last element in the range to be
|
|
86
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
87
|
+
* are taken as an offset from the end of the array.
|
|
88
|
+
*
|
|
89
|
+
* @returns The index of the first matching value, or `-1` if no
|
|
90
|
+
* matching value is found.
|
|
91
|
+
*
|
|
92
|
+
* #### Notes
|
|
93
|
+
* If `stop < start` the search will wrap at the end of the array.
|
|
94
|
+
*
|
|
95
|
+
* #### Complexity
|
|
96
|
+
* Linear.
|
|
97
|
+
*
|
|
98
|
+
* #### Undefined Behavior
|
|
99
|
+
* A `start` or `stop` which is non-integral.
|
|
100
|
+
*
|
|
101
|
+
* Modifying the length of the array while searching.
|
|
102
|
+
*
|
|
103
|
+
* #### Example
|
|
104
|
+
* ```typescript
|
|
105
|
+
*
|
|
106
|
+
* function isEven(value: number): boolean {
|
|
107
|
+
* return value % 2 === 0;
|
|
108
|
+
* }
|
|
109
|
+
*
|
|
110
|
+
* let data = [1, 2, 3, 4, 3, 2, 1];
|
|
111
|
+
* findFirstArrayIndex(data, isEven); // 1
|
|
112
|
+
* findFirstArrayIndex(data, isEven, 4); // 5
|
|
113
|
+
* findFirstArrayIndex(data, isEven, 6); // -1
|
|
114
|
+
* findFirstArrayIndex(data, isEven, 6, 5); // 1
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export function findFirstArrayIndex(array, fn) {
|
|
118
|
+
var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
119
|
+
var stop = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
|
|
120
|
+
var n = array.length;
|
|
121
|
+
var arrStart = start;
|
|
122
|
+
var arrStop = stop;
|
|
123
|
+
if (n === 0) {
|
|
124
|
+
return -1;
|
|
125
|
+
}
|
|
126
|
+
if (arrStart < 0) {
|
|
127
|
+
arrStart = Math.max(0, arrStart + n);
|
|
128
|
+
} else {
|
|
129
|
+
arrStart = Math.min(arrStart, n - 1);
|
|
130
|
+
}
|
|
131
|
+
if (arrStop < 0) {
|
|
132
|
+
arrStop = Math.max(0, arrStop + n);
|
|
133
|
+
} else {
|
|
134
|
+
arrStop = Math.min(arrStop, n - 1);
|
|
135
|
+
}
|
|
136
|
+
var span;
|
|
137
|
+
if (arrStop < arrStart) {
|
|
138
|
+
span = arrStop + 1 + (n - arrStart);
|
|
139
|
+
} else {
|
|
140
|
+
span = arrStop - arrStart + 1;
|
|
141
|
+
}
|
|
142
|
+
for (var i = 0; i < span; ++i) {
|
|
143
|
+
var j = (arrStart + i) % n;
|
|
144
|
+
if (fn(array[j], j)) {
|
|
145
|
+
return j;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return -1;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Find the index of the last value which matches a predicate.
|
|
153
|
+
*
|
|
154
|
+
* @param object - The array-like object to search.
|
|
155
|
+
*
|
|
156
|
+
* @param fn - The predicate function to apply to the values.
|
|
157
|
+
*
|
|
158
|
+
* @param start - The index of the first element in the range to be
|
|
159
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
160
|
+
* are taken as an offset from the end of the array.
|
|
161
|
+
*
|
|
162
|
+
* @param stop - The index of the last element in the range to be
|
|
163
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
164
|
+
* are taken as an offset from the end of the array.
|
|
165
|
+
*
|
|
166
|
+
* @returns The index of the last matching value, or `-1` if no
|
|
167
|
+
* matching value is found.
|
|
168
|
+
*
|
|
169
|
+
* #### Notes
|
|
170
|
+
* If `start < stop` the search will wrap at the front of the array.
|
|
171
|
+
*
|
|
172
|
+
* #### Complexity
|
|
173
|
+
* Linear.
|
|
174
|
+
*
|
|
175
|
+
* #### Undefined Behavior
|
|
176
|
+
* A `start` or `stop` which is non-integral.
|
|
177
|
+
*
|
|
178
|
+
* Modifying the length of the array while searching.
|
|
179
|
+
*
|
|
180
|
+
* #### Example
|
|
181
|
+
* ```typescript
|
|
182
|
+
*
|
|
183
|
+
* function isEven(value: number): boolean {
|
|
184
|
+
* return value % 2 === 0;
|
|
185
|
+
* }
|
|
186
|
+
*
|
|
187
|
+
* let data = [1, 2, 3, 4, 3, 2, 1];
|
|
188
|
+
* findLastArrayIndex(data, isEven); // 5
|
|
189
|
+
* findLastArrayIndex(data, isEven, 4); // 3
|
|
190
|
+
* findLastArrayIndex(data, isEven, 0); // -1
|
|
191
|
+
* findLastArrayIndex(data, isEven, 0, 1); // 5
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export function findLastArrayIndex(array, fn) {
|
|
195
|
+
var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
|
|
196
|
+
var stop = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
197
|
+
var arrStart = start;
|
|
198
|
+
var arrStop = stop;
|
|
199
|
+
var n = array.length;
|
|
200
|
+
if (n === 0) {
|
|
201
|
+
return -1;
|
|
202
|
+
}
|
|
203
|
+
if (arrStart < 0) {
|
|
204
|
+
arrStart = Math.max(0, arrStart + n);
|
|
205
|
+
} else {
|
|
206
|
+
arrStart = Math.min(arrStart, n - 1);
|
|
207
|
+
}
|
|
208
|
+
if (arrStop < 0) {
|
|
209
|
+
arrStop = Math.max(0, arrStop + n);
|
|
210
|
+
} else {
|
|
211
|
+
arrStop = Math.min(arrStop, n - 1);
|
|
212
|
+
}
|
|
213
|
+
var d;
|
|
214
|
+
if (arrStart < arrStop) {
|
|
215
|
+
d = arrStart + 1 + (n - arrStop);
|
|
216
|
+
} else {
|
|
217
|
+
d = arrStart - arrStop + 1;
|
|
218
|
+
}
|
|
219
|
+
for (var i = 0; i < d; ++i) {
|
|
220
|
+
var j = (arrStart - i + n) % n;
|
|
221
|
+
if (fn(array[j], j)) {
|
|
222
|
+
return j;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return -1;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Find the first value which matches a predicate.
|
|
230
|
+
*
|
|
231
|
+
* @param array - The array-like object to search.
|
|
232
|
+
*
|
|
233
|
+
* @param fn - The predicate function to apply to the values.
|
|
234
|
+
*
|
|
235
|
+
* @param start - The index of the first element in the range to be
|
|
236
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
237
|
+
* are taken as an offset from the end of the array.
|
|
238
|
+
*
|
|
239
|
+
* @param stop - The index of the last element in the range to be
|
|
240
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
241
|
+
* are taken as an offset from the end of the array.
|
|
242
|
+
*
|
|
243
|
+
* @returns The first matching value, or `undefined` if no matching
|
|
244
|
+
* value is found.
|
|
245
|
+
*
|
|
246
|
+
* #### Notes
|
|
247
|
+
* If `stop < start` the search will wrap at the end of the array.
|
|
248
|
+
*
|
|
249
|
+
* #### Complexity
|
|
250
|
+
* Linear.
|
|
251
|
+
*
|
|
252
|
+
* #### Undefined Behavior
|
|
253
|
+
* A `start` or `stop` which is non-integral.
|
|
254
|
+
*
|
|
255
|
+
* Modifying the length of the array while searching.
|
|
256
|
+
*
|
|
257
|
+
* #### Example
|
|
258
|
+
* ```typescript
|
|
259
|
+
*
|
|
260
|
+
* function isEven(value: number): boolean {
|
|
261
|
+
* return value % 2 === 0;
|
|
262
|
+
* }
|
|
263
|
+
*
|
|
264
|
+
* let data = [1, 2, 3, 4, 3, 2, 1];
|
|
265
|
+
* findFirstArrayValue(data, isEven); // 2
|
|
266
|
+
* findFirstArrayValue(data, isEven, 2); // 4
|
|
267
|
+
* findFirstArrayValue(data, isEven, 6); // undefined
|
|
268
|
+
* findFirstArrayValue(data, isEven, 6, 5); // 2
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
export function findFirstArrayValue(array, fn) {
|
|
272
|
+
var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
273
|
+
var stop = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
|
|
274
|
+
var index = findFirstArrayIndex(array, fn, start, stop);
|
|
275
|
+
return index !== -1 ? array[index] : undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Find the last value which matches a predicate.
|
|
280
|
+
*
|
|
281
|
+
* @param object - The array-like object to search.
|
|
282
|
+
*
|
|
283
|
+
* @param fn - The predicate function to apply to the values.
|
|
284
|
+
*
|
|
285
|
+
* @param start - The index of the first element in the range to be
|
|
286
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
287
|
+
* are taken as an offset from the end of the array.
|
|
288
|
+
*
|
|
289
|
+
* @param stop - The index of the last element in the range to be
|
|
290
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
291
|
+
* are taken as an offset from the end of the array.
|
|
292
|
+
*
|
|
293
|
+
* @returns The last matching value, or `undefined` if no matching
|
|
294
|
+
* value is found.
|
|
295
|
+
*
|
|
296
|
+
* #### Notes
|
|
297
|
+
* If `start < stop` the search will wrap at the front of the array.
|
|
298
|
+
*
|
|
299
|
+
* #### Complexity
|
|
300
|
+
* Linear.
|
|
301
|
+
*
|
|
302
|
+
* #### Undefined Behavior
|
|
303
|
+
* A `start` or `stop` which is non-integral.
|
|
304
|
+
*
|
|
305
|
+
* Modifying the length of the array while searching.
|
|
306
|
+
*
|
|
307
|
+
* #### Example
|
|
308
|
+
* ```typescript
|
|
309
|
+
*
|
|
310
|
+
* function isEven(value: number): boolean {
|
|
311
|
+
* return value % 2 === 0;
|
|
312
|
+
* }
|
|
313
|
+
*
|
|
314
|
+
* let data = [1, 2, 3, 4, 3, 2, 1];
|
|
315
|
+
* findLastArrayValue(data, isEven); // 2
|
|
316
|
+
* findLastArrayValue(data, isEven, 4); // 4
|
|
317
|
+
* findLastArrayValue(data, isEven, 0); // undefined
|
|
318
|
+
* findLastArrayValue(data, isEven, 0, 1); // 2
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export function findLastArrayValue(array, fn) {
|
|
322
|
+
var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
|
|
323
|
+
var stop = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
324
|
+
var index = findLastArrayIndex(array, fn, start, stop);
|
|
325
|
+
return index !== -1 ? array[index] : undefined;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Find the index of the first element which compares `>=` to a value.
|
|
330
|
+
*
|
|
331
|
+
* @param array - The sorted array-like object to search.
|
|
332
|
+
*
|
|
333
|
+
* @param value - The value to locate in the array.
|
|
334
|
+
*
|
|
335
|
+
* @param fn - The 3-way comparison function to apply to the values.
|
|
336
|
+
* It should return `< 0` if an element is less than a value, `0` if
|
|
337
|
+
* an element is equal to a value, or `> 0` if an element is greater
|
|
338
|
+
* than a value.
|
|
339
|
+
*
|
|
340
|
+
* @param start - The index of the first element in the range to be
|
|
341
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
342
|
+
* are taken as an offset from the end of the array.
|
|
343
|
+
*
|
|
344
|
+
* @param stop - The index of the last element in the range to be
|
|
345
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
346
|
+
* are taken as an offset from the end of the array.
|
|
347
|
+
*
|
|
348
|
+
* @returns The index of the first element which compares `>=` to the
|
|
349
|
+
* value, or `length` if there is no such element. If the computed
|
|
350
|
+
* index for `stop` is less than `start`, then the computed index
|
|
351
|
+
* for `start` is returned.
|
|
352
|
+
*
|
|
353
|
+
* #### Notes
|
|
354
|
+
* The array must already be sorted in ascending order according to
|
|
355
|
+
* the comparison function.
|
|
356
|
+
*
|
|
357
|
+
* #### Complexity
|
|
358
|
+
* Logarithmic.
|
|
359
|
+
*
|
|
360
|
+
* #### Undefined Behavior
|
|
361
|
+
* Searching a range which is not sorted in ascending order.
|
|
362
|
+
*
|
|
363
|
+
* A `start` or `stop` which is non-integral.
|
|
364
|
+
*
|
|
365
|
+
* Modifying the length of the array while searching.
|
|
366
|
+
*
|
|
367
|
+
* #### Example
|
|
368
|
+
* ```typescript
|
|
369
|
+
*
|
|
370
|
+
* function numberCmp(a: number, b: number): number {
|
|
371
|
+
* return a - b;
|
|
372
|
+
* }
|
|
373
|
+
*
|
|
374
|
+
* let data = [0, 3, 4, 7, 7, 9];
|
|
375
|
+
* lowerArrayBound(data, 0, numberCmp); // 0
|
|
376
|
+
* lowerArrayBound(data, 6, numberCmp); // 3
|
|
377
|
+
* lowerArrayBound(data, 7, numberCmp); // 3
|
|
378
|
+
* lowerArrayBound(data, -1, numberCmp); // 0
|
|
379
|
+
* lowerArrayBound(data, 10, numberCmp); // 6
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
export function lowerArrayBound(array, value, fn) {
|
|
383
|
+
var start = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
384
|
+
var stop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
|
|
385
|
+
var arrStart = start;
|
|
386
|
+
var arrStop = stop;
|
|
387
|
+
var n = array.length;
|
|
388
|
+
if (n === 0) {
|
|
389
|
+
return 0;
|
|
390
|
+
}
|
|
391
|
+
if (arrStart < 0) {
|
|
392
|
+
arrStart = Math.max(0, arrStart + n);
|
|
393
|
+
} else {
|
|
394
|
+
arrStart = Math.min(arrStart, n - 1);
|
|
395
|
+
}
|
|
396
|
+
if (arrStop < 0) {
|
|
397
|
+
arrStop = Math.max(0, arrStop + n);
|
|
398
|
+
} else {
|
|
399
|
+
arrStop = Math.min(arrStop, n - 1);
|
|
400
|
+
}
|
|
401
|
+
var begin = arrStart;
|
|
402
|
+
var span = arrStop - arrStart + 1;
|
|
403
|
+
while (span > 0) {
|
|
404
|
+
var half = span >> 1;
|
|
405
|
+
var middle = begin + half;
|
|
406
|
+
if (fn(array[middle], value) < 0) {
|
|
407
|
+
begin = middle + 1;
|
|
408
|
+
span -= half + 1;
|
|
409
|
+
} else {
|
|
410
|
+
span = half;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return begin;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Find the index of the first element which compares `>` than a value.
|
|
418
|
+
*
|
|
419
|
+
* @param array - The sorted array-like object to search.
|
|
420
|
+
*
|
|
421
|
+
* @param value - The value to locate in the array.
|
|
422
|
+
*
|
|
423
|
+
* @param fn - The 3-way comparison function to apply to the values.
|
|
424
|
+
* It should return `< 0` if an element is less than a value, `0` if
|
|
425
|
+
* an element is equal to a value, or `> 0` if an element is greater
|
|
426
|
+
* than a value.
|
|
427
|
+
*
|
|
428
|
+
* @param start - The index of the first element in the range to be
|
|
429
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
430
|
+
* are taken as an offset from the end of the array.
|
|
431
|
+
*
|
|
432
|
+
* @param stop - The index of the last element in the range to be
|
|
433
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
434
|
+
* are taken as an offset from the end of the array.
|
|
435
|
+
*
|
|
436
|
+
* @returns The index of the first element which compares `>` than the
|
|
437
|
+
* value, or `length` if there is no such element. If the computed
|
|
438
|
+
* index for `stop` is less than `start`, then the computed index
|
|
439
|
+
* for `start` is returned.
|
|
440
|
+
*
|
|
441
|
+
* #### Notes
|
|
442
|
+
* The array must already be sorted in ascending order according to
|
|
443
|
+
* the comparison function.
|
|
444
|
+
*
|
|
445
|
+
* #### Complexity
|
|
446
|
+
* Logarithmic.
|
|
447
|
+
*
|
|
448
|
+
* #### Undefined Behavior
|
|
449
|
+
* Searching a range which is not sorted in ascending order.
|
|
450
|
+
*
|
|
451
|
+
* A `start` or `stop` which is non-integral.
|
|
452
|
+
*
|
|
453
|
+
* Modifying the length of the array while searching.
|
|
454
|
+
*
|
|
455
|
+
* #### Example
|
|
456
|
+
* ```typescript
|
|
457
|
+
*
|
|
458
|
+
* function numberCmp(a: number, b: number): number {
|
|
459
|
+
* return a - b;
|
|
460
|
+
* }
|
|
461
|
+
*
|
|
462
|
+
* let data = [0, 3, 4, 7, 7, 9];
|
|
463
|
+
* upperArrayBound(data, 0, numberCmp); // 1
|
|
464
|
+
* upperArrayBound(data, 6, numberCmp); // 3
|
|
465
|
+
* upperArrayBound(data, 7, numberCmp); // 5
|
|
466
|
+
* upperArrayBound(data, -1, numberCmp); // 0
|
|
467
|
+
* upperArrayBound(data, 10, numberCmp); // 6
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
export function upperArrayBound(array, value, fn) {
|
|
471
|
+
var start = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
472
|
+
var stop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
|
|
473
|
+
var n = array.length;
|
|
474
|
+
var arrStart = start;
|
|
475
|
+
var arrStop = stop;
|
|
476
|
+
if (n === 0) {
|
|
477
|
+
return 0;
|
|
478
|
+
}
|
|
479
|
+
if (arrStart < 0) {
|
|
480
|
+
arrStart = Math.max(0, arrStart + n);
|
|
481
|
+
} else {
|
|
482
|
+
arrStart = Math.min(arrStart, n - 1);
|
|
483
|
+
}
|
|
484
|
+
if (arrStop < 0) {
|
|
485
|
+
arrStop = Math.max(0, arrStop + n);
|
|
486
|
+
} else {
|
|
487
|
+
arrStop = Math.min(arrStop, n - 1);
|
|
488
|
+
}
|
|
489
|
+
var begin = arrStart;
|
|
490
|
+
var span = arrStop - arrStart + 1;
|
|
491
|
+
while (span > 0) {
|
|
492
|
+
var half = span >> 1;
|
|
493
|
+
var middle = begin + half;
|
|
494
|
+
if (fn(array[middle], value) > 0) {
|
|
495
|
+
span = half;
|
|
496
|
+
} else {
|
|
497
|
+
begin = middle + 1;
|
|
498
|
+
span -= half + 1;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return begin;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Remove all occurrences of values which match a predicate.
|
|
506
|
+
*
|
|
507
|
+
* @param array - The array of interest.
|
|
508
|
+
*
|
|
509
|
+
* @param fn - The predicate function to apply to the values.
|
|
510
|
+
*
|
|
511
|
+
* @param start - The index of the first element in the range to be
|
|
512
|
+
* searched, inclusive. The default value is `0`. Negative values
|
|
513
|
+
* are taken as an offset from the end of the array.
|
|
514
|
+
*
|
|
515
|
+
* @param stop - The index of the last element in the range to be
|
|
516
|
+
* searched, inclusive. The default value is `-1`. Negative values
|
|
517
|
+
* are taken as an offset from the end of the array.
|
|
518
|
+
*
|
|
519
|
+
* @returns The number of elements removed from the array.
|
|
520
|
+
*
|
|
521
|
+
* #### Notes
|
|
522
|
+
* If `stop < start` the search will conceptually wrap at the end of
|
|
523
|
+
* the array, however the array will be traversed front-to-back.
|
|
524
|
+
*
|
|
525
|
+
* #### Complexity
|
|
526
|
+
* Linear.
|
|
527
|
+
*
|
|
528
|
+
* #### Example
|
|
529
|
+
* ```typescript
|
|
530
|
+
*
|
|
531
|
+
* function isEven(value: number): boolean {
|
|
532
|
+
* return value % 2 === 0;
|
|
533
|
+
* }
|
|
534
|
+
*
|
|
535
|
+
* function isNegative(value: number): boolean {
|
|
536
|
+
* return value < 0;
|
|
537
|
+
* }
|
|
538
|
+
*
|
|
539
|
+
* let data = [0, 12, -13, -9, 23, 39, 14, -15, 12, 75];
|
|
540
|
+
* removeAllWhereFromArray(data, isEven); // 4
|
|
541
|
+
* removeAllWhereFromArray(data, isNegative, 0, 3); // 2
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
export function removeAllWhereFromArray(array, fn) {
|
|
545
|
+
var start = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
546
|
+
var stop = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
|
|
547
|
+
var n = array.length;
|
|
548
|
+
var arrStart = start;
|
|
549
|
+
var arrStop = stop;
|
|
550
|
+
if (n === 0) {
|
|
551
|
+
return 0;
|
|
552
|
+
}
|
|
553
|
+
if (arrStart < 0) {
|
|
554
|
+
arrStart = Math.max(0, arrStart + n);
|
|
555
|
+
} else {
|
|
556
|
+
arrStart = Math.min(arrStart, n - 1);
|
|
557
|
+
}
|
|
558
|
+
if (arrStop < 0) {
|
|
559
|
+
arrStop = Math.max(0, arrStop + n);
|
|
560
|
+
} else {
|
|
561
|
+
arrStop = Math.min(arrStop, n - 1);
|
|
562
|
+
}
|
|
563
|
+
var count = 0;
|
|
564
|
+
for (var i = 0; i < n; ++i) {
|
|
565
|
+
if (arrStart <= arrStop && i >= arrStart && i <= arrStop && fn(array[i], i)) {
|
|
566
|
+
count++;
|
|
567
|
+
} else if (arrStop < arrStart && (i <= arrStop || i >= arrStart) && fn(array[i], i)) {
|
|
568
|
+
count++;
|
|
569
|
+
} else if (count > 0) {
|
|
570
|
+
array[i - count] = array[i];
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (count > 0) {
|
|
574
|
+
array.length = n - count;
|
|
575
|
+
}
|
|
576
|
+
return count;
|
|
577
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display-wrapper.d.ts","sourceRoot":"","sources":["../src/display-wrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC;IAC1C,QAAQ,EAAE,GAAG,CAAC;IACd,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;CAC3B,CAKA,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export var DisplayWrapComponent = function DisplayWrapComponent(_ref) {
|
|
4
|
+
var children = _ref.children,
|
|
5
|
+
mode = _ref.mode;
|
|
6
|
+
if (mode) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return /*#__PURE__*/_jsx("div", {
|
|
10
|
+
children: children
|
|
11
|
+
});
|
|
12
|
+
};
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './array.js';
|
|
2
|
+
export * from './iter.js';
|
|
3
|
+
export * from './json.js';
|
|
4
|
+
export * from './utils.js';
|
|
5
|
+
export * from './sanitizer.js';
|
|
6
|
+
export * from './url.js';
|
|
7
|
+
export * from './path.js';
|
|
8
|
+
export * from './polling/index.js';
|
|
9
|
+
export * from './display-wrapper.js';
|
|
10
|
+
export * from './protocol/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
package/es/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./array.js";
|
|
2
|
+
export * from "./iter.js";
|
|
3
|
+
export * from "./json.js";
|
|
4
|
+
export * from "./utils.js";
|
|
5
|
+
export * from "./sanitizer.js";
|
|
6
|
+
export * from "./url.js";
|
|
7
|
+
export * from "./path.js";
|
|
8
|
+
export * from "./polling/index.js";
|
|
9
|
+
export * from "./display-wrapper.js";
|
|
10
|
+
export * from "./protocol/index.js";
|