@oscarpalmer/atoms 0.74.1 → 0.76.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/js/array/chunk.cjs +18 -0
- package/dist/js/array/{chunk.mjs → chunk.js} +2 -2
- package/dist/js/array/compact.cjs +6 -0
- package/dist/js/array/{compact.mjs → compact.js} +0 -1
- package/dist/js/array/count.cjs +14 -0
- package/dist/js/array/count.js +14 -0
- package/dist/js/array/exists.cjs +14 -0
- package/dist/js/array/exists.js +14 -0
- package/dist/js/array/filter.cjs +14 -0
- package/dist/js/array/filter.js +14 -0
- package/dist/js/array/find.cjs +14 -0
- package/dist/js/array/find.js +14 -0
- package/dist/js/array/group-by.cjs +35 -0
- package/dist/js/array/group-by.js +35 -0
- package/dist/js/array/index-of.cjs +14 -0
- package/dist/js/array/index-of.js +14 -0
- package/dist/js/array/index.cjs +40 -0
- package/dist/js/array/index.js +34 -381
- package/dist/js/array/insert.cjs +31 -0
- package/dist/js/array/insert.js +31 -0
- package/dist/js/array/models.cjs +1 -0
- package/dist/js/array/models.js +1 -0
- package/dist/js/array/shuffle.cjs +13 -0
- package/dist/js/array/{shuffle.mjs → shuffle.js} +2 -3
- package/dist/js/array/sort.cjs +53 -0
- package/dist/js/array/{sort.mjs → sort.js} +13 -9
- package/dist/js/array/splice.cjs +14 -0
- package/dist/js/array/splice.js +14 -0
- package/dist/js/array/to-map.cjs +27 -0
- package/dist/js/array/to-map.js +27 -0
- package/dist/js/array/to-record.cjs +12 -0
- package/dist/js/array/to-record.js +12 -0
- package/dist/js/array/unique.cjs +7 -0
- package/dist/js/array/unique.js +7 -0
- package/dist/js/colour/base.cjs +18 -0
- package/dist/js/colour/{base.mjs → base.js} +4 -3
- package/dist/js/colour/functions.cjs +96 -0
- package/dist/js/colour/{functions.mjs → functions.js} +18 -19
- package/dist/js/colour/hex.cjs +56 -0
- package/dist/js/colour/{hex.mjs → hex.js} +34 -15
- package/dist/js/colour/hsl.cjs +85 -0
- package/dist/js/colour/{hsl.mjs → hsl.js} +40 -12
- package/dist/js/colour/index.cjs +29 -0
- package/dist/js/colour/index.js +14 -272
- package/dist/js/colour/is.cjs +27 -0
- package/dist/js/colour/{is.mjs → is.js} +7 -6
- package/dist/js/colour/rgb.cjs +87 -0
- package/dist/js/colour/{rgb.mjs → rgb.js} +43 -12
- package/dist/js/{emitter.mjs → emitter.cjs} +88 -56
- package/dist/js/emitter.js +85 -56
- package/dist/js/{function.mjs → function.cjs} +66 -46
- package/dist/js/function.js +61 -48
- package/dist/js/index.cjs +136 -0
- package/dist/js/index.js +133 -1724
- package/dist/js/internal/array/callbacks.cjs +23 -0
- package/dist/js/internal/array/callbacks.js +23 -0
- package/dist/js/internal/array/find.cjs +51 -0
- package/dist/js/internal/array/find.js +51 -0
- package/dist/js/internal/value/handle.cjs +21 -0
- package/dist/js/internal/{value-handle.mjs → value/handle.js} +0 -1
- package/dist/js/{is.mjs → is.cjs} +17 -18
- package/dist/js/is.js +15 -27
- package/dist/js/logger.cjs +108 -0
- package/dist/js/logger.js +44 -8
- package/dist/js/{math.mjs → math.cjs} +7 -8
- package/dist/js/math.js +4 -5
- package/dist/js/models.cjs +1 -0
- package/dist/js/models.js +1 -0
- package/dist/js/{number.mjs → number.cjs} +8 -8
- package/dist/js/number.js +5 -5
- package/dist/js/{query.mjs → query.cjs} +18 -18
- package/dist/js/query.js +17 -86
- package/dist/js/{queue.mjs → queue.cjs} +12 -13
- package/dist/js/queue.js +9 -10
- package/dist/js/{random.mjs → random.cjs} +14 -21
- package/dist/js/random.js +9 -26
- package/dist/js/{sized.mjs → sized.cjs} +68 -33
- package/dist/js/sized.js +66 -38
- package/dist/js/string/case.cjs +41 -0
- package/dist/js/string/{case.mjs → case.js} +13 -9
- package/dist/js/string/index.cjs +59 -0
- package/dist/js/string/index.js +30 -100
- package/dist/js/string/template.cjs +21 -0
- package/dist/js/string/{template.mjs → template.js} +4 -5
- package/dist/js/{touch.mjs → touch.cjs} +4 -7
- package/dist/js/touch.js +3 -5
- package/dist/js/value/clone.cjs +76 -0
- package/dist/js/value/{clone.mjs → clone.js} +5 -6
- package/dist/js/value/compare.cjs +59 -0
- package/dist/js/value/{compare.mjs → compare.js} +4 -6
- package/dist/js/value/diff.cjs +75 -0
- package/dist/js/value/{diff.mjs → diff.js} +13 -11
- package/dist/js/value/equal.cjs +106 -0
- package/dist/js/value/{equal.mjs → equal.js} +13 -8
- package/dist/js/value/get.cjs +21 -0
- package/dist/js/value/{get.mjs → get.js} +9 -4
- package/dist/js/value/index.cjs +30 -0
- package/dist/js/value/index.js +19 -510
- package/dist/js/value/merge.cjs +35 -0
- package/dist/js/value/{merge.mjs → merge.js} +7 -6
- package/dist/js/value/set.cjs +25 -0
- package/dist/js/value/{set.mjs → set.js} +3 -4
- package/dist/js/value/smush.cjs +26 -0
- package/dist/js/value/{smush.mjs → smush.js} +3 -4
- package/dist/js/value/unsmush.cjs +39 -0
- package/dist/js/value/{unsmush.mjs → unsmush.js} +10 -7
- package/package.json +50 -47
- package/src/js/array/chunk.ts +6 -5
- package/src/js/array/compact.ts +8 -10
- package/src/js/array/count.ts +39 -19
- package/src/js/array/exists.ts +39 -15
- package/src/js/array/filter.ts +42 -20
- package/src/js/array/find.ts +45 -20
- package/src/js/array/group-by.ts +158 -27
- package/src/js/array/index-of.ts +40 -18
- package/src/js/array/index.ts +10 -9
- package/src/js/array/insert.ts +28 -14
- package/src/js/array/models.ts +18 -15
- package/src/js/array/shuffle.ts +3 -3
- package/src/js/array/sort.ts +32 -34
- package/src/js/array/splice.ts +22 -26
- package/src/js/array/to-map.ts +133 -45
- package/src/js/array/to-record.ts +137 -39
- package/src/js/array/unique.ts +20 -15
- package/src/js/colour/base.ts +3 -3
- package/src/js/colour/functions.ts +4 -6
- package/src/js/colour/hex.ts +5 -5
- package/src/js/colour/hsl.ts +18 -12
- package/src/js/colour/index.ts +1 -1
- package/src/js/colour/is.ts +3 -3
- package/src/js/colour/rgb.ts +17 -11
- package/src/js/emitter.ts +12 -9
- package/src/js/function.ts +17 -17
- package/src/js/index.ts +16 -16
- package/src/js/internal/array/callbacks.ts +33 -0
- package/src/js/internal/{array-find.ts → array/find.ts} +23 -24
- package/src/js/internal/{value-handle.ts → value/handle.ts} +1 -1
- package/src/js/is.ts +2 -2
- package/src/js/logger.ts +14 -14
- package/src/js/math.ts +1 -1
- package/src/js/models.ts +5 -5
- package/src/js/number.ts +2 -2
- package/src/js/query.ts +6 -10
- package/src/js/queue.ts +1 -1
- package/src/js/random.ts +9 -19
- package/src/js/sized.ts +145 -145
- package/src/js/string/case.ts +1 -1
- package/src/js/string/index.ts +13 -7
- package/src/js/string/template.ts +6 -3
- package/src/js/value/clone.ts +3 -7
- package/src/js/value/compare.ts +3 -5
- package/src/js/value/diff.ts +4 -4
- package/src/js/value/equal.ts +2 -2
- package/src/js/value/get.ts +3 -3
- package/src/js/value/index.ts +2 -2
- package/src/js/value/merge.ts +3 -3
- package/src/js/value/set.ts +3 -4
- package/src/js/value/smush.ts +4 -4
- package/src/js/value/unsmush.ts +4 -4
- package/types/array/chunk.d.cts +8 -0
- package/types/array/chunk.d.ts +2 -2
- package/types/array/compact.d.cts +12 -0
- package/types/array/compact.d.ts +4 -4
- package/types/array/count.d.cts +24 -0
- package/types/array/count.d.ts +13 -7
- package/types/array/exists.d.cts +26 -0
- package/types/array/exists.d.ts +11 -3
- package/types/array/filter.d.cts +26 -0
- package/types/array/filter.d.ts +14 -6
- package/types/array/find.d.cts +26 -0
- package/types/array/find.d.ts +14 -6
- package/types/array/group-by.d.cts +58 -0
- package/types/array/group-by.d.ts +49 -5
- package/types/array/index-of.d.cts +26 -0
- package/types/array/index-of.d.ts +14 -6
- package/types/array/index.d.cts +239 -95
- package/types/array/index.d.ts +7 -6
- package/types/array/insert.d.cts +16 -0
- package/types/array/insert.d.ts +10 -5
- package/types/array/models.d.cts +14 -11
- package/types/array/models.d.ts +14 -12
- package/types/array/shuffle.d.cts +8 -0
- package/types/array/shuffle.d.ts +2 -2
- package/types/array/sort.d.cts +24 -0
- package/types/array/sort.d.ts +10 -10
- package/types/array/splice.d.cts +22 -0
- package/types/array/splice.d.ts +4 -4
- package/types/array/to-map.d.cts +61 -0
- package/types/array/to-map.d.ts +42 -20
- package/types/array/to-record.d.cts +61 -0
- package/types/array/to-record.d.ts +42 -20
- package/types/array/unique.d.cts +21 -0
- package/types/array/unique.d.ts +10 -6
- package/types/colour/base.d.cts +153 -0
- package/types/colour/base.d.ts +2 -2
- package/types/colour/functions.d.cts +173 -0
- package/types/colour/functions.d.ts +3 -3
- package/types/colour/hex.d.cts +157 -0
- package/types/colour/hex.d.ts +4 -4
- package/types/colour/hsl.d.cts +157 -0
- package/types/colour/hsl.d.ts +16 -10
- package/types/colour/index.d.cts +28 -16
- package/types/colour/index.d.ts +1 -1
- package/types/colour/is.d.cts +170 -0
- package/types/colour/is.d.ts +3 -3
- package/types/colour/rgb.d.cts +157 -0
- package/types/colour/rgb.d.ts +15 -9
- package/types/emitter.d.cts +11 -8
- package/types/emitter.d.ts +11 -8
- package/types/function.d.cts +10 -10
- package/types/function.d.ts +11 -11
- package/types/index.d.cts +1120 -736
- package/types/index.d.ts +16 -16
- package/types/internal/array/callbacks.d.cts +11 -0
- package/types/internal/array/callbacks.d.ts +2 -0
- package/types/internal/array/find.d.cts +7 -0
- package/types/internal/array/find.d.ts +3 -0
- package/types/internal/value/handle.d.cts +37 -0
- package/types/internal/{value-handle.d.ts → value/handle.d.ts} +1 -1
- package/types/is.d.ts +1 -1
- package/types/logger.d.cts +13 -21
- package/types/logger.d.ts +13 -21
- package/types/math.d.cts +1 -1
- package/types/math.d.ts +1 -1
- package/types/models.d.cts +4 -4
- package/types/models.d.ts +1 -4
- package/types/number.d.cts +2 -2
- package/types/number.d.ts +2 -2
- package/types/query.d.cts +2 -2
- package/types/query.d.ts +3 -3
- package/types/queue.d.cts +1 -1
- package/types/queue.d.ts +1 -1
- package/types/random.d.cts +8 -12
- package/types/random.d.ts +8 -12
- package/types/sized.d.cts +6 -6
- package/types/sized.d.ts +6 -6
- package/types/string/case.d.cts +28 -0
- package/types/string/index.d.cts +30 -27
- package/types/string/index.d.ts +3 -3
- package/types/string/template.d.cts +50 -0
- package/types/string/template.d.ts +4 -1
- package/types/value/clone.d.cts +8 -0
- package/types/value/clone.d.ts +4 -2
- package/types/value/compare.d.cts +8 -0
- package/types/value/diff.d.cts +25 -0
- package/types/value/equal.d.cts +12 -0
- package/types/value/get.d.cts +1319 -0
- package/types/value/get.d.ts +1 -1
- package/types/value/index.d.cts +8 -6
- package/types/value/index.d.ts +2 -2
- package/types/value/merge.d.cts +72 -0
- package/types/value/merge.d.ts +2 -2
- package/types/value/set.d.cts +1011 -0
- package/types/value/set.d.ts +1 -1
- package/types/value/smush.d.cts +1368 -0
- package/types/value/smush.d.ts +2 -2
- package/types/value/unsmush.d.cts +141 -0
- package/types/value/unsmush.d.ts +2 -2
- package/dist/js/array/count.mjs +0 -8
- package/dist/js/array/exists.mjs +0 -8
- package/dist/js/array/filter.mjs +0 -8
- package/dist/js/array/find.mjs +0 -8
- package/dist/js/array/group-by.mjs +0 -33
- package/dist/js/array/index-of.mjs +0 -8
- package/dist/js/array/index.mjs +0 -34
- package/dist/js/array/insert.mjs +0 -22
- package/dist/js/array/models.mjs +0 -0
- package/dist/js/array/splice.mjs +0 -9
- package/dist/js/array/to-map.mjs +0 -27
- package/dist/js/array/to-record.mjs +0 -8
- package/dist/js/array/unique.mjs +0 -8
- package/dist/js/colour/index.mjs +0 -30
- package/dist/js/index.mjs +0 -17
- package/dist/js/internal/array-callbacks.mjs +0 -19
- package/dist/js/internal/array-find.mjs +0 -51
- package/dist/js/logger.mjs +0 -69
- package/dist/js/models.mjs +0 -0
- package/dist/js/string/index.mjs +0 -44
- package/dist/js/value/index.mjs +0 -23
- package/src/js/internal/array-callbacks.ts +0 -28
- package/types/internal/array-callbacks.d.ts +0 -2
- package/types/internal/array-find.d.ts +0 -4
package/src/js/colour/hsl.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
1
|
+
import {Colour} from '~/colour/base';
|
|
2
|
+
import {hslToRgb} from '~/colour/functions';
|
|
3
|
+
import type {HexColour} from '~/colour/hex';
|
|
4
|
+
import type {RGBColour} from '~/colour/rgb';
|
|
5
|
+
import {clamp} from '~/number';
|
|
6
6
|
|
|
7
7
|
export type HSLColourValue = {
|
|
8
8
|
hue: number;
|
|
@@ -12,42 +12,42 @@ export type HSLColourValue = {
|
|
|
12
12
|
|
|
13
13
|
export class HSLColour extends Colour<HSLColourValue> {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Get the current hue
|
|
16
16
|
*/
|
|
17
17
|
get hue(): number {
|
|
18
18
|
return +this.state.value.hue;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Set the current hue
|
|
23
23
|
*/
|
|
24
24
|
set hue(value: number) {
|
|
25
25
|
this.state.value.hue = clamp(value, 0, 360);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Get the current lightness
|
|
30
30
|
*/
|
|
31
31
|
get lightness(): number {
|
|
32
32
|
return +this.state.value.lightness;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Set the current lightness
|
|
37
37
|
*/
|
|
38
38
|
set lightness(value: number) {
|
|
39
39
|
this.state.value.lightness = clamp(value, 0, 100);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Get the current saturation
|
|
44
44
|
*/
|
|
45
45
|
get saturation(): number {
|
|
46
46
|
return +this.state.value.saturation;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Set the current saturation
|
|
51
51
|
*/
|
|
52
52
|
set saturation(value: number) {
|
|
53
53
|
this.state.value.saturation = clamp(value, 0, 100);
|
|
@@ -57,17 +57,23 @@ export class HSLColour extends Colour<HSLColourValue> {
|
|
|
57
57
|
super('hsl', value, defaults, properties);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @inheritdoc
|
|
62
|
+
*/
|
|
60
63
|
toHex(): HexColour {
|
|
61
64
|
return HSLColour.toRgb(this.state.value).toHex();
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
/**
|
|
65
|
-
*
|
|
68
|
+
* Convert the colour to an RGB-colour
|
|
66
69
|
*/
|
|
67
70
|
toRgb(): RGBColour {
|
|
68
71
|
return HSLColour.toRgb(this.state.value);
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @inheritdoc
|
|
76
|
+
*/
|
|
71
77
|
toString(): string {
|
|
72
78
|
return `hsl(${this.state.value.hue}, ${this.state.value.saturation}%, ${this.state.value.lightness}%)`;
|
|
73
79
|
}
|
package/src/js/colour/index.ts
CHANGED
package/src/js/colour/is.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {HexColour} from '
|
|
2
|
-
import type {HSLColour} from '
|
|
3
|
-
import type {RGBColour} from '
|
|
1
|
+
import type {HexColour} from '~/colour/hex';
|
|
2
|
+
import type {HSLColour} from '~/colour/hsl';
|
|
3
|
+
import type {RGBColour} from '~/colour/rgb';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Is the value a colour?
|
package/src/js/colour/rgb.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
1
|
+
import {Colour} from '~/colour/base';
|
|
2
|
+
import {rgbToHex, rgbToHsl} from '~/colour/functions';
|
|
3
|
+
import type {HexColour} from '~/colour/hex';
|
|
4
|
+
import type {HSLColour} from '~/colour/hsl';
|
|
5
|
+
import {clamp} from '~/number';
|
|
6
6
|
|
|
7
7
|
export type RGBColourValue = {
|
|
8
8
|
blue: number;
|
|
@@ -12,42 +12,42 @@ export type RGBColourValue = {
|
|
|
12
12
|
|
|
13
13
|
export class RGBColour extends Colour<RGBColourValue> {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Get the current blue value
|
|
16
16
|
*/
|
|
17
17
|
get blue(): number {
|
|
18
18
|
return +this.state.value.blue;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Set the current blue value
|
|
23
23
|
*/
|
|
24
24
|
set blue(value: number) {
|
|
25
25
|
this.state.value.blue = clamp(value, 0, 255);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Get the current green value
|
|
30
30
|
*/
|
|
31
31
|
get green(): number {
|
|
32
32
|
return +this.state.value.green;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Set the current green value
|
|
37
37
|
*/
|
|
38
38
|
set green(value: number) {
|
|
39
39
|
this.state.value.green = clamp(value, 0, 255);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Get the current red value
|
|
44
44
|
*/
|
|
45
45
|
get red(): number {
|
|
46
46
|
return +this.state.value.red;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Set the current red value
|
|
51
51
|
*/
|
|
52
52
|
set red(value: number) {
|
|
53
53
|
this.state.value.red = clamp(value, 0, 255);
|
|
@@ -57,6 +57,9 @@ export class RGBColour extends Colour<RGBColourValue> {
|
|
|
57
57
|
super('rgb', value, defaults, properties);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @inheritdoc
|
|
62
|
+
*/
|
|
60
63
|
toHex(): HexColour {
|
|
61
64
|
return RGBColour.toHex(this.value);
|
|
62
65
|
}
|
|
@@ -68,6 +71,9 @@ export class RGBColour extends Colour<RGBColourValue> {
|
|
|
68
71
|
return RGBColour.toHsl(this.value);
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @inheritdoc
|
|
76
|
+
*/
|
|
71
77
|
toString(): string {
|
|
72
78
|
return `rgb(${this.value.red}, ${this.value.green}, ${this.value.blue})`;
|
|
73
79
|
}
|
package/src/js/emitter.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {noop} from '
|
|
1
|
+
import {noop} from '~/function';
|
|
2
2
|
|
|
3
3
|
class Emitter<Value> {
|
|
4
4
|
private declare readonly state: EmitterState<Value>;
|
|
@@ -36,14 +36,14 @@ class Emitter<Value> {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Destroy the emitter
|
|
40
40
|
*/
|
|
41
41
|
destroy(): void {
|
|
42
42
|
finishEmitter(this.state, false);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Emit a new value _(and optionally finishes the emitter)_
|
|
47
47
|
*/
|
|
48
48
|
emit(value: Value, finish?: boolean): void {
|
|
49
49
|
if (this.state.active) {
|
|
@@ -60,7 +60,7 @@ class Emitter<Value> {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Emit an error _(and optionally finishes the emitter)_
|
|
64
64
|
*/
|
|
65
65
|
error(error: Error, finish?: boolean): void {
|
|
66
66
|
if (this.state.active) {
|
|
@@ -75,7 +75,7 @@ class Emitter<Value> {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
78
|
+
* Finish the emitter
|
|
79
79
|
*/
|
|
80
80
|
finish(): void {
|
|
81
81
|
finishEmitter(this.state, true);
|
|
@@ -103,12 +103,12 @@ class Observable<Value> {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Subscribe to value changes
|
|
107
107
|
*/
|
|
108
108
|
subscribe(observer: Observer<Value>): Subscription<Value>;
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* Subscribe to value changes
|
|
112
112
|
*/
|
|
113
113
|
subscribe(
|
|
114
114
|
onNext: (value: Value) => void,
|
|
@@ -169,6 +169,9 @@ class Subscription<Value> {
|
|
|
169
169
|
return this.state.closed || !(this.state.emitter?.active ?? false);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Destroy the subscription
|
|
174
|
+
*/
|
|
172
175
|
destroy(): void {
|
|
173
176
|
this.unsubscribe();
|
|
174
177
|
|
|
@@ -177,7 +180,7 @@ class Subscription<Value> {
|
|
|
177
180
|
}
|
|
178
181
|
|
|
179
182
|
/**
|
|
180
|
-
*
|
|
183
|
+
* Unsubscribe from its observable
|
|
181
184
|
*/
|
|
182
185
|
unsubscribe(): void {
|
|
183
186
|
if (!this.state.closed) {
|
|
@@ -197,7 +200,7 @@ type SubscriptionState<Value> = {
|
|
|
197
200
|
const properties: Array<keyof Observer<never>> = ['complete', 'error', 'next'];
|
|
198
201
|
|
|
199
202
|
/**
|
|
200
|
-
*
|
|
203
|
+
* Create a new emitter
|
|
201
204
|
*/
|
|
202
205
|
export function emitter<Value>(value: Value): Emitter<Value> {
|
|
203
206
|
return new Emitter(value);
|
package/src/js/function.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {GenericCallback} from '
|
|
2
|
-
import {clamp} from '
|
|
1
|
+
import type {GenericCallback} from '~/models';
|
|
2
|
+
import {clamp} from '~/number';
|
|
3
3
|
|
|
4
4
|
type Debounced<Callback extends GenericCallback> = Callback & {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Cancel the debounce
|
|
7
7
|
*/
|
|
8
8
|
cancel: () => void;
|
|
9
9
|
};
|
|
@@ -34,21 +34,21 @@ class Memoised<Callback extends GenericCallback> {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Clear the cache
|
|
38
38
|
*/
|
|
39
39
|
clear(): void {
|
|
40
40
|
this.state.cache?.clear();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Delete a result from the cache
|
|
45
45
|
*/
|
|
46
46
|
delete(key: Parameters<Callback>[0]): boolean {
|
|
47
47
|
return this.state.cache?.delete(key);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* Destroy the instance, clearing its cache and removing its callback
|
|
52
52
|
*/
|
|
53
53
|
destroy(): void {
|
|
54
54
|
this.state.cache.clear();
|
|
@@ -58,21 +58,21 @@ class Memoised<Callback extends GenericCallback> {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Get a result from the cache if it exists _(or `undefined` otherwise)_
|
|
62
62
|
*/
|
|
63
63
|
get(key: Parameters<Callback>[0]): ReturnType<Callback> | undefined {
|
|
64
64
|
return this.state.cache?.get(key);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* Does the result exist?
|
|
69
69
|
*/
|
|
70
70
|
has(key: Parameters<Callback>[0]): boolean {
|
|
71
71
|
return this.state.cache?.has(key) ?? false;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* Get the result from the cache if it exists; otherwise runs the callback, caches the result, and returns it
|
|
76
76
|
*/
|
|
77
77
|
run(...parameters: Parameters<Callback>): ReturnType<Callback> {
|
|
78
78
|
return this.state.getter(...parameters);
|
|
@@ -85,7 +85,7 @@ type MemoisedState<Callback extends GenericCallback> = {
|
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
* -
|
|
88
|
+
* - Debounce a function, ensuring it is only called after `time` milliseconds have passed
|
|
89
89
|
* - On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
|
|
90
90
|
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
91
91
|
* - Returns the callback with an added `cancel`-method for manually cancelling the debounce
|
|
@@ -96,10 +96,10 @@ export function debounce<Callback extends GenericCallback>(
|
|
|
96
96
|
): Debounced<Callback> {
|
|
97
97
|
const interval = clamp(time ?? 0, 0, 1000);
|
|
98
98
|
|
|
99
|
-
let timer:
|
|
99
|
+
let timer: unknown;
|
|
100
100
|
|
|
101
101
|
const debounced = ((...parameters: Parameters<Callback>) => {
|
|
102
|
-
clearTimeout(timer);
|
|
102
|
+
clearTimeout(timer as never);
|
|
103
103
|
|
|
104
104
|
timer = setTimeout(() => {
|
|
105
105
|
callback(...parameters);
|
|
@@ -107,14 +107,14 @@ export function debounce<Callback extends GenericCallback>(
|
|
|
107
107
|
}) as Debounced<Callback>;
|
|
108
108
|
|
|
109
109
|
debounced.cancel = () => {
|
|
110
|
-
clearTimeout(timer);
|
|
110
|
+
clearTimeout(timer as never);
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
return debounced;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
|
-
*
|
|
117
|
+
* Memoise a function, caching and retrieving results based on the first parameter
|
|
118
118
|
*/
|
|
119
119
|
export function memoise<Callback extends GenericCallback>(
|
|
120
120
|
callback: Callback,
|
|
@@ -128,7 +128,7 @@ export function memoise<Callback extends GenericCallback>(
|
|
|
128
128
|
export function noop(): void {}
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
|
-
* -
|
|
131
|
+
* - Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
132
132
|
* - Time is clamped between _0_ and _1000_ milliseconds
|
|
133
133
|
*/
|
|
134
134
|
export function throttle<Callback extends GenericCallback>(
|
|
@@ -138,10 +138,10 @@ export function throttle<Callback extends GenericCallback>(
|
|
|
138
138
|
const interval = clamp(time ?? 0, 0, 1000);
|
|
139
139
|
|
|
140
140
|
let timestamp = performance.now();
|
|
141
|
-
let timer:
|
|
141
|
+
let timer: unknown;
|
|
142
142
|
|
|
143
143
|
return ((...parameters: Parameters<Callback>) => {
|
|
144
|
-
clearTimeout(timer);
|
|
144
|
+
clearTimeout(timer as never);
|
|
145
145
|
|
|
146
146
|
const now = performance.now();
|
|
147
147
|
const difference = now - timestamp;
|
package/src/js/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
14
|
-
export * from '
|
|
15
|
-
export * from '
|
|
16
|
-
export * from '
|
|
1
|
+
export * from '~/array/index';
|
|
2
|
+
export * from '~/colour/index';
|
|
3
|
+
export * from '~/emitter';
|
|
4
|
+
export * from '~/function';
|
|
5
|
+
export * from '~/is';
|
|
6
|
+
export * from '~/logger';
|
|
7
|
+
export * from '~/math';
|
|
8
|
+
export * from '~/models';
|
|
9
|
+
export * from '~/number';
|
|
10
|
+
export * from '~/query';
|
|
11
|
+
export * from '~/queue';
|
|
12
|
+
export * from '~/random';
|
|
13
|
+
export * from '~/sized';
|
|
14
|
+
export * from '~/string/index';
|
|
15
|
+
export * from '~/touch';
|
|
16
|
+
export * from '~/value/index';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {BooleanCallback, Callbacks, KeyCallback} from '~/array/models';
|
|
2
|
+
import type {GenericCallback, PlainObject} from '~/models';
|
|
3
|
+
|
|
4
|
+
function getCallback(value: unknown): GenericCallback | undefined {
|
|
5
|
+
switch (typeof value) {
|
|
6
|
+
case 'function':
|
|
7
|
+
return value as GenericCallback;
|
|
8
|
+
|
|
9
|
+
case 'number':
|
|
10
|
+
case 'string':
|
|
11
|
+
return typeof value === 'string' && value.includes('.')
|
|
12
|
+
? undefined
|
|
13
|
+
: (obj: PlainObject) => obj[value];
|
|
14
|
+
|
|
15
|
+
default:
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getCallbacks(
|
|
21
|
+
bool?: unknown,
|
|
22
|
+
key?: unknown,
|
|
23
|
+
value?: unknown,
|
|
24
|
+
): Callbacks | undefined {
|
|
25
|
+
if (typeof bool === 'function') {
|
|
26
|
+
return {bool: bool as BooleanCallback<unknown>};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
key: getCallback(key) as KeyCallback<unknown>,
|
|
31
|
+
value: getCallback(value) as GenericCallback,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import {getCallbacks} from './array-callbacks';
|
|
1
|
+
import type {FindType} from '~/array/models';
|
|
2
|
+
import {getCallbacks} from '~/internal/array/callbacks';
|
|
4
3
|
|
|
5
|
-
export function findValue
|
|
4
|
+
export function findValue(
|
|
6
5
|
type: FindType,
|
|
7
|
-
array:
|
|
8
|
-
|
|
9
|
-
key
|
|
6
|
+
array: unknown[],
|
|
7
|
+
bool: unknown,
|
|
8
|
+
key: unknown,
|
|
9
|
+
value: unknown,
|
|
10
10
|
): unknown {
|
|
11
|
-
const callbacks = getCallbacks(
|
|
11
|
+
const callbacks = getCallbacks(bool, key);
|
|
12
12
|
|
|
13
13
|
if (callbacks?.bool == null && callbacks?.key == null) {
|
|
14
14
|
return type === 'index'
|
|
15
|
-
? array.
|
|
15
|
+
? array.findIndex(item => item === value)
|
|
16
16
|
: array.find(item => item === value);
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -35,21 +35,21 @@ export function findValue<Model, Value = Model>(
|
|
|
35
35
|
return type === 'index' ? -1 : undefined;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function findValues
|
|
38
|
+
export function findValues(
|
|
39
39
|
type: 'all' | 'unique',
|
|
40
|
-
array:
|
|
41
|
-
|
|
42
|
-
key
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
array: unknown[],
|
|
41
|
+
bool: unknown,
|
|
42
|
+
key: unknown,
|
|
43
|
+
value: unknown,
|
|
44
|
+
): unknown[] {
|
|
45
|
+
const callbacks = getCallbacks(bool, key);
|
|
46
46
|
const {length} = array;
|
|
47
47
|
|
|
48
48
|
if (type === 'unique' && callbacks?.key == null && length >= 100) {
|
|
49
49
|
return Array.from(new Set(array));
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
if (
|
|
52
|
+
if (callbacks?.bool != null) {
|
|
53
53
|
return array.filter(callbacks.bool);
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -57,20 +57,19 @@ export function findValues<Model, Value = Model>(
|
|
|
57
57
|
return array.filter(item => item === value);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const values: unknown[] = hasCallback ? [] : result;
|
|
60
|
+
const result: unknown[] = [];
|
|
61
|
+
const values: unknown[] = callbacks?.key != null ? [] : result;
|
|
63
62
|
|
|
64
63
|
for (let index = 0; index < length; index += 1) {
|
|
65
64
|
const item = array[index];
|
|
66
|
-
const
|
|
65
|
+
const keyed = callbacks?.key?.(item, index, array) ?? item;
|
|
67
66
|
|
|
68
67
|
if (
|
|
69
|
-
(type === 'all' &&
|
|
70
|
-
(type === 'unique' && values.indexOf(
|
|
68
|
+
(type === 'all' && keyed === value) ||
|
|
69
|
+
(type === 'unique' && values.indexOf(keyed) === -1)
|
|
71
70
|
) {
|
|
72
71
|
if (values !== result) {
|
|
73
|
-
values.push(
|
|
72
|
+
values.push(keyed);
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
result.push(item);
|
package/src/js/is.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {ArrayOrPlainObject, Key, PlainObject, Primitive} from '
|
|
2
|
-
import {getString} from '
|
|
1
|
+
import type {ArrayOrPlainObject, Key, PlainObject, Primitive} from '~/models';
|
|
2
|
+
import {getString} from '~/string';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Is the value an array or a record?
|
package/src/js/logger.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {noop} from '
|
|
1
|
+
import {noop} from '~/function';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
var _atomic_logging: boolean;
|
|
@@ -10,14 +10,14 @@ if (globalThis._atomic_logging == null) {
|
|
|
10
10
|
|
|
11
11
|
class Logger {
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Log any number of values at the "debug" log level
|
|
14
14
|
*/
|
|
15
15
|
get debug() {
|
|
16
16
|
return this.enabled ? console.debug : noop;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Log the value and shows all its properties
|
|
21
21
|
*/
|
|
22
22
|
get dir() {
|
|
23
23
|
return this.enabled ? console.dir : noop;
|
|
@@ -38,49 +38,49 @@ class Logger {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Log any number of values at the "error" log level
|
|
42
42
|
*/
|
|
43
43
|
get error() {
|
|
44
44
|
return this.enabled ? console.error : noop;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Log any number of values at the "info" log level
|
|
49
49
|
*/
|
|
50
50
|
get info() {
|
|
51
51
|
return this.enabled ? console.info : noop;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Log any number of values at the "log" log level
|
|
56
56
|
*/
|
|
57
57
|
get log() {
|
|
58
58
|
return this.enabled ? console.log : noop;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Log data as a table, with optional properties to use as columns
|
|
63
63
|
*/
|
|
64
64
|
get table() {
|
|
65
65
|
return this.enabled ? console.table : noop;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Log any number of values together with a trace from where it was called
|
|
70
70
|
*/
|
|
71
71
|
get trace() {
|
|
72
72
|
return this.enabled ? console.trace : noop;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
*
|
|
76
|
+
* Log any number of values at the "warn" log level
|
|
77
77
|
*/
|
|
78
78
|
get warn() {
|
|
79
79
|
return this.enabled ? console.warn : noop;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* -
|
|
83
|
+
* - Start a logged timer with a label
|
|
84
84
|
* - Returns a `Time`-object for logging the current duration of the timer and stopping the timer _(and logging the total duration)_
|
|
85
85
|
*/
|
|
86
86
|
time(label: string): Time {
|
|
@@ -104,8 +104,8 @@ class Time {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
* -
|
|
108
|
-
* - Ignored if logging is disabled
|
|
107
|
+
* - Log the current duration of the timer
|
|
108
|
+
* - _(Ignored if logging is disabled)_
|
|
109
109
|
*/
|
|
110
110
|
log(): void {
|
|
111
111
|
if (this.state.started && !this.state.stopped && logger.enabled) {
|
|
@@ -114,8 +114,8 @@ class Time {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
|
-
* -
|
|
118
|
-
* - Will always log the total duration, even if logging is disabled
|
|
117
|
+
* - Stop the timer and logs the total duration
|
|
118
|
+
* - _(Will always log the total duration, even if logging is disabled)_
|
|
119
119
|
*/
|
|
120
120
|
stop(): void {
|
|
121
121
|
if (this.state.started && !this.state.stopped) {
|
package/src/js/math.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function min(values: number[]): number {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Round a number to a specific number of decimal places _(defaults to 0)_
|
|
24
24
|
*/
|
|
25
25
|
export function round(value: number, decimals?: number): number {
|
|
26
26
|
if (typeof decimals !== 'number' || decimals < 1) {
|