@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.
Files changed (113) hide show
  1. package/dist/array/sort.cjs +5 -10
  2. package/dist/array/sort.js +5 -10
  3. package/dist/colour/base.cjs +27 -2
  4. package/dist/colour/base.js +27 -2
  5. package/dist/colour/functions.cjs +1 -1
  6. package/dist/colour/functions.js +1 -1
  7. package/dist/colour/hsl.cjs +2 -12
  8. package/dist/colour/hsl.js +2 -12
  9. package/dist/colour/index.cjs +5 -0
  10. package/dist/colour/index.js +6 -1
  11. package/dist/colour/rgb.cjs +2 -8
  12. package/dist/colour/rgb.js +2 -8
  13. package/dist/index.cjs +5 -0
  14. package/dist/index.js +5 -0
  15. package/dist/internal/array/find.cjs +6 -7
  16. package/dist/internal/array/find.js +6 -7
  17. package/dist/value/equal.cjs +4 -1
  18. package/dist/value/equal.js +4 -1
  19. package/package.json +15 -8
  20. package/src/array/chunk.ts +1 -1
  21. package/src/array/count.ts +2 -2
  22. package/src/array/exists.ts +2 -2
  23. package/src/array/filter.ts +2 -2
  24. package/src/array/find.ts +2 -2
  25. package/src/array/group-by.ts +2 -2
  26. package/src/array/index-of.ts +2 -2
  27. package/src/array/index.ts +3 -2
  28. package/src/array/insert.ts +2 -2
  29. package/src/array/models.ts +1 -1
  30. package/src/array/shuffle.ts +1 -1
  31. package/src/array/sort.ts +13 -20
  32. package/src/array/splice.ts +1 -1
  33. package/src/array/to-map.ts +2 -2
  34. package/src/array/to-record.ts +60 -60
  35. package/src/array/unique.ts +5 -5
  36. package/src/colour/base.ts +48 -12
  37. package/src/colour/functions.ts +4 -4
  38. package/src/colour/hex.ts +3 -3
  39. package/src/colour/hsl.ts +6 -18
  40. package/src/colour/index.ts +2 -1
  41. package/src/colour/is.ts +4 -7
  42. package/src/colour/rgb.ts +6 -14
  43. package/src/emitter.ts +1 -1
  44. package/src/function.ts +2 -2
  45. package/src/index.ts +16 -16
  46. package/src/internal/array/callbacks.ts +2 -2
  47. package/src/internal/array/find.ts +10 -11
  48. package/src/internal/value/handle.ts +1 -1
  49. package/src/is.ts +2 -2
  50. package/src/logger.ts +1 -1
  51. package/src/query.ts +4 -4
  52. package/src/random.ts +1 -1
  53. package/src/sized.ts +1 -1
  54. package/src/string/case.ts +1 -1
  55. package/src/string/index.ts +2 -1
  56. package/src/string/template.ts +3 -3
  57. package/src/value/clone.ts +3 -3
  58. package/src/value/compare.ts +3 -3
  59. package/src/value/diff.ts +4 -4
  60. package/src/value/equal.ts +6 -3
  61. package/src/value/get.ts +2 -2
  62. package/src/value/index.ts +2 -1
  63. package/src/value/merge.ts +2 -2
  64. package/src/value/set.ts +2 -2
  65. package/src/value/smush.ts +3 -3
  66. package/src/value/unsmush.ts +3 -3
  67. package/types/array/count.d.ts +1 -1
  68. package/types/array/exists.d.ts +1 -1
  69. package/types/array/filter.d.ts +1 -1
  70. package/types/array/find.d.ts +1 -1
  71. package/types/array/group-by.d.ts +1 -1
  72. package/types/array/index-of.d.ts +1 -1
  73. package/types/array/index.d.ts +1 -1
  74. package/types/array/insert.d.ts +1 -1
  75. package/types/array/models.d.ts +1 -1
  76. package/types/array/sort.d.ts +2 -2
  77. package/types/array/to-map.d.ts +1 -1
  78. package/types/array/to-record.d.ts +1 -1
  79. package/types/array/unique.d.ts +1 -1
  80. package/types/colour/base.d.cts +9 -1
  81. package/types/colour/base.d.ts +12 -2
  82. package/types/colour/functions.d.cts +9 -1
  83. package/types/colour/functions.d.ts +3 -3
  84. package/types/colour/hex.d.cts +9 -1
  85. package/types/colour/hex.d.ts +2 -2
  86. package/types/colour/hsl.d.cts +9 -1
  87. package/types/colour/hsl.d.ts +3 -3
  88. package/types/colour/index.d.cts +27 -1
  89. package/types/colour/index.d.ts +2 -1
  90. package/types/colour/is.d.cts +10 -2
  91. package/types/colour/is.d.ts +4 -4
  92. package/types/colour/rgb.d.cts +9 -1
  93. package/types/colour/rgb.d.ts +3 -3
  94. package/types/function.d.ts +1 -1
  95. package/types/index.d.cts +37 -9
  96. package/types/index.d.ts +16 -16
  97. package/types/internal/array/callbacks.d.ts +1 -1
  98. package/types/internal/array/find.d.ts +1 -1
  99. package/types/internal/value/handle.d.ts +1 -1
  100. package/types/is.d.ts +1 -1
  101. package/types/models.d.cts +10 -3
  102. package/types/query.d.ts +1 -1
  103. package/types/string/template.d.ts +1 -1
  104. package/types/value/get.d.cts +10 -3
  105. package/types/value/get.d.ts +1 -1
  106. package/types/value/index.d.cts +10 -3
  107. package/types/value/index.d.ts +1 -1
  108. package/types/value/merge.d.ts +1 -1
  109. package/types/value/set.d.cts +2 -1
  110. package/types/value/set.d.ts +1 -1
  111. package/types/value/smush.d.cts +10 -3
  112. package/types/value/smush.d.ts +1 -1
  113. package/types/value/unsmush.d.ts +1 -1
package/src/array/sort.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type {SortKey, SortKeyWithCallback} from '~/array/models';
2
- import {isKey} from '~/is';
3
- import type {Key, PlainObject} from '~/models';
4
- import {compare} from '~/value/compare';
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
- if (first == null || typeof first === 'boolean') {
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 direction === 'asc'
96
- ? array.sort()
97
- : (array as never[]).sort((first, second) => second - first);
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 descending = direction === 'desc';
113
-
114
- const compared = compare(
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;
@@ -1,4 +1,4 @@
1
- import {insertValues} from '~/array/insert';
1
+ import {insertValues} from './insert';
2
2
 
3
3
  /**
4
4
  * Removes and returns all items from an array starting from a specific index
@@ -1,5 +1,5 @@
1
- import {getCallbacks} from '~/internal/array/callbacks';
2
- import type {Key, PlainObject} from '~/models';
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)_
@@ -1,6 +1,6 @@
1
1
  import type {Simplify} from 'type-fest';
2
- import {groupValues} from '~/array/group-by';
3
- import type {Key, KeyedValue, PlainObject} from '~/models';
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
- array: Item[],
15
- key: ItemKey,
16
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item>>;
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
- array: Item[],
23
- key: ItemKey,
24
- arrays: true,
25
- ): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
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
- 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]>>;
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
- 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]>>>;
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
- 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>>>;
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
- 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>>>>;
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
- 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]>;
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
- 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]>>;
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
@@ -1,5 +1,5 @@
1
- import {findValues} from '~/internal/array/find';
2
- import type {Key, PlainObject} from '~/models';
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
- Item,
24
- ItemKey extends (item: Item, index: number, array: Item[]) => Key,
25
- >(array: Item[], key: ItemKey): Item[];
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]);
@@ -1,8 +1,44 @@
1
- import type {HexColour} from '~/colour/hex';
2
- import {isColourValue} from '~/colour/is';
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: string;
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
- constructor(
16
- type: string,
17
- value: Model,
18
- defaults: Model,
19
- properties: Array<keyof Model>,
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: isColourValue<Model>(value, properties)
25
- ? {...value}
26
- : {...defaults},
62
+ value: getValue(value, type),
27
63
  };
28
64
  }
29
65
 
@@ -1,7 +1,7 @@
1
- import {HexColour} from '~/colour/hex';
2
- import {HSLColour, type HSLColourValue} from '~/colour/hsl';
3
- import {RGBColour, type RGBColourValue} from '~/colour/rgb';
4
- import {clamp} from '~/number';
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 '~/colour/functions';
2
- import type {HSLColour} from '~/colour/hsl';
3
- import type {RGBColour} from '~/colour/rgb';
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 {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';
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, defaults, properties);
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
  */
@@ -1,4 +1,4 @@
1
- import type {RGBColourValue} from '~/colour/rgb';
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 '~/colour/hex';
2
- import type {HSLColour} from '~/colour/hsl';
3
- import type {RGBColour} from '~/colour/rgb';
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<Expected>(
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 {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';
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, defaults, properties);
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
@@ -1,4 +1,4 @@
1
- import {noop} from '~/function';
1
+ import {noop} from './function';
2
2
 
3
3
  class Emitter<Value> {
4
4
  private declare readonly state: EmitterState<Value>;
package/src/function.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type {GenericCallback} from '~/models';
2
- import {clamp} from '~/number';
1
+ import type {GenericCallback} from './models';
2
+ import {clamp} from './number';
3
3
 
4
4
  type Debounced<Callback extends GenericCallback> = Callback & {
5
5
  /**
package/src/index.ts CHANGED
@@ -1,16 +1,16 @@
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
+ 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 '~/array/models';
2
- import type {GenericCallback, PlainObject} from '~/models';
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 '~/array/models';
2
- import {getCallbacks} from '~/internal/array/callbacks';
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.findIndex(item => item === value)
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 keyed = callbacks?.key?.(item, index, array) ?? item;
72
+ const key = callbacks?.key?.(item, index, array) ?? item;
73
73
 
74
74
  if (
75
- (type === 'all' && keyed === value) ||
76
- (type === 'unique' && values.indexOf(keyed) === -1)
75
+ (type === 'all' && key === value) ||
76
+ (type === 'unique' && !keys.has(key))
77
77
  ) {
78
- if (values !== result) {
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
 
@@ -1,4 +1,4 @@
1
- import type {ArrayOrPlainObject, PlainObject} from '~/models';
1
+ import type {ArrayOrPlainObject, PlainObject} from '../../models';
2
2
 
3
3
  function findKey(
4
4
  needle: string,
package/src/is.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type {ArrayOrPlainObject, Key, PlainObject, Primitive} from '~/models';
2
- import {getString} from '~/string';
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
@@ -1,4 +1,4 @@
1
- import {noop} from '~/function';
1
+ import {noop} from './function';
2
2
 
3
3
  declare global {
4
4
  var _atomic_logging: boolean;
package/src/query.ts CHANGED
@@ -1,7 +1,7 @@
1
- import {isPlainObject} from '~/is';
2
- import type {ArrayOrPlainObject, PlainObject} from '~/models';
3
- import {join} from '~/string';
4
- import {setValue} from '~/value';
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
@@ -1,4 +1,4 @@
1
- import {shuffle} from '~/array/shuffle';
1
+ import {shuffle} from './array/shuffle';
2
2
 
3
3
  /**
4
4
  * Get a random boolean
package/src/sized.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {clamp} from '~/number';
1
+ import {clamp} from './number';
2
2
 
3
3
  /**
4
4
  * A Map with a maximum size
@@ -1,4 +1,4 @@
1
- import {words} from '~/string/index';
1
+ import {words} from './index';
2
2
 
3
3
  /**
4
4
  * Convert a string to camel case _(thisIsCamelCase)_
@@ -1,4 +1,4 @@
1
- import {compact} from '~/array';
1
+ import {compact} from '../array/compact';
2
2
 
3
3
  /**
4
4
  * Create a new UUID
@@ -91,3 +91,4 @@ export function words(value: string): string[] {
91
91
 
92
92
  export * from './case';
93
93
  export * from './template';
94
+