@oscarpalmer/atoms 0.71.0 → 0.73.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/dist/css/flex.css +5 -11
- package/dist/js/array/chunk.mjs +1 -1
- package/dist/js/array/count.mjs +1 -1
- package/dist/js/array/exists.mjs +1 -1
- package/dist/js/array/filter.mjs +1 -1
- package/dist/js/array/find.mjs +1 -1
- package/dist/js/array/group-by.mjs +1 -1
- package/dist/js/array/index-of.mjs +1 -1
- package/dist/js/array/index.js +141 -42
- package/dist/js/array/index.mjs +5 -5
- package/dist/js/array/insert.mjs +2 -2
- package/dist/js/array/shuffle.mjs +3 -3
- package/dist/js/array/sort.mjs +4 -11
- package/dist/js/array/splice.mjs +1 -1
- package/dist/js/array/to-map.mjs +1 -1
- package/dist/js/array/to-record.mjs +1 -1
- package/dist/js/array/unique.mjs +1 -1
- package/dist/js/colour/base.mjs +1 -1
- package/dist/js/colour/functions.mjs +17 -17
- package/dist/js/colour/hex.mjs +1 -1
- package/dist/js/colour/hsl.mjs +3 -3
- package/dist/js/colour/index.js +13 -13
- package/dist/js/colour/index.mjs +4 -4
- package/dist/js/colour/rgb.mjs +3 -3
- package/dist/js/emitter.js +28 -16
- package/dist/js/emitter.mjs +29 -17
- package/dist/js/function.js +9 -4
- package/dist/js/function.mjs +10 -5
- package/dist/js/index.js +433 -295
- package/dist/js/index.mjs +1 -1
- package/dist/js/internal/array-find.mjs +1 -1
- package/dist/js/is.js +31 -31
- package/dist/js/is.mjs +1 -1
- package/dist/js/logger.mjs +1 -1
- package/dist/js/query.js +30 -32
- package/dist/js/query.mjs +18 -18
- package/dist/js/random.js +4 -4
- package/dist/js/random.mjs +4 -4
- package/dist/js/sized.js +98 -0
- package/dist/js/sized.mjs +91 -0
- package/dist/js/string/case.mjs +1 -1
- package/dist/js/string/index.js +20 -20
- package/dist/js/string/index.mjs +1 -1
- package/dist/js/string/template.mjs +7 -6
- package/dist/js/value/clone.mjs +1 -1
- package/dist/js/value/compare.mjs +61 -0
- package/dist/js/value/diff.mjs +4 -4
- package/dist/js/value/equal.mjs +1 -1
- package/dist/js/value/get.mjs +1 -1
- package/dist/js/value/index.js +177 -85
- package/dist/js/value/index.mjs +1 -0
- package/dist/js/value/merge.mjs +1 -1
- package/dist/js/value/set.mjs +1 -3
- package/dist/js/value/smush.mjs +2 -2
- package/dist/js/value/unsmush.mjs +2 -2
- package/package.json +9 -15
- package/src/css/flex.scss +13 -22
- package/src/js/array/chunk.ts +1 -1
- package/src/js/array/sort.ts +3 -15
- package/src/js/emitter.ts +41 -24
- package/src/js/function.ts +14 -4
- package/src/js/index.ts +1 -1
- package/src/js/query.ts +2 -2
- package/src/js/random.ts +2 -4
- package/src/js/sized.ts +203 -0
- package/src/js/string/index.ts +0 -1
- package/src/js/string/template.ts +2 -1
- package/src/js/value/compare.ts +85 -0
- package/src/js/value/index.ts +12 -12
- package/src/js/value/set.ts +0 -2
- package/types/emitter.d.ts +1 -0
- package/types/function.d.ts +4 -0
- package/types/index.d.cts +255 -72
- package/types/index.d.ts +1 -1
- package/types/sized.d.ts +78 -0
- package/types/value/compare.d.ts +4 -0
- package/types/value/index.d.ts +1 -0
- package/dist/js/event.js +0 -16
- package/dist/js/event.mjs +0 -16
- package/src/js/event.ts +0 -21
- package/types/event.d.ts +0 -5
package/dist/css/flex.css
CHANGED
|
@@ -2,21 +2,16 @@
|
|
|
2
2
|
flex: 1;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
:where(.flow, .
|
|
6
|
-
.stack,
|
|
7
|
-
.stack-large,
|
|
8
|
-
.stack-small,
|
|
9
|
-
.stack-text) {
|
|
5
|
+
:where(.flow, .stack) {
|
|
10
6
|
display: flex;
|
|
11
7
|
}
|
|
12
8
|
|
|
13
|
-
:where(.flow
|
|
9
|
+
:where(.flow) {
|
|
14
10
|
flex-flow: row wrap;
|
|
15
11
|
align-items: center;
|
|
16
|
-
}
|
|
17
|
-
:where(.flow) {
|
|
18
12
|
gap: var(--flow-gap, 1rem);
|
|
19
13
|
}
|
|
14
|
+
|
|
20
15
|
:where(.flow-large) {
|
|
21
16
|
gap: var(--flow-gap-large, calc(2 * var(--flow-gap, 1rem)));
|
|
22
17
|
}
|
|
@@ -30,12 +25,11 @@
|
|
|
30
25
|
gap: var(--flow-gap-text, 1em);
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
:where(.stack, .stack-large, .stack-small, .stack-text) {
|
|
34
|
-
flex-flow: column nowrap;
|
|
35
|
-
}
|
|
36
28
|
:where(.stack) {
|
|
29
|
+
flex-flow: column nowrap;
|
|
37
30
|
gap: var(--stack-gap, 1rem);
|
|
38
31
|
}
|
|
32
|
+
|
|
39
33
|
:where(.stack-large) {
|
|
40
34
|
gap: var(--stack-gap-large, calc(2 * var(--stack-gap, 1rem)));
|
|
41
35
|
}
|
package/dist/js/array/chunk.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/js/array/chunk.ts
|
|
2
2
|
function chunk(array, size) {
|
|
3
3
|
const { length } = array;
|
|
4
|
-
const chunkSize = typeof size === "number" && size > 0 ? size :
|
|
4
|
+
const chunkSize = typeof size === "number" && size > 0 ? size : 64000;
|
|
5
5
|
if (length <= chunkSize) {
|
|
6
6
|
return [array];
|
|
7
7
|
}
|
package/dist/js/array/count.mjs
CHANGED
package/dist/js/array/exists.mjs
CHANGED
package/dist/js/array/filter.mjs
CHANGED
package/dist/js/array/find.mjs
CHANGED
package/dist/js/array/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/js/array/chunk.ts
|
|
2
2
|
function chunk(array, size) {
|
|
3
3
|
const { length } = array;
|
|
4
|
-
const chunkSize = typeof size === "number" && size > 0 ? size :
|
|
4
|
+
const chunkSize = typeof size === "number" && size > 0 ? size : 64000;
|
|
5
5
|
if (length <= chunkSize) {
|
|
6
6
|
return [array];
|
|
7
7
|
}
|
|
@@ -33,11 +33,11 @@ function insertValues(type, array, values, start, deleteCount) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// src/js/array/index.ts
|
|
36
|
-
function flatten(
|
|
37
|
-
return
|
|
36
|
+
function flatten(array) {
|
|
37
|
+
return array.flat(Number.POSITIVE_INFINITY);
|
|
38
38
|
}
|
|
39
|
-
function push(
|
|
40
|
-
return insertValues("push",
|
|
39
|
+
function push(array, values) {
|
|
40
|
+
return insertValues("push", array, values, array.length, 0);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// src/js/array/compact.ts
|
|
@@ -166,35 +166,134 @@ function getRandomInteger(min, max) {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// src/js/array/shuffle.ts
|
|
169
|
-
function
|
|
169
|
+
function shuffle(array) {
|
|
170
170
|
const shuffled = array.slice();
|
|
171
171
|
const { length } = shuffled;
|
|
172
172
|
for (let index = 0;index < length; index += 1) {
|
|
173
|
-
const
|
|
174
|
-
[shuffled[index], shuffled[
|
|
173
|
+
const random = getRandomInteger(0, length);
|
|
174
|
+
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
175
175
|
}
|
|
176
176
|
return shuffled;
|
|
177
177
|
}
|
|
178
|
-
// src/js/
|
|
179
|
-
function
|
|
180
|
-
|
|
178
|
+
// src/js/string/index.ts
|
|
179
|
+
function getString(value) {
|
|
180
|
+
if (typeof value === "string") {
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
if (typeof value !== "object" || value == null) {
|
|
184
|
+
return String(value);
|
|
185
|
+
}
|
|
186
|
+
const valueOff = value.valueOf?.() ?? value;
|
|
187
|
+
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
188
|
+
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
189
|
+
}
|
|
190
|
+
function join(value, delimiter) {
|
|
191
|
+
return compact(value).map(getString).filter((value2) => value2.trim().length > 0).join(typeof delimiter === "string" ? delimiter : "");
|
|
192
|
+
}
|
|
193
|
+
function words(value) {
|
|
194
|
+
return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
|
|
195
|
+
}
|
|
196
|
+
// src/js/math.ts
|
|
197
|
+
function max(values) {
|
|
198
|
+
return values.length > 0 ? Math.max(...values) : Number.NaN;
|
|
181
199
|
}
|
|
182
200
|
|
|
183
|
-
// src/js/
|
|
184
|
-
function
|
|
185
|
-
if (typeof
|
|
186
|
-
return
|
|
201
|
+
// src/js/number.ts
|
|
202
|
+
function getNumber(value) {
|
|
203
|
+
if (typeof value === "number") {
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
if (typeof value === "symbol") {
|
|
207
|
+
return Number.NaN;
|
|
208
|
+
}
|
|
209
|
+
let parsed = value?.valueOf?.() ?? value;
|
|
210
|
+
if (typeof parsed === "object") {
|
|
211
|
+
parsed = parsed?.toString() ?? parsed;
|
|
212
|
+
}
|
|
213
|
+
if (typeof parsed !== "string") {
|
|
214
|
+
return parsed == null ? Number.NaN : typeof parsed === "number" ? parsed : +parsed;
|
|
215
|
+
}
|
|
216
|
+
if (/^\s*0+\s*$/.test(parsed)) {
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
|
219
|
+
const trimmed = parsed.trim();
|
|
220
|
+
if (trimmed.length === 0) {
|
|
221
|
+
return Number.NaN;
|
|
222
|
+
}
|
|
223
|
+
const isBinary = /^0b[01]+$/i.test(trimmed);
|
|
224
|
+
if (isBinary || /^0o[0-7]+$/i.test(trimmed)) {
|
|
225
|
+
return Number.parseInt(trimmed.slice(2), isBinary ? 2 : 8);
|
|
226
|
+
}
|
|
227
|
+
return +(/^0x[0-9a-f]+$/i.test(trimmed) ? trimmed : trimmed.replace(/_/g, ""));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/js/value/compare.ts
|
|
231
|
+
function compare(first, second) {
|
|
232
|
+
const firstParts = getParts(first);
|
|
233
|
+
const secondParts = getParts(second);
|
|
234
|
+
const length = max([firstParts.length, secondParts.length]);
|
|
235
|
+
const lastIndex = length - 1;
|
|
236
|
+
for (let index = 0;index < length; index += 1) {
|
|
237
|
+
const firstPart = firstParts[index];
|
|
238
|
+
const secondPart = secondParts[index];
|
|
239
|
+
if (firstPart === secondPart) {
|
|
240
|
+
if (index === lastIndex) {
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (firstPart == null || typeof firstPart === "string" && firstPart.length === 0) {
|
|
246
|
+
return -1;
|
|
247
|
+
}
|
|
248
|
+
if (secondPart == null || typeof secondPart === "string" && secondPart.length === 0) {
|
|
249
|
+
return 1;
|
|
250
|
+
}
|
|
251
|
+
const firstNumber = getNumber(firstPart);
|
|
252
|
+
const secondNumber = getNumber(secondPart);
|
|
253
|
+
const firstIsNaN = Number.isNaN(firstNumber);
|
|
254
|
+
const secondIsNaN = Number.isNaN(secondNumber);
|
|
255
|
+
if (firstIsNaN || secondIsNaN) {
|
|
256
|
+
if (firstIsNaN && secondIsNaN) {
|
|
257
|
+
return getString(firstPart).localeCompare(getString(secondPart));
|
|
258
|
+
}
|
|
259
|
+
if (firstIsNaN) {
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
if (secondIsNaN) {
|
|
263
|
+
return -1;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (firstNumber === secondNumber) {
|
|
267
|
+
if (index === lastIndex) {
|
|
268
|
+
return 0;
|
|
269
|
+
}
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
return firstNumber - secondNumber;
|
|
187
273
|
}
|
|
188
|
-
|
|
189
|
-
const secondAsNumber = Number(second);
|
|
190
|
-
return Number.isNaN(firstAsNumber) || Number.isNaN(secondAsNumber) ? String(first).localeCompare(String(second)) : firstAsNumber - secondAsNumber;
|
|
274
|
+
return join(firstParts).localeCompare(join(secondParts));
|
|
191
275
|
}
|
|
192
|
-
function
|
|
193
|
-
if (
|
|
194
|
-
return
|
|
276
|
+
function getParts(value) {
|
|
277
|
+
if (value == null) {
|
|
278
|
+
return [""];
|
|
279
|
+
}
|
|
280
|
+
if (Array.isArray(value)) {
|
|
281
|
+
return value;
|
|
282
|
+
}
|
|
283
|
+
return typeof value === "object" ? [value] : words(getString(value));
|
|
284
|
+
}
|
|
285
|
+
// src/js/is.ts
|
|
286
|
+
function isKey(value) {
|
|
287
|
+
return typeof value === "number" || typeof value === "string";
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/js/array/sort.ts
|
|
291
|
+
function sort(array, first, second) {
|
|
292
|
+
if (array.length < 2) {
|
|
293
|
+
return array;
|
|
195
294
|
}
|
|
196
295
|
if (first == null || typeof first === "boolean") {
|
|
197
|
-
return first === true ?
|
|
296
|
+
return first === true ? array.sort((first2, second2) => second2 - first2) : array.sort();
|
|
198
297
|
}
|
|
199
298
|
const direction = second === true ? "desc" : "asc";
|
|
200
299
|
const keys = (Array.isArray(first) ? first : [first]).map((key) => {
|
|
@@ -203,27 +302,27 @@ function sort(array2, first, second) {
|
|
|
203
302
|
callback: undefined
|
|
204
303
|
};
|
|
205
304
|
if (isKey(key)) {
|
|
206
|
-
returned.callback = (
|
|
305
|
+
returned.callback = (value) => value[key];
|
|
207
306
|
} else if (typeof key === "function") {
|
|
208
307
|
returned.callback = key;
|
|
209
308
|
} else if (typeof key?.value === "function" || isKey(key?.value)) {
|
|
210
309
|
returned.direction = key?.direction ?? direction;
|
|
211
|
-
returned.callback = typeof key.value === "function" ? key.value : (
|
|
310
|
+
returned.callback = typeof key.value === "function" ? key.value : (value) => value[key.value];
|
|
212
311
|
}
|
|
213
312
|
return returned;
|
|
214
313
|
}).filter((key) => typeof key.callback === "function");
|
|
215
314
|
const { length } = keys;
|
|
216
315
|
if (length === 0) {
|
|
217
|
-
return direction === "asc" ?
|
|
316
|
+
return direction === "asc" ? array.sort() : array.sort((first2, second2) => second2 - first2);
|
|
218
317
|
}
|
|
219
318
|
if (length === 1) {
|
|
220
|
-
return
|
|
319
|
+
return array.sort((first2, second2) => compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1));
|
|
221
320
|
}
|
|
222
|
-
const sorted =
|
|
321
|
+
const sorted = array.sort((first2, second2) => {
|
|
223
322
|
for (let index = 0;index < length; index += 1) {
|
|
224
323
|
const { callback, direction: direction2 } = keys[index];
|
|
225
324
|
const descending = direction2 === "desc";
|
|
226
|
-
const compared =
|
|
325
|
+
const compared = compare(callback(descending ? second2 : first2), callback(descending ? first2 : second2));
|
|
227
326
|
if (compared !== 0) {
|
|
228
327
|
return compared;
|
|
229
328
|
}
|
|
@@ -233,40 +332,40 @@ function sort(array2, first, second) {
|
|
|
233
332
|
return sorted;
|
|
234
333
|
}
|
|
235
334
|
// src/js/array/splice.ts
|
|
236
|
-
function splice(
|
|
335
|
+
function splice(array, start, amountOrValues, values) {
|
|
237
336
|
const amoutOrValuesIsArray = Array.isArray(amountOrValues);
|
|
238
|
-
return insertValues("splice",
|
|
337
|
+
return insertValues("splice", array, amoutOrValuesIsArray ? amountOrValues : values ?? [], start, amoutOrValuesIsArray ? array.length : typeof amountOrValues === "number" && amountOrValues > 0 ? amountOrValues : 0);
|
|
239
338
|
}
|
|
240
339
|
// src/js/array/to-map.ts
|
|
241
|
-
function toMap(
|
|
340
|
+
function toMap(array, first, second) {
|
|
242
341
|
const asArrays = first === true || second === true;
|
|
243
342
|
const callbacks = getCallbacks(undefined, first);
|
|
244
343
|
const hasCallback = typeof callbacks?.key === "function";
|
|
245
344
|
const map = new Map;
|
|
246
|
-
const { length } =
|
|
345
|
+
const { length } = array;
|
|
247
346
|
for (let index = 0;index < length; index += 1) {
|
|
248
|
-
const
|
|
249
|
-
const key = hasCallback ? callbacks?.key?.(
|
|
347
|
+
const value = array[index];
|
|
348
|
+
const key = hasCallback ? callbacks?.key?.(value, index, array) ?? index : index;
|
|
250
349
|
if (asArrays) {
|
|
251
350
|
const existing = map.get(key);
|
|
252
351
|
if (Array.isArray(existing)) {
|
|
253
|
-
existing.push(
|
|
352
|
+
existing.push(value);
|
|
254
353
|
} else {
|
|
255
|
-
map.set(key, [
|
|
354
|
+
map.set(key, [value]);
|
|
256
355
|
}
|
|
257
356
|
} else {
|
|
258
|
-
map.set(key,
|
|
357
|
+
map.set(key, value);
|
|
259
358
|
}
|
|
260
359
|
}
|
|
261
360
|
return map;
|
|
262
361
|
}
|
|
263
362
|
// src/js/array/to-record.ts
|
|
264
|
-
function toRecord(
|
|
265
|
-
return groupValues(
|
|
363
|
+
function toRecord(array, first, second) {
|
|
364
|
+
return groupValues(array, first, first === true || second === true, true);
|
|
266
365
|
}
|
|
267
366
|
// src/js/array/unique.ts
|
|
268
|
-
function unique(
|
|
269
|
-
return findValues("unique",
|
|
367
|
+
function unique(array, key) {
|
|
368
|
+
return findValues("unique", array, undefined, key);
|
|
270
369
|
}
|
|
271
370
|
export {
|
|
272
371
|
unique,
|
|
@@ -274,7 +373,7 @@ export {
|
|
|
274
373
|
toMap,
|
|
275
374
|
splice,
|
|
276
375
|
sort,
|
|
277
|
-
|
|
376
|
+
shuffle,
|
|
278
377
|
push,
|
|
279
378
|
insert,
|
|
280
379
|
indexOf,
|
package/dist/js/array/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/js/array/index.ts
|
|
2
|
-
import {insertValues} from "./insert";
|
|
2
|
+
import { insertValues } from "./insert";
|
|
3
3
|
function flatten(array) {
|
|
4
4
|
return array.flat(Number.POSITIVE_INFINITY);
|
|
5
5
|
}
|
|
@@ -13,13 +13,13 @@ export * from "./count";
|
|
|
13
13
|
export * from "./exists";
|
|
14
14
|
export * from "./filter";
|
|
15
15
|
export * from "./find";
|
|
16
|
-
import {groupBy} from "./group-by";
|
|
16
|
+
import { groupBy } from "./group-by";
|
|
17
17
|
|
|
18
18
|
export * from "./index-of";
|
|
19
|
-
import {insert
|
|
19
|
+
import { insert } from "./insert";
|
|
20
20
|
|
|
21
21
|
export * from "./shuffle";
|
|
22
|
-
import {sort} from "./sort";
|
|
22
|
+
import { sort } from "./sort";
|
|
23
23
|
|
|
24
24
|
export * from "./splice";
|
|
25
25
|
export * from "./to-map";
|
|
@@ -28,7 +28,7 @@ export * from "./unique";
|
|
|
28
28
|
export {
|
|
29
29
|
sort,
|
|
30
30
|
push,
|
|
31
|
-
|
|
31
|
+
insert,
|
|
32
32
|
groupBy,
|
|
33
33
|
flatten
|
|
34
34
|
};
|
package/dist/js/array/insert.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/js/array/insert.ts
|
|
2
|
-
import {chunk
|
|
2
|
+
import { chunk } from "./chunk";
|
|
3
3
|
function insert(array, index, values) {
|
|
4
4
|
insertValues("splice", array, values, index, 0);
|
|
5
5
|
}
|
|
6
6
|
function insertValues(type, array, values, start, deleteCount) {
|
|
7
|
-
const chunked =
|
|
7
|
+
const chunked = chunk(values);
|
|
8
8
|
const lastIndex = chunked.length - 1;
|
|
9
9
|
let index = Number(chunked.length);
|
|
10
10
|
let returned;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/js/array/shuffle.ts
|
|
2
|
-
import {getRandomInteger} from "../random";
|
|
2
|
+
import { getRandomInteger } from "../random";
|
|
3
3
|
function shuffle(array) {
|
|
4
4
|
const shuffled = array.slice();
|
|
5
5
|
const { length } = shuffled;
|
|
6
6
|
for (let index = 0;index < length; index += 1) {
|
|
7
|
-
const
|
|
8
|
-
[shuffled[index], shuffled[
|
|
7
|
+
const random = getRandomInteger(0, length);
|
|
8
|
+
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
9
9
|
}
|
|
10
10
|
return shuffled;
|
|
11
11
|
}
|
package/dist/js/array/sort.mjs
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
// src/js/array/sort.ts
|
|
2
|
-
import {isKey} from "../is";
|
|
3
|
-
|
|
4
|
-
if (typeof first === "number" && typeof second === "number") {
|
|
5
|
-
return first - second;
|
|
6
|
-
}
|
|
7
|
-
const firstAsNumber = Number(first);
|
|
8
|
-
const secondAsNumber = Number(second);
|
|
9
|
-
return Number.isNaN(firstAsNumber) || Number.isNaN(secondAsNumber) ? String(first).localeCompare(String(second)) : firstAsNumber - secondAsNumber;
|
|
10
|
-
}
|
|
2
|
+
import { isKey } from "../is";
|
|
3
|
+
import { compare } from "../value/compare";
|
|
11
4
|
function sort(array, first, second) {
|
|
12
5
|
if (array.length < 2) {
|
|
13
6
|
return array;
|
|
@@ -36,13 +29,13 @@ function sort(array, first, second) {
|
|
|
36
29
|
return direction === "asc" ? array.sort() : array.sort((first2, second2) => second2 - first2);
|
|
37
30
|
}
|
|
38
31
|
if (length === 1) {
|
|
39
|
-
return array.sort((first2, second2) =>
|
|
32
|
+
return array.sort((first2, second2) => compare(keys[0].callback(first2), keys[0].callback(second2)) * (keys[0].direction === "asc" ? 1 : -1));
|
|
40
33
|
}
|
|
41
34
|
const sorted = array.sort((first2, second2) => {
|
|
42
35
|
for (let index = 0;index < length; index += 1) {
|
|
43
36
|
const { callback, direction: direction2 } = keys[index];
|
|
44
37
|
const descending = direction2 === "desc";
|
|
45
|
-
const compared =
|
|
38
|
+
const compared = compare(callback(descending ? second2 : first2), callback(descending ? first2 : second2));
|
|
46
39
|
if (compared !== 0) {
|
|
47
40
|
return compared;
|
|
48
41
|
}
|
package/dist/js/array/splice.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/js/array/splice.ts
|
|
2
|
-
import {insertValues} from "./insert";
|
|
2
|
+
import { insertValues } from "./insert";
|
|
3
3
|
function splice(array, start, amountOrValues, values) {
|
|
4
4
|
const amoutOrValuesIsArray = Array.isArray(amountOrValues);
|
|
5
5
|
return insertValues("splice", array, amoutOrValuesIsArray ? amountOrValues : values ?? [], start, amoutOrValuesIsArray ? array.length : typeof amountOrValues === "number" && amountOrValues > 0 ? amountOrValues : 0);
|
package/dist/js/array/to-map.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/js/array/to-map.ts
|
|
2
|
-
import {getCallbacks} from "../internal/array-callbacks";
|
|
2
|
+
import { getCallbacks } from "../internal/array-callbacks";
|
|
3
3
|
function toMap(array, first, second) {
|
|
4
4
|
const asArrays = first === true || second === true;
|
|
5
5
|
const callbacks = getCallbacks(undefined, first);
|
package/dist/js/array/unique.mjs
CHANGED
package/dist/js/colour/base.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
// src/js/colour/functions.ts
|
|
2
|
-
import {clamp} from "../number";
|
|
3
|
-
import {HexColour} from "./hex";
|
|
4
|
-
import {HSLColour} from "./hsl";
|
|
5
|
-
import {RGBColour} from "./rgb";
|
|
2
|
+
import { clamp } from "../number";
|
|
3
|
+
import { HexColour } from "./hex";
|
|
4
|
+
import { HSLColour } from "./hsl";
|
|
5
|
+
import { RGBColour } from "./rgb";
|
|
6
6
|
function getNormalisedHex(value) {
|
|
7
7
|
const normalised = value.replace(/^#/, "");
|
|
8
8
|
return normalised.length === 3 ? normalised.split("").map((character) => character.repeat(2)).join("") : normalised;
|
|
9
9
|
}
|
|
10
10
|
function hexToRgb(value) {
|
|
11
|
-
const
|
|
12
|
-
const pairs = groupedPattern.exec(
|
|
13
|
-
const
|
|
11
|
+
const hex = anyPattern.test(value) ? getNormalisedHex(value) : "";
|
|
12
|
+
const pairs = groupedPattern.exec(hex) ?? [];
|
|
13
|
+
const rgb = [];
|
|
14
14
|
const { length } = pairs;
|
|
15
15
|
for (let index = 1;index < length; index += 1) {
|
|
16
|
-
|
|
16
|
+
rgb.push(Number.parseInt(pairs[index], 16));
|
|
17
17
|
}
|
|
18
18
|
return new RGBColour({
|
|
19
|
-
blue:
|
|
20
|
-
green:
|
|
21
|
-
red:
|
|
19
|
+
blue: rgb[2] ?? 0,
|
|
20
|
+
green: rgb[1] ?? 0,
|
|
21
|
+
red: rgb[0] ?? 0
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
function hslToRgb(value) {
|
|
@@ -41,14 +41,14 @@ function hslToRgb(value) {
|
|
|
41
41
|
}
|
|
42
42
|
function rgbToHex(value) {
|
|
43
43
|
return new HexColour(`${[value.red, value.green, value.blue].map((colour) => {
|
|
44
|
-
const
|
|
45
|
-
return
|
|
44
|
+
const hex = colour.toString(16);
|
|
45
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
46
46
|
}).join("")}`);
|
|
47
47
|
}
|
|
48
|
-
function rgbToHsl(
|
|
49
|
-
const blue =
|
|
50
|
-
const green =
|
|
51
|
-
const red =
|
|
48
|
+
function rgbToHsl(rgb) {
|
|
49
|
+
const blue = rgb.blue / 255;
|
|
50
|
+
const green = rgb.green / 255;
|
|
51
|
+
const red = rgb.red / 255;
|
|
52
52
|
const max = Math.max(blue, green, red);
|
|
53
53
|
const min = Math.min(blue, green, red);
|
|
54
54
|
const delta = max - min;
|
package/dist/js/colour/hex.mjs
CHANGED
package/dist/js/colour/hsl.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/js/colour/hsl.ts
|
|
2
|
-
import {clamp} from "../number";
|
|
3
|
-
import {Colour} from "./base";
|
|
4
|
-
import {hslToRgb} from "./functions";
|
|
2
|
+
import { clamp } from "../number";
|
|
3
|
+
import { Colour } from "./base";
|
|
4
|
+
import { hslToRgb } from "./functions";
|
|
5
5
|
function getHSLColour(value) {
|
|
6
6
|
return new HSLColour(value);
|
|
7
7
|
}
|
package/dist/js/colour/index.js
CHANGED
|
@@ -160,17 +160,17 @@ function getNormalisedHex(value) {
|
|
|
160
160
|
return normalised.length === 3 ? normalised.split("").map((character) => character.repeat(2)).join("") : normalised;
|
|
161
161
|
}
|
|
162
162
|
function hexToRgb(value) {
|
|
163
|
-
const
|
|
164
|
-
const pairs = groupedPattern.exec(
|
|
165
|
-
const
|
|
163
|
+
const hex = anyPattern.test(value) ? getNormalisedHex(value) : "";
|
|
164
|
+
const pairs = groupedPattern.exec(hex) ?? [];
|
|
165
|
+
const rgb = [];
|
|
166
166
|
const { length } = pairs;
|
|
167
167
|
for (let index = 1;index < length; index += 1) {
|
|
168
|
-
|
|
168
|
+
rgb.push(Number.parseInt(pairs[index], 16));
|
|
169
169
|
}
|
|
170
170
|
return new RGBColour({
|
|
171
|
-
blue:
|
|
172
|
-
green:
|
|
173
|
-
red:
|
|
171
|
+
blue: rgb[2] ?? 0,
|
|
172
|
+
green: rgb[1] ?? 0,
|
|
173
|
+
red: rgb[0] ?? 0
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
176
|
function hslToRgb(value) {
|
|
@@ -193,14 +193,14 @@ function hslToRgb(value) {
|
|
|
193
193
|
}
|
|
194
194
|
function rgbToHex(value) {
|
|
195
195
|
return new HexColour(`${[value.red, value.green, value.blue].map((colour) => {
|
|
196
|
-
const
|
|
197
|
-
return
|
|
196
|
+
const hex = colour.toString(16);
|
|
197
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
198
198
|
}).join("")}`);
|
|
199
199
|
}
|
|
200
|
-
function rgbToHsl(
|
|
201
|
-
const blue =
|
|
202
|
-
const green =
|
|
203
|
-
const red =
|
|
200
|
+
function rgbToHsl(rgb) {
|
|
201
|
+
const blue = rgb.blue / 255;
|
|
202
|
+
const green = rgb.green / 255;
|
|
203
|
+
const red = rgb.red / 255;
|
|
204
204
|
const max = Math.max(blue, green, red);
|
|
205
205
|
const min = Math.min(blue, green, red);
|
|
206
206
|
const delta = max - min;
|
package/dist/js/colour/index.mjs
CHANGED
|
@@ -11,10 +11,10 @@ function getForegroundColour(value) {
|
|
|
11
11
|
const luminance = 0.2126 * values[2] + 0.7152 * values[1] + 0.0722 * values[0];
|
|
12
12
|
return luminance > 0.625 ? "black" : "white";
|
|
13
13
|
}
|
|
14
|
-
import {getHexColour, HexColour} from "./hex";
|
|
15
|
-
import {getHSLColour, HSLColour} from "./hsl";
|
|
16
|
-
import {isColour, isHexColour, isHSLColour, isRGBColour} from "./is";
|
|
17
|
-
import {getRGBColour, RGBColour} from "./rgb";
|
|
14
|
+
import { getHexColour, HexColour } from "./hex";
|
|
15
|
+
import { getHSLColour, HSLColour } from "./hsl";
|
|
16
|
+
import { isColour, isHexColour, isHSLColour, isRGBColour } from "./is";
|
|
17
|
+
import { getRGBColour, RGBColour } from "./rgb";
|
|
18
18
|
export {
|
|
19
19
|
isRGBColour,
|
|
20
20
|
isHexColour,
|
package/dist/js/colour/rgb.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/js/colour/rgb.ts
|
|
2
|
-
import {clamp} from "../number";
|
|
3
|
-
import {Colour} from "./base";
|
|
4
|
-
import {rgbToHex, rgbToHsl} from "./functions";
|
|
2
|
+
import { clamp } from "../number";
|
|
3
|
+
import { Colour } from "./base";
|
|
4
|
+
import { rgbToHex, rgbToHsl } from "./functions";
|
|
5
5
|
function getRGBColour(value) {
|
|
6
6
|
return new RGBColour(value);
|
|
7
7
|
}
|