@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/types/value/smush.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Get, Paths, Simplify } from 'type-fest';
|
|
2
2
|
import type { ToString } from 'type-fest/source/internal/string';
|
|
3
|
-
import type { PlainObject } from '
|
|
3
|
+
import type { PlainObject } from '~/models';
|
|
4
4
|
type Smushed<Value> = Simplify<{
|
|
5
5
|
[Key in Paths<Value>]: Get<Value, ToString<Key>>;
|
|
6
6
|
}>;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Smush an object into a flat object that uses dot notation keys
|
|
9
9
|
*/
|
|
10
10
|
export declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
|
|
11
11
|
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
5
|
+
|
|
6
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
7
|
+
|
|
8
|
+
@link https://stackoverflow.com/a/49402091
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
type A = {
|
|
15
|
+
common: string;
|
|
16
|
+
a: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type B = {
|
|
20
|
+
common: string;
|
|
21
|
+
b: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type C = {
|
|
25
|
+
common: string;
|
|
26
|
+
c: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type Union = A | B | C;
|
|
30
|
+
|
|
31
|
+
type CommonKeys = keyof Union;
|
|
32
|
+
//=> 'common'
|
|
33
|
+
|
|
34
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
35
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
@category Object
|
|
39
|
+
*/
|
|
40
|
+
export type KeysOfUnion<ObjectType> = ObjectType extends unknown ? keyof ObjectType : never;
|
|
41
|
+
/**
|
|
42
|
+
Represents an object with `unknown` value. You probably want this instead of `{}`.
|
|
43
|
+
|
|
44
|
+
Use case: You have an object whose keys and values are unknown to you.
|
|
45
|
+
|
|
46
|
+
@example
|
|
47
|
+
```
|
|
48
|
+
import type {UnknownRecord} from 'type-fest';
|
|
49
|
+
|
|
50
|
+
function toJson(object: UnknownRecord) {
|
|
51
|
+
return JSON.stringify(object);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
toJson({hello: 'world'});
|
|
55
|
+
//=> '{"hello":"world"}'
|
|
56
|
+
|
|
57
|
+
function isObject(value: unknown): value is UnknownRecord {
|
|
58
|
+
return typeof value === 'object' && value !== null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
isObject({hello: 'world'});
|
|
62
|
+
//=> true
|
|
63
|
+
|
|
64
|
+
isObject('hello');
|
|
65
|
+
//=> false
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
@category Type
|
|
69
|
+
@category Object
|
|
70
|
+
*/
|
|
71
|
+
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
72
|
+
/**
|
|
73
|
+
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
74
|
+
|
|
75
|
+
@example
|
|
76
|
+
```
|
|
77
|
+
import type {Simplify} from 'type-fest';
|
|
78
|
+
|
|
79
|
+
type PositionProps = {
|
|
80
|
+
top: number;
|
|
81
|
+
left: number;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
type SizeProps = {
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
90
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
94
|
+
|
|
95
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
96
|
+
|
|
97
|
+
@example
|
|
98
|
+
```
|
|
99
|
+
import type {Simplify} from 'type-fest';
|
|
100
|
+
|
|
101
|
+
interface SomeInterface {
|
|
102
|
+
foo: number;
|
|
103
|
+
bar?: string;
|
|
104
|
+
baz: number | undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type SomeType = {
|
|
108
|
+
foo: number;
|
|
109
|
+
bar?: string;
|
|
110
|
+
baz: number | undefined;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
114
|
+
const someType: SomeType = literal;
|
|
115
|
+
const someInterface: SomeInterface = literal;
|
|
116
|
+
|
|
117
|
+
function fn(object: Record<string, unknown>): void {}
|
|
118
|
+
|
|
119
|
+
fn(literal); // Good: literal object type is sealed
|
|
120
|
+
fn(someType); // Good: type is sealed
|
|
121
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
122
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
126
|
+
@see SimplifyDeep
|
|
127
|
+
@category Object
|
|
128
|
+
*/
|
|
129
|
+
export type Simplify<T> = {
|
|
130
|
+
[KeyType in keyof T]: T[KeyType];
|
|
131
|
+
} & {};
|
|
132
|
+
export type PlainObject = UnknownRecord;
|
|
133
|
+
export type Unsmushed<Value extends PlainObject> = Simplify<Omit<{
|
|
134
|
+
[Key in KeysOfUnion<Value>]: Value[Key];
|
|
135
|
+
}, `${string}.${string}`>>;
|
|
136
|
+
/**
|
|
137
|
+
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
138
|
+
*/
|
|
139
|
+
export declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Value>;
|
|
140
|
+
|
|
141
|
+
export {};
|
package/types/value/unsmush.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { KeysOfUnion, Simplify } from 'type-fest';
|
|
2
|
-
import type { PlainObject } from '
|
|
2
|
+
import type { PlainObject } from '~/models';
|
|
3
3
|
type Unsmushed<Value extends PlainObject> = Simplify<Omit<{
|
|
4
4
|
[Key in KeysOfUnion<Value>]: Value[Key];
|
|
5
5
|
}, `${string}.${string}`>>;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
8
8
|
*/
|
|
9
9
|
export declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Value>;
|
|
10
10
|
export {};
|
package/dist/js/array/count.mjs
DELETED
package/dist/js/array/exists.mjs
DELETED
package/dist/js/array/filter.mjs
DELETED
package/dist/js/array/find.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// src/js/array/group-by.ts
|
|
2
|
-
import { getCallbacks } from "../internal/array-callbacks";
|
|
3
|
-
function groupBy(array, key) {
|
|
4
|
-
return groupValues(array, key, true, false);
|
|
5
|
-
}
|
|
6
|
-
function groupValues(array, key, arrays, indicable) {
|
|
7
|
-
const callbacks = getCallbacks(undefined, key);
|
|
8
|
-
const hasCallback = typeof callbacks?.key === "function";
|
|
9
|
-
if (!hasCallback && !indicable) {
|
|
10
|
-
return {};
|
|
11
|
-
}
|
|
12
|
-
const record = {};
|
|
13
|
-
const { length } = array;
|
|
14
|
-
for (let index = 0;index < length; index += 1) {
|
|
15
|
-
const value = array[index];
|
|
16
|
-
const key2 = hasCallback ? callbacks?.key?.(value, index, array) ?? index : index;
|
|
17
|
-
if (arrays) {
|
|
18
|
-
const existing = record[key2];
|
|
19
|
-
if (Array.isArray(existing)) {
|
|
20
|
-
existing.push(value);
|
|
21
|
-
} else {
|
|
22
|
-
record[key2] = [value];
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
record[key2] = value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return record;
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
groupValues,
|
|
32
|
-
groupBy
|
|
33
|
-
};
|
package/dist/js/array/index.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// src/js/array/index.ts
|
|
2
|
-
import { insertValues } from "./insert";
|
|
3
|
-
function flatten(array) {
|
|
4
|
-
return array.flat(Number.POSITIVE_INFINITY);
|
|
5
|
-
}
|
|
6
|
-
function push(array, values) {
|
|
7
|
-
return insertValues("push", array, values, array.length, 0);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export * from "./chunk";
|
|
11
|
-
export * from "./compact";
|
|
12
|
-
export * from "./count";
|
|
13
|
-
export * from "./exists";
|
|
14
|
-
export * from "./filter";
|
|
15
|
-
export * from "./find";
|
|
16
|
-
import { groupBy } from "./group-by";
|
|
17
|
-
|
|
18
|
-
export * from "./index-of";
|
|
19
|
-
import { insert } from "./insert";
|
|
20
|
-
|
|
21
|
-
export * from "./shuffle";
|
|
22
|
-
import { sort } from "./sort";
|
|
23
|
-
|
|
24
|
-
export * from "./splice";
|
|
25
|
-
export * from "./to-map";
|
|
26
|
-
export * from "./to-record";
|
|
27
|
-
export * from "./unique";
|
|
28
|
-
export {
|
|
29
|
-
sort,
|
|
30
|
-
push,
|
|
31
|
-
insert,
|
|
32
|
-
groupBy,
|
|
33
|
-
flatten
|
|
34
|
-
};
|
package/dist/js/array/insert.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// src/js/array/insert.ts
|
|
2
|
-
import { chunk } from "./chunk";
|
|
3
|
-
function insert(array, index, values) {
|
|
4
|
-
insertValues("splice", array, values, index, 0);
|
|
5
|
-
}
|
|
6
|
-
function insertValues(type, array, values, start, deleteCount) {
|
|
7
|
-
const chunked = chunk(values);
|
|
8
|
-
const lastIndex = chunked.length - 1;
|
|
9
|
-
let index = Number(chunked.length);
|
|
10
|
-
let returned;
|
|
11
|
-
while (--index >= 0) {
|
|
12
|
-
const result = array.splice(start, index === lastIndex ? deleteCount : 0, ...chunked[index]);
|
|
13
|
-
if (returned == null) {
|
|
14
|
-
returned = result;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return type === "splice" ? returned : array.length;
|
|
18
|
-
}
|
|
19
|
-
export {
|
|
20
|
-
insertValues,
|
|
21
|
-
insert
|
|
22
|
-
};
|
package/dist/js/array/models.mjs
DELETED
|
File without changes
|
package/dist/js/array/splice.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// src/js/array/splice.ts
|
|
2
|
-
import { insertValues } from "./insert";
|
|
3
|
-
function splice(array, start, amountOrValues, values) {
|
|
4
|
-
const amoutOrValuesIsArray = Array.isArray(amountOrValues);
|
|
5
|
-
return insertValues("splice", array, amoutOrValuesIsArray ? amountOrValues : values ?? [], start, amoutOrValuesIsArray ? array.length : typeof amountOrValues === "number" && amountOrValues > 0 ? amountOrValues : 0);
|
|
6
|
-
}
|
|
7
|
-
export {
|
|
8
|
-
splice
|
|
9
|
-
};
|
package/dist/js/array/to-map.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/js/array/to-map.ts
|
|
2
|
-
import { getCallbacks } from "../internal/array-callbacks";
|
|
3
|
-
function toMap(array, first, second) {
|
|
4
|
-
const asArrays = first === true || second === true;
|
|
5
|
-
const callbacks = getCallbacks(undefined, first);
|
|
6
|
-
const hasCallback = typeof callbacks?.key === "function";
|
|
7
|
-
const map = new Map;
|
|
8
|
-
const { length } = array;
|
|
9
|
-
for (let index = 0;index < length; index += 1) {
|
|
10
|
-
const value = array[index];
|
|
11
|
-
const key = hasCallback ? callbacks?.key?.(value, index, array) ?? index : index;
|
|
12
|
-
if (asArrays) {
|
|
13
|
-
const existing = map.get(key);
|
|
14
|
-
if (Array.isArray(existing)) {
|
|
15
|
-
existing.push(value);
|
|
16
|
-
} else {
|
|
17
|
-
map.set(key, [value]);
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
map.set(key, value);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return map;
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
toMap
|
|
27
|
-
};
|
package/dist/js/array/unique.mjs
DELETED
package/dist/js/colour/index.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// src/js/colour/index.ts
|
|
2
|
-
function getForegroundColour(value) {
|
|
3
|
-
const values = [value.blue / 255, value.green / 255, value.red / 255];
|
|
4
|
-
for (let colour of values) {
|
|
5
|
-
if (colour <= 0.03928) {
|
|
6
|
-
colour /= 12.92;
|
|
7
|
-
} else {
|
|
8
|
-
colour = ((colour + 0.055) / 1.055) ** 2.4;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
const luminance = 0.2126 * values[2] + 0.7152 * values[1] + 0.0722 * values[0];
|
|
12
|
-
return luminance > 0.625 ? "black" : "white";
|
|
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";
|
|
18
|
-
export {
|
|
19
|
-
isRGBColour,
|
|
20
|
-
isHexColour,
|
|
21
|
-
isHSLColour,
|
|
22
|
-
isColour,
|
|
23
|
-
getRGBColour,
|
|
24
|
-
getHexColour,
|
|
25
|
-
getHSLColour,
|
|
26
|
-
getForegroundColour,
|
|
27
|
-
RGBColour,
|
|
28
|
-
HexColour,
|
|
29
|
-
HSLColour
|
|
30
|
-
};
|
package/dist/js/index.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/js/index.ts
|
|
2
|
-
export * from "./array/index";
|
|
3
|
-
export * from "./colour/index";
|
|
4
|
-
export * from "./emitter";
|
|
5
|
-
export * from "./function";
|
|
6
|
-
export * from "./is";
|
|
7
|
-
export * from "./logger";
|
|
8
|
-
export * from "./math";
|
|
9
|
-
export * from "./models";
|
|
10
|
-
export * from "./number";
|
|
11
|
-
export * from "./query";
|
|
12
|
-
export * from "./queue";
|
|
13
|
-
export * from "./random";
|
|
14
|
-
export * from "./sized";
|
|
15
|
-
export * from "./string/index";
|
|
16
|
-
export * from "./touch";
|
|
17
|
-
export * from "./value/index";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// src/js/internal/array-callbacks.ts
|
|
2
|
-
function getCallbacks(bool, key) {
|
|
3
|
-
if (typeof bool === "function") {
|
|
4
|
-
return { bool };
|
|
5
|
-
}
|
|
6
|
-
if (typeof key === "function") {
|
|
7
|
-
return { key };
|
|
8
|
-
}
|
|
9
|
-
const isString = typeof key === "string";
|
|
10
|
-
if (!isString && typeof key !== "number" || isString && key.includes(".")) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
key: (value) => value?.[key]
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export {
|
|
18
|
-
getCallbacks
|
|
19
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// src/js/internal/array-find.ts
|
|
2
|
-
import { getCallbacks } from "./array-callbacks";
|
|
3
|
-
function findValue(type, array, value, key) {
|
|
4
|
-
const callbacks = getCallbacks(value, key);
|
|
5
|
-
if (callbacks?.bool == null && callbacks?.key == null) {
|
|
6
|
-
return type === "index" ? array.indexOf(value) : array.find((item) => item === value);
|
|
7
|
-
}
|
|
8
|
-
if (callbacks.bool != null) {
|
|
9
|
-
const index = array.findIndex(callbacks.bool);
|
|
10
|
-
return type === "index" ? index : index > -1 ? array[index] : undefined;
|
|
11
|
-
}
|
|
12
|
-
const { length } = array;
|
|
13
|
-
for (let index = 0;index < length; index += 1) {
|
|
14
|
-
const item = array[index];
|
|
15
|
-
if (callbacks.key?.(item, index, array) === value) {
|
|
16
|
-
return type === "index" ? index : item;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return type === "index" ? -1 : undefined;
|
|
20
|
-
}
|
|
21
|
-
function findValues(type, array, value, key) {
|
|
22
|
-
const callbacks = getCallbacks(value, key);
|
|
23
|
-
const { length } = array;
|
|
24
|
-
if (type === "unique" && callbacks?.key == null && length >= 100) {
|
|
25
|
-
return Array.from(new Set(array));
|
|
26
|
-
}
|
|
27
|
-
if (typeof callbacks?.bool === "function") {
|
|
28
|
-
return array.filter(callbacks.bool);
|
|
29
|
-
}
|
|
30
|
-
if (type === "all" && key == null) {
|
|
31
|
-
return array.filter((item) => item === value);
|
|
32
|
-
}
|
|
33
|
-
const hasCallback = typeof callbacks?.key === "function";
|
|
34
|
-
const result = [];
|
|
35
|
-
const values = hasCallback ? [] : result;
|
|
36
|
-
for (let index = 0;index < length; index += 1) {
|
|
37
|
-
const item = array[index];
|
|
38
|
-
const itemKey = hasCallback ? callbacks.key?.(item, index, array) : item;
|
|
39
|
-
if (type === "all" && itemKey === value || type === "unique" && values.indexOf(itemKey) === -1) {
|
|
40
|
-
if (values !== result) {
|
|
41
|
-
values.push(itemKey);
|
|
42
|
-
}
|
|
43
|
-
result.push(item);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
export {
|
|
49
|
-
findValues,
|
|
50
|
-
findValue
|
|
51
|
-
};
|
package/dist/js/logger.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// src/js/logger.ts
|
|
2
|
-
import { noop } from "./function";
|
|
3
|
-
if (globalThis._atomic_logging == null) {
|
|
4
|
-
globalThis._atomic_logging = true;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
class Logger {
|
|
8
|
-
get debug() {
|
|
9
|
-
return this.enabled ? console.debug : noop;
|
|
10
|
-
}
|
|
11
|
-
get dir() {
|
|
12
|
-
return this.enabled ? console.dir : noop;
|
|
13
|
-
}
|
|
14
|
-
get enabled() {
|
|
15
|
-
return globalThis._atomic_logging ?? true;
|
|
16
|
-
}
|
|
17
|
-
set enabled(value) {
|
|
18
|
-
globalThis._atomic_logging = value;
|
|
19
|
-
}
|
|
20
|
-
get error() {
|
|
21
|
-
return this.enabled ? console.error : noop;
|
|
22
|
-
}
|
|
23
|
-
get info() {
|
|
24
|
-
return this.enabled ? console.info : noop;
|
|
25
|
-
}
|
|
26
|
-
get log() {
|
|
27
|
-
return this.enabled ? console.log : noop;
|
|
28
|
-
}
|
|
29
|
-
get table() {
|
|
30
|
-
return this.enabled ? console.table : noop;
|
|
31
|
-
}
|
|
32
|
-
get trace() {
|
|
33
|
-
return this.enabled ? console.trace : noop;
|
|
34
|
-
}
|
|
35
|
-
get warn() {
|
|
36
|
-
return this.enabled ? console.warn : noop;
|
|
37
|
-
}
|
|
38
|
-
time(label) {
|
|
39
|
-
return new Time(label);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class Time {
|
|
44
|
-
constructor(label) {
|
|
45
|
-
this.state = {
|
|
46
|
-
label,
|
|
47
|
-
started: globalThis._atomic_logging ?? true,
|
|
48
|
-
stopped: false
|
|
49
|
-
};
|
|
50
|
-
if (this.state.started) {
|
|
51
|
-
console.time(label);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
log() {
|
|
55
|
-
if (this.state.started && !this.state.stopped && logger.enabled) {
|
|
56
|
-
console.timeLog(this.state.label);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
stop() {
|
|
60
|
-
if (this.state.started && !this.state.stopped) {
|
|
61
|
-
this.state.stopped = true;
|
|
62
|
-
console.timeEnd(this.state.label);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
var logger = new Logger;
|
|
67
|
-
export {
|
|
68
|
-
logger
|
|
69
|
-
};
|
package/dist/js/models.mjs
DELETED
|
File without changes
|
package/dist/js/string/index.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// src/js/string/index.ts
|
|
2
|
-
import { compact } from "../array";
|
|
3
|
-
function createUuid() {
|
|
4
|
-
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (substring) => (substring ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> substring / 4).toString(16));
|
|
5
|
-
}
|
|
6
|
-
function getString(value) {
|
|
7
|
-
if (typeof value === "string") {
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
if (typeof value !== "object" || value == null) {
|
|
11
|
-
return String(value);
|
|
12
|
-
}
|
|
13
|
-
const valueOff = value.valueOf?.() ?? value;
|
|
14
|
-
const asString = valueOff?.toString?.() ?? String(valueOff);
|
|
15
|
-
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
16
|
-
}
|
|
17
|
-
function join(value, delimiter) {
|
|
18
|
-
return compact(value).map(getString).filter((value2) => value2.trim().length > 0).join(typeof delimiter === "string" ? delimiter : "");
|
|
19
|
-
}
|
|
20
|
-
function parse(value, reviver) {
|
|
21
|
-
try {
|
|
22
|
-
return JSON.parse(value, reviver);
|
|
23
|
-
} catch {
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function truncate(value, length, suffix) {
|
|
27
|
-
const suffixLength = suffix?.length ?? 0;
|
|
28
|
-
const truncatedLength = length - suffixLength;
|
|
29
|
-
return value.length <= length ? value : `${value.slice(0, truncatedLength)}${suffix ?? ""}`;
|
|
30
|
-
}
|
|
31
|
-
function words(value) {
|
|
32
|
-
return value.match(/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g) ?? [];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export * from "./case";
|
|
36
|
-
export * from "./template";
|
|
37
|
-
export {
|
|
38
|
-
words,
|
|
39
|
-
truncate,
|
|
40
|
-
parse,
|
|
41
|
-
join,
|
|
42
|
-
getString,
|
|
43
|
-
createUuid
|
|
44
|
-
};
|
package/dist/js/value/index.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// src/js/value/index.ts
|
|
2
|
-
function partial(value, keys) {
|
|
3
|
-
const result = {};
|
|
4
|
-
const { length } = keys;
|
|
5
|
-
for (let index = 0;index < length; index += 1) {
|
|
6
|
-
const key = keys[index];
|
|
7
|
-
result[key] = value[key];
|
|
8
|
-
}
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export * from "./clone";
|
|
13
|
-
export * from "./compare";
|
|
14
|
-
export * from "./diff";
|
|
15
|
-
export * from "./equal";
|
|
16
|
-
export * from "./get";
|
|
17
|
-
export * from "./merge";
|
|
18
|
-
export * from "./set";
|
|
19
|
-
export * from "./smush";
|
|
20
|
-
export * from "./unsmush";
|
|
21
|
-
export {
|
|
22
|
-
partial
|
|
23
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type {BooleanCallback, Callbacks, KeyCallback} from '../array/models';
|
|
2
|
-
import type {Key, PlainObject} from '../models';
|
|
3
|
-
|
|
4
|
-
export function getCallbacks<Value>(
|
|
5
|
-
bool: unknown,
|
|
6
|
-
key: unknown,
|
|
7
|
-
): Callbacks<Value> | undefined {
|
|
8
|
-
if (typeof bool === 'function') {
|
|
9
|
-
return {bool: bool as BooleanCallback<Value>};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (typeof key === 'function') {
|
|
13
|
-
return {key: key as KeyCallback<Value>};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const isString = typeof key === 'string';
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
(!isString && typeof key !== 'number') ||
|
|
20
|
-
(isString && key.includes('.'))
|
|
21
|
-
) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
key: (value: Value) => (value as PlainObject)?.[key as string] as Key,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { BooleanCallback, FindType, KeyCallback } from '../array/models';
|
|
2
|
-
import type { Key } from '../models';
|
|
3
|
-
export declare function findValue<Model, Value = Model>(type: FindType, array: Model[], value: Value | BooleanCallback<Model>, key?: Key | KeyCallback<Model>): unknown;
|
|
4
|
-
export declare function findValues<Model, Value = Model>(type: 'all' | 'unique', array: Model[], value: Value | BooleanCallback<Model>, key?: Key | KeyCallback<Model>): Model[];
|