@oscarpalmer/atoms 0.78.0 → 0.80.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/array/sort.cjs +5 -10
- package/dist/array/sort.js +5 -10
- package/dist/colour/base.cjs +27 -2
- package/dist/colour/base.js +27 -2
- package/dist/colour/functions.cjs +1 -1
- package/dist/colour/functions.js +1 -1
- package/dist/colour/hsl.cjs +2 -12
- package/dist/colour/hsl.js +2 -12
- package/dist/colour/index.cjs +5 -0
- package/dist/colour/index.js +6 -1
- package/dist/colour/rgb.cjs +2 -8
- package/dist/colour/rgb.js +2 -8
- package/dist/index.cjs +5 -0
- package/dist/index.js +5 -0
- package/dist/internal/array/find.cjs +6 -7
- package/dist/internal/array/find.js +6 -7
- package/dist/value/equal.cjs +4 -1
- package/dist/value/equal.js +4 -1
- package/package.json +15 -8
- package/src/array/chunk.ts +1 -1
- package/src/array/count.ts +2 -2
- package/src/array/exists.ts +2 -2
- package/src/array/filter.ts +2 -2
- package/src/array/find.ts +2 -2
- package/src/array/group-by.ts +2 -2
- package/src/array/index-of.ts +2 -2
- package/src/array/index.ts +3 -2
- package/src/array/insert.ts +2 -2
- package/src/array/models.ts +1 -1
- package/src/array/shuffle.ts +1 -1
- package/src/array/sort.ts +13 -20
- package/src/array/splice.ts +1 -1
- package/src/array/to-map.ts +2 -2
- package/src/array/to-record.ts +60 -60
- package/src/array/unique.ts +5 -5
- package/src/colour/base.ts +48 -12
- package/src/colour/functions.ts +4 -4
- package/src/colour/hex.ts +3 -3
- package/src/colour/hsl.ts +6 -18
- package/src/colour/index.ts +2 -1
- package/src/colour/is.ts +4 -7
- package/src/colour/rgb.ts +6 -14
- package/src/emitter.ts +1 -1
- package/src/function.ts +2 -2
- package/src/index.ts +16 -16
- package/src/internal/array/callbacks.ts +2 -2
- package/src/internal/array/find.ts +10 -11
- package/src/internal/value/handle.ts +1 -1
- package/src/is.ts +2 -2
- package/src/logger.ts +1 -1
- package/src/query.ts +4 -4
- package/src/random.ts +1 -1
- package/src/sized.ts +1 -1
- package/src/string/case.ts +1 -1
- package/src/string/index.ts +2 -1
- package/src/string/template.ts +3 -3
- package/src/value/clone.ts +3 -3
- package/src/value/compare.ts +3 -3
- package/src/value/diff.ts +4 -4
- package/src/value/equal.ts +6 -3
- package/src/value/get.ts +2 -2
- package/src/value/index.ts +2 -1
- package/src/value/merge.ts +2 -2
- package/src/value/set.ts +2 -2
- package/src/value/smush.ts +3 -3
- package/src/value/unsmush.ts +3 -3
- package/types/array/count.d.ts +1 -1
- package/types/array/exists.d.ts +1 -1
- package/types/array/filter.d.ts +1 -1
- package/types/array/find.d.ts +1 -1
- package/types/array/group-by.d.ts +1 -1
- package/types/array/index-of.d.ts +1 -1
- package/types/array/index.d.ts +1 -1
- package/types/array/insert.d.ts +1 -1
- package/types/array/models.d.ts +1 -1
- package/types/array/sort.d.ts +2 -2
- package/types/array/to-map.d.ts +1 -1
- package/types/array/to-record.d.ts +1 -1
- package/types/array/unique.d.ts +1 -1
- package/types/colour/base.d.cts +9 -1
- package/types/colour/base.d.ts +12 -2
- package/types/colour/functions.d.cts +9 -1
- package/types/colour/functions.d.ts +3 -3
- package/types/colour/hex.d.cts +9 -1
- package/types/colour/hex.d.ts +2 -2
- package/types/colour/hsl.d.cts +9 -1
- package/types/colour/hsl.d.ts +3 -3
- package/types/colour/index.d.cts +27 -1
- package/types/colour/index.d.ts +2 -1
- package/types/colour/is.d.cts +10 -2
- package/types/colour/is.d.ts +4 -4
- package/types/colour/rgb.d.cts +9 -1
- package/types/colour/rgb.d.ts +3 -3
- package/types/function.d.ts +1 -1
- package/types/index.d.cts +37 -9
- package/types/index.d.ts +16 -16
- package/types/internal/array/callbacks.d.ts +1 -1
- package/types/internal/array/find.d.ts +1 -1
- package/types/internal/value/handle.d.ts +1 -1
- package/types/is.d.ts +1 -1
- package/types/models.d.cts +10 -3
- package/types/query.d.ts +1 -1
- package/types/string/template.d.ts +1 -1
- package/types/value/get.d.cts +10 -3
- package/types/value/get.d.ts +1 -1
- package/types/value/index.d.cts +10 -3
- package/types/value/index.d.ts +1 -1
- package/types/value/merge.d.ts +1 -1
- package/types/value/set.d.cts +2 -1
- package/types/value/set.d.ts +1 -1
- package/types/value/smush.d.cts +10 -3
- package/types/value/smush.d.ts +1 -1
- package/types/value/unsmush.d.ts +1 -1
package/src/array/sort.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import {isKey} from '../is';
|
|
2
|
+
import type {Key, PlainObject} from '../models';
|
|
3
|
+
import {compare} from '../value/compare';
|
|
4
|
+
import type {SortKey, SortKeyWithCallback} from './models';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Sort an array of items _(defaults to ascending)_
|
|
@@ -57,13 +57,7 @@ export function sort(
|
|
|
57
57
|
return array;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
return first === true
|
|
62
|
-
? (array as never[]).sort((first, second) => second - first)
|
|
63
|
-
: array.sort();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const direction = second === true ? 'desc' : 'asc';
|
|
60
|
+
const direction = first === true || second === true ? 'desc' : 'asc';
|
|
67
61
|
|
|
68
62
|
const keys = (Array.isArray(first) ? first : [first])
|
|
69
63
|
.map(key => {
|
|
@@ -92,9 +86,11 @@ export function sort(
|
|
|
92
86
|
const {length} = keys;
|
|
93
87
|
|
|
94
88
|
if (length === 0) {
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
return array.sort(
|
|
90
|
+
(first, second) =>
|
|
91
|
+
compare(first as never, second as never) *
|
|
92
|
+
(direction === 'asc' ? 1 : -1),
|
|
93
|
+
);
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
if (length === 1) {
|
|
@@ -109,12 +105,9 @@ export function sort(
|
|
|
109
105
|
for (let index = 0; index < length; index += 1) {
|
|
110
106
|
const {callback, direction} = keys[index];
|
|
111
107
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
callback(descending ? second : first),
|
|
116
|
-
callback(descending ? first : second),
|
|
117
|
-
);
|
|
108
|
+
const compared =
|
|
109
|
+
compare(callback(first), callback(second)) *
|
|
110
|
+
(direction === 'asc' ? 1 : -1);
|
|
118
111
|
|
|
119
112
|
if (compared !== 0) {
|
|
120
113
|
return compared;
|
package/src/array/splice.ts
CHANGED
package/src/array/to-map.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {getCallbacks} from '
|
|
2
|
-
import type {Key, PlainObject} from '
|
|
1
|
+
import {getCallbacks} from '../internal/array/callbacks';
|
|
2
|
+
import type {Key, PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Create a map from an array of items _(using their indices as keys)_
|
package/src/array/to-record.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {Simplify} from 'type-fest';
|
|
2
|
-
import {groupValues} from '
|
|
3
|
-
import type {Key, KeyedValue, PlainObject} from '
|
|
2
|
+
import {groupValues} from '../array/group-by';
|
|
3
|
+
import type {Key, KeyedValue, PlainObject} from '../models';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Create a record from an array of items _(using their indices as keys)_
|
|
@@ -11,18 +11,18 @@ export function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
|
11
11
|
* Create a record from an array of items using a specific key
|
|
12
12
|
*/
|
|
13
13
|
export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
array: Item[],
|
|
15
|
+
key: ItemKey,
|
|
16
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
20
20
|
*/
|
|
21
21
|
export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
array: Item[],
|
|
23
|
+
key: ItemKey,
|
|
24
|
+
arrays: true,
|
|
25
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Create a record from an array of items using a specific key
|
|
@@ -48,82 +48,82 @@ export function toRecord<
|
|
|
48
48
|
* Create a record from an array of items using a specific key and value
|
|
49
49
|
*/
|
|
50
50
|
export function toRecord<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
Item extends PlainObject,
|
|
52
|
+
ItemKey extends keyof Item,
|
|
53
|
+
ItemValue extends keyof Item,
|
|
54
|
+
>(
|
|
55
|
+
array: Item[],
|
|
56
|
+
key: ItemKey,
|
|
57
|
+
value: ItemValue,
|
|
58
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue]>>;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
62
62
|
*/
|
|
63
63
|
export function toRecord<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
Item extends PlainObject,
|
|
65
|
+
ItemKey extends keyof Item,
|
|
66
|
+
ItemValue extends keyof Item,
|
|
67
|
+
>(
|
|
68
|
+
array: Item[],
|
|
69
|
+
key: ItemKey,
|
|
70
|
+
value: ItemValue,
|
|
71
|
+
arrays: true,
|
|
72
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Array<Item[ItemValue]>>>;
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Create a record from an array of items using a specific key and value
|
|
76
76
|
*/
|
|
77
77
|
export function toRecord<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
Item extends PlainObject,
|
|
79
|
+
ItemKey extends keyof Item,
|
|
80
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
81
|
+
>(
|
|
82
|
+
array: Item[],
|
|
83
|
+
key: ItemKey,
|
|
84
|
+
value: ItemValue,
|
|
85
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>>;
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
89
89
|
*/
|
|
90
90
|
export function toRecord<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
Item extends PlainObject,
|
|
92
|
+
ItemKey extends keyof Item,
|
|
93
|
+
ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
|
|
94
|
+
>(
|
|
95
|
+
array: Item[],
|
|
96
|
+
key: ItemKey,
|
|
97
|
+
value: ItemValue,
|
|
98
|
+
arrays: true,
|
|
99
|
+
): Simplify<Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>>;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Create a record from an array of items using a specific key and value
|
|
103
103
|
*/
|
|
104
104
|
export function toRecord<
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
Item extends PlainObject,
|
|
106
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
107
|
+
ItemValue extends keyof Item,
|
|
108
|
+
>(
|
|
109
|
+
array: Item[],
|
|
110
|
+
key: ItemKey,
|
|
111
|
+
value: ItemValue,
|
|
112
|
+
): Record<ReturnType<ItemKey>, Item[ItemValue]>;
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
116
116
|
*/
|
|
117
117
|
export function toRecord<
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
Item extends PlainObject,
|
|
119
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
120
|
+
ItemValue extends keyof Item,
|
|
121
|
+
>(
|
|
122
|
+
array: Item[],
|
|
123
|
+
key: ItemKey,
|
|
124
|
+
value: ItemValue,
|
|
125
|
+
arrays: true,
|
|
126
|
+
): Record<ReturnType<ItemKey>, Array<Item[ItemValue]>>;
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* Create a record from an array of items using a specific key and value
|
package/src/array/unique.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {findValues} from '
|
|
2
|
-
import type {Key, PlainObject} from '
|
|
1
|
+
import {findValues} from '../internal/array/find';
|
|
2
|
+
import type {Key, PlainObject} from '../models';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Get an array of unique items
|
|
@@ -20,9 +20,9 @@ export function unique<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
|
20
20
|
* - Use `key` to find a comparison value for an item
|
|
21
21
|
*/
|
|
22
22
|
export function unique<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
Item,
|
|
24
|
+
ItemKey extends (item: Item, index: number, array: Item[]) => Key,
|
|
25
|
+
>(array: Item[], key: ItemKey): Item[];
|
|
26
26
|
|
|
27
27
|
export function unique(array: unknown[], key?: unknown): unknown[] {
|
|
28
28
|
return findValues('unique', array, [key, undefined]);
|
package/src/colour/base.ts
CHANGED
|
@@ -1,8 +1,44 @@
|
|
|
1
|
-
import type {HexColour} from '
|
|
2
|
-
import {
|
|
1
|
+
import type {HexColour} from './hex';
|
|
2
|
+
import type {HSLColourValue} from './hsl';
|
|
3
|
+
import {isColourValue} from './is';
|
|
4
|
+
import type {RGBColourValue} from './rgb';
|
|
5
|
+
|
|
6
|
+
type Defaults = {
|
|
7
|
+
hsl: HSLColourValue;
|
|
8
|
+
rgb: RGBColourValue;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type Properties = {
|
|
12
|
+
hsl: Array<keyof HSLColourValue>;
|
|
13
|
+
rgb: Array<keyof RGBColourValue>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const defaults: Defaults = {
|
|
17
|
+
hsl: {
|
|
18
|
+
hue: 0,
|
|
19
|
+
lightness: 0,
|
|
20
|
+
saturation: 0,
|
|
21
|
+
},
|
|
22
|
+
rgb: {
|
|
23
|
+
blue: 0,
|
|
24
|
+
green: 0,
|
|
25
|
+
red: 0,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const properties: Properties = {
|
|
30
|
+
hsl: ['hue', 'lightness', 'saturation'],
|
|
31
|
+
rgb: ['blue', 'green', 'red'],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function getValue<Model>(value: Model, type: keyof Properties): Model {
|
|
35
|
+
return (
|
|
36
|
+
isColourValue(value, properties[type]) ? {...value} : {...defaults[type]}
|
|
37
|
+
) as Model;
|
|
38
|
+
}
|
|
3
39
|
|
|
4
40
|
export abstract class Colour<Model> {
|
|
5
|
-
private declare readonly $colour:
|
|
41
|
+
private declare readonly $colour: keyof Properties;
|
|
6
42
|
protected declare readonly state: ColourState<Model>;
|
|
7
43
|
|
|
8
44
|
/**
|
|
@@ -12,18 +48,18 @@ export abstract class Colour<Model> {
|
|
|
12
48
|
return {...this.state.value};
|
|
13
49
|
}
|
|
14
50
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Set the current value of the colour
|
|
53
|
+
*/
|
|
54
|
+
set value(value: Model) {
|
|
55
|
+
this.state.value = getValue(value, this.$colour);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
constructor(type: keyof Properties, value: Model) {
|
|
21
59
|
this.$colour = type;
|
|
22
60
|
|
|
23
61
|
this.state = {
|
|
24
|
-
value:
|
|
25
|
-
? {...value}
|
|
26
|
-
: {...defaults},
|
|
62
|
+
value: getValue(value, type),
|
|
27
63
|
};
|
|
28
64
|
}
|
|
29
65
|
|
package/src/colour/functions.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import {clamp} from '../number';
|
|
2
|
+
import {HexColour} from './hex';
|
|
3
|
+
import {HSLColour, type HSLColourValue} from './hsl';
|
|
4
|
+
import {RGBColour, type RGBColourValue} from './rgb';
|
|
5
5
|
|
|
6
6
|
export const anyPattern = /^#*([a-f0-9]{3}){1,2}$/i;
|
|
7
7
|
const groupedPattern = /^#*([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i;
|
package/src/colour/hex.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {anyPattern, getNormalisedHex, hexToRgb} from '
|
|
2
|
-
import type {HSLColour} from '
|
|
3
|
-
import type {RGBColour} from '
|
|
1
|
+
import {anyPattern, getNormalisedHex, hexToRgb} from './functions';
|
|
2
|
+
import type {HSLColour} from './hsl';
|
|
3
|
+
import type {RGBColour} from './rgb';
|
|
4
4
|
|
|
5
5
|
type State = {
|
|
6
6
|
value: string;
|
package/src/colour/hsl.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
1
|
+
import {clamp} from '../number';
|
|
2
|
+
import {Colour} from './base';
|
|
3
|
+
import {hslToRgb} from './functions';
|
|
4
|
+
import type {HexColour} from './hex';
|
|
5
|
+
import type {RGBColour} from './rgb';
|
|
6
6
|
|
|
7
7
|
export type HSLColourValue = {
|
|
8
8
|
hue: number;
|
|
@@ -54,7 +54,7 @@ export class HSLColour extends Colour<HSLColourValue> {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
constructor(value: HSLColourValue) {
|
|
57
|
-
super('hsl', value
|
|
57
|
+
super('hsl', value);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
@@ -86,18 +86,6 @@ export class HSLColour extends Colour<HSLColourValue> {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const defaults: HSLColourValue = {
|
|
90
|
-
hue: 0,
|
|
91
|
-
lightness: 0,
|
|
92
|
-
saturation: 0,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const properties: Array<keyof HSLColourValue> = [
|
|
96
|
-
'hue',
|
|
97
|
-
'lightness',
|
|
98
|
-
'saturation',
|
|
99
|
-
];
|
|
100
|
-
|
|
101
89
|
/**
|
|
102
90
|
* Get an HSL-colour from a value-object
|
|
103
91
|
*/
|
package/src/colour/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {RGBColourValue} from '
|
|
1
|
+
import type {RGBColourValue} from './rgb';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Get a foreground colour _(usually text)_ based on a background colour's luminance
|
|
@@ -21,6 +21,7 @@ export function getForegroundColour(value: RGBColourValue): string {
|
|
|
21
21
|
return luminance > 0.625 ? 'black' : 'white';
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
export {hexToRgb, hslToRgb, rgbToHex, rgbToHsl} from './functions';
|
|
24
25
|
export {getHexColour, HexColour} from './hex';
|
|
25
26
|
export {getHSLColour, HSLColour, type HSLColourValue} from './hsl';
|
|
26
27
|
export {isColour, isHexColour, isHSLColour, isRGBColour} from './is';
|
package/src/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 './hex';
|
|
2
|
+
import type {HSLColour} from './hsl';
|
|
3
|
+
import type {RGBColour} from './rgb';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Is the value a colour?
|
|
@@ -11,10 +11,7 @@ export function isColour(
|
|
|
11
11
|
return isInstance(/^(hex|hsl|rgb)$/, value);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export function isColourValue
|
|
15
|
-
value: unknown,
|
|
16
|
-
properties: Array<keyof Expected>,
|
|
17
|
-
): value is Expected {
|
|
14
|
+
export function isColourValue(value: unknown, properties: string[]): boolean {
|
|
18
15
|
return (
|
|
19
16
|
typeof value === 'object' &&
|
|
20
17
|
value !== null &&
|
package/src/colour/rgb.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
1
|
+
import {clamp} from '../number';
|
|
2
|
+
import {Colour} from './base';
|
|
3
|
+
import {rgbToHex, rgbToHsl} from './functions';
|
|
4
|
+
import type {HexColour} from './hex';
|
|
5
|
+
import type {HSLColour} from './hsl';
|
|
6
6
|
|
|
7
7
|
export type RGBColourValue = {
|
|
8
8
|
blue: number;
|
|
@@ -54,7 +54,7 @@ export class RGBColour extends Colour<RGBColourValue> {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
constructor(value: RGBColourValue) {
|
|
57
|
-
super('rgb', value
|
|
57
|
+
super('rgb', value);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
@@ -93,14 +93,6 @@ export class RGBColour extends Colour<RGBColourValue> {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const defaults: RGBColourValue = {
|
|
97
|
-
blue: 0,
|
|
98
|
-
green: 0,
|
|
99
|
-
red: 0,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const properties: Array<keyof RGBColourValue> = ['blue', 'green', 'red'];
|
|
103
|
-
|
|
104
96
|
/**
|
|
105
97
|
* Get an RGB-colour from a value-object
|
|
106
98
|
*/
|
package/src/emitter.ts
CHANGED
package/src/function.ts
CHANGED
package/src/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';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {Callbacks} from '
|
|
2
|
-
import type {GenericCallback, PlainObject} from '
|
|
1
|
+
import type {Callbacks} from '../../array/models';
|
|
2
|
+
import type {GenericCallback, PlainObject} from '../../models';
|
|
3
3
|
|
|
4
4
|
function getCallback(value: unknown): GenericCallback | undefined {
|
|
5
5
|
switch (typeof value) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {FindType} from '
|
|
2
|
-
import {getCallbacks} from '
|
|
1
|
+
import type {FindType} from '../../array/models';
|
|
2
|
+
import {getCallbacks} from './callbacks';
|
|
3
3
|
|
|
4
4
|
type Parameters = {
|
|
5
5
|
bool?: unknown;
|
|
@@ -18,7 +18,7 @@ export function findValue(
|
|
|
18
18
|
|
|
19
19
|
if (callbacks?.bool == null && callbacks?.key == null) {
|
|
20
20
|
return type === 'index'
|
|
21
|
-
? array.
|
|
21
|
+
? array.indexOf(value)
|
|
22
22
|
: array.find(item => item === value);
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -64,25 +64,24 @@ export function findValues(
|
|
|
64
64
|
return array.filter(item => item === value);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
const keys = new Set();
|
|
67
68
|
const result: unknown[] = [];
|
|
68
|
-
const values: unknown[] = callbacks?.key != null ? [] : result;
|
|
69
69
|
|
|
70
70
|
for (let index = 0; index < length; index += 1) {
|
|
71
71
|
const item = array[index];
|
|
72
|
-
const
|
|
72
|
+
const key = callbacks?.key?.(item, index, array) ?? item;
|
|
73
73
|
|
|
74
74
|
if (
|
|
75
|
-
(type === 'all' &&
|
|
76
|
-
(type === 'unique' &&
|
|
75
|
+
(type === 'all' && key === value) ||
|
|
76
|
+
(type === 'unique' && !keys.has(key))
|
|
77
77
|
) {
|
|
78
|
-
|
|
79
|
-
values.push(keyed);
|
|
80
|
-
}
|
|
81
|
-
|
|
78
|
+
keys.add(key);
|
|
82
79
|
result.push(item);
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
|
|
83
|
+
keys.clear();
|
|
84
|
+
|
|
86
85
|
return result;
|
|
87
86
|
}
|
|
88
87
|
|
package/src/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/index';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Is the value an array or a record?
|
package/src/logger.ts
CHANGED
package/src/query.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {isPlainObject} from '
|
|
2
|
-
import type {ArrayOrPlainObject, PlainObject} from '
|
|
3
|
-
import {join} from '
|
|
4
|
-
import {setValue} from '
|
|
1
|
+
import {isPlainObject} from './is';
|
|
2
|
+
import type {ArrayOrPlainObject, PlainObject} from './models';
|
|
3
|
+
import {join} from './string/index';
|
|
4
|
+
import {setValue} from './value/set';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Convert a query string to a plain _(nested)_ object
|
package/src/random.ts
CHANGED
package/src/sized.ts
CHANGED
package/src/string/case.ts
CHANGED
package/src/string/index.ts
CHANGED