@oscarpalmer/atoms 0.194.0 → 0.195.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 (81) hide show
  1. package/dist/array/index.d.mts +2 -2
  2. package/dist/array/index.mjs +2 -2
  3. package/dist/array/move.mjs +1 -1
  4. package/dist/array/swap.mjs +1 -1
  5. package/dist/color/instance.mjs +1 -1
  6. package/dist/color/misc/state.d.mts +1 -1
  7. package/dist/color/models.d.mts +1 -1
  8. package/dist/color/space/hex.mjs +1 -1
  9. package/dist/color/space/rgb.mjs +1 -1
  10. package/dist/function/index.d.mts +1 -2
  11. package/dist/function/index.mjs +1 -2
  12. package/dist/function/once.mjs +1 -1
  13. package/dist/herald.d.mts +2 -71
  14. package/dist/herald.mjs +1 -109
  15. package/dist/index.d.mts +3270 -3271
  16. package/dist/index.mjs +1500 -1498
  17. package/dist/{array → internal/array}/get.d.mts +2 -2
  18. package/dist/{array → internal/array}/get.mjs +2 -2
  19. package/dist/{array → internal/array}/match.d.mts +2 -2
  20. package/dist/{array → internal/array}/match.mjs +2 -2
  21. package/dist/internal/defaults.d.mts +5 -0
  22. package/dist/internal/defaults.mjs +9 -0
  23. package/dist/{function → internal/function}/assert.d.mts +2 -2
  24. package/dist/{function → internal/function}/assert.mjs +2 -2
  25. package/dist/{function → internal/function}/memoize.d.mts +2 -2
  26. package/dist/{function → internal/function}/memoize.mjs +3 -3
  27. package/dist/{function → internal/function}/work.d.mts +2 -2
  28. package/dist/{function → internal/function}/work.mjs +2 -2
  29. package/dist/internal/herald.d.mts +71 -0
  30. package/dist/internal/herald.mjs +110 -0
  31. package/dist/internal/number.d.mts +1 -2
  32. package/dist/internal/number.mjs +1 -4
  33. package/dist/internal/{result.d.mts → result/misc.d.mts} +42 -3
  34. package/dist/internal/{result.mjs → result/misc.mjs} +29 -3
  35. package/dist/{result → internal/result}/models.d.mts +2 -2
  36. package/dist/{sized → internal/sized}/map.d.mts +1 -1
  37. package/dist/{sized → internal/sized}/map.mjs +2 -2
  38. package/dist/internal/{sized.d.mts → sized/misc.d.mts} +1 -1
  39. package/dist/internal/{sized.mjs → sized/misc.mjs} +2 -2
  40. package/dist/{string → internal/string}/case.d.mts +1 -1
  41. package/dist/{string → internal/string}/case.mjs +2 -2
  42. package/dist/internal/{string.d.mts → string/misc.d.mts} +1 -1
  43. package/dist/internal/{string.mjs → string/misc.mjs} +1 -1
  44. package/dist/internal/value/compare.mjs +1 -1
  45. package/dist/internal/value/has.d.mts +1 -1
  46. package/dist/internal/value/misc.d.mts +1 -1
  47. package/dist/internal/value/misc.mjs +2 -2
  48. package/dist/is.mjs +2 -2
  49. package/dist/logger.mjs +1 -1
  50. package/dist/promise/helpers.d.mts +1 -1
  51. package/dist/promise/helpers.mjs +2 -2
  52. package/dist/promise/index.d.mts +1 -1
  53. package/dist/promise/misc.d.mts +1 -1
  54. package/dist/promise/misc.mjs +2 -1
  55. package/dist/promise/models.d.mts +1 -1
  56. package/dist/query.mjs +1 -1
  57. package/dist/queue.mjs +1 -4
  58. package/dist/random.mjs +1 -1
  59. package/dist/result/index.d.mts +1 -1
  60. package/dist/result/index.mjs +1 -1
  61. package/dist/result/match.d.mts +1 -1
  62. package/dist/result/match.mjs +1 -1
  63. package/dist/result/misc.d.mts +3 -42
  64. package/dist/result/misc.mjs +2 -28
  65. package/dist/result/work/flow.d.mts +1 -1
  66. package/dist/result/work/flow.mjs +2 -2
  67. package/dist/result/work/pipe.d.mts +1 -1
  68. package/dist/result/work/pipe.mjs +2 -2
  69. package/dist/sized/set.mjs +1 -1
  70. package/dist/string/fuzzy.mjs +2 -2
  71. package/dist/string/index.d.mts +1 -1
  72. package/dist/string/index.mjs +1 -1
  73. package/dist/string/match.mjs +1 -1
  74. package/dist/string/normalize.mjs +2 -2
  75. package/dist/string/template.mjs +1 -1
  76. package/dist/subscription.d.mts +2 -0
  77. package/dist/subscription.mjs +2 -0
  78. package/dist/value/diff.mjs +1 -1
  79. package/dist/value/smush.mjs +1 -1
  80. package/package.json +23 -11
  81. /package/dist/{result → internal/result}/models.mjs +0 -0
@@ -3,15 +3,15 @@ import { exists } from "./exists.mjs";
3
3
  import { find, findLast } from "./find.mjs";
4
4
  import { flatten } from "./flatten.mjs";
5
5
  import { range, times } from "./from.mjs";
6
- import { getArray } from "./get.mjs";
7
6
  import { chunk } from "../internal/array/chunk.mjs";
8
7
  import { compact } from "../internal/array/compact.mjs";
8
+ import { getArray } from "../internal/array/get.mjs";
9
9
  import { indexOf, lastIndexOf } from "../internal/array/index-of.mjs";
10
+ import { ArrayComparison, endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray } from "../internal/array/match.mjs";
10
11
  import { shuffle } from "../internal/array/shuffle.mjs";
11
12
  import { insert } from "./insert.mjs";
12
13
  import { intersection } from "./intersection.mjs";
13
14
  import { partition } from "./partition.mjs";
14
- import { ArrayComparison, endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray } from "./match.mjs";
15
15
  import { push } from "./push.mjs";
16
16
  import { reverse } from "./reverse.mjs";
17
17
  import { select } from "./select.mjs";
@@ -1,17 +1,17 @@
1
1
  import { chunk } from "../internal/array/chunk.mjs";
2
2
  import { compact } from "../internal/array/compact.mjs";
3
+ import { getArray } from "../internal/array/get.mjs";
3
4
  import { indexOf, lastIndexOf } from "../internal/array/index-of.mjs";
5
+ import { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray } from "../internal/array/match.mjs";
4
6
  import { shuffle } from "../internal/array/shuffle.mjs";
5
7
  import { difference } from "./difference.mjs";
6
8
  import { exists } from "./exists.mjs";
7
9
  import { find, findLast } from "./find.mjs";
8
10
  import { flatten } from "./flatten.mjs";
9
11
  import { range, times } from "./from.mjs";
10
- import { getArray } from "./get.mjs";
11
12
  import { insert } from "./insert.mjs";
12
13
  import { intersection } from "./intersection.mjs";
13
14
  import { partition } from "./partition.mjs";
14
- import { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray } from "./match.mjs";
15
15
  import { push } from "./push.mjs";
16
16
  import { reverse } from "./reverse.mjs";
17
17
  import { select } from "./select.mjs";
@@ -1,4 +1,4 @@
1
- import { indexOfArray } from "./match.mjs";
1
+ import { indexOfArray } from "../internal/array/match.mjs";
2
2
  import { arraysOverlap } from "../internal/array/overlap.mjs";
3
3
  //#region src/array/move.ts
4
4
  function move(array, from, to, key) {
@@ -1,6 +1,6 @@
1
1
  import { getArrayCallback } from "../internal/array/callbacks.mjs";
2
2
  import { indexOf } from "../internal/array/index-of.mjs";
3
- import { indexOfArray } from "./match.mjs";
3
+ import { indexOfArray } from "../internal/array/match.mjs";
4
4
  import { arraysOverlap } from "../internal/array/overlap.mjs";
5
5
  //#region src/array/swap.ts
6
6
  function swap(array, first, second, third) {
@@ -1,4 +1,4 @@
1
- import { herald } from "../herald.mjs";
1
+ import { herald } from "../internal/herald.mjs";
2
2
  import { COLOR_PROPERTY, COLOR_TYPE } from "./constants.mjs";
3
3
  import { getAlpha } from "./misc/alpha.mjs";
4
4
  import { getColorFromState, getColorState, setHSLColor, setHWBColor, setHexColor, setRGBColor } from "./misc/state.mjs";
@@ -1,4 +1,4 @@
1
- import { Herald } from "../../herald.mjs";
1
+ import { Herald } from "../../internal/herald.mjs";
2
2
  import { Color, ColorChanges, ColorState, ColorType } from "../models.mjs";
3
3
  //#region src/color/misc/state.d.ts
4
4
  declare function getColorFromState<Type extends ColorType>(state: ColorState, type: Type): NonNullable<ColorState[Type]>;
@@ -1,5 +1,5 @@
1
1
  import { Subscription } from "../internal/subscription.mjs";
2
- import { HeraldEvents } from "../herald.mjs";
2
+ import { HeraldEvents } from "../internal/herald.mjs";
3
3
  import { COLOR_ALPHA } from "./constants.mjs";
4
4
  //#region src/color/models.d.ts
5
5
  type Alpha = {
@@ -1,4 +1,4 @@
1
- import { join } from "../../internal/string.mjs";
1
+ import { join } from "../../internal/string/misc.mjs";
2
2
  import { COLOR_ALPHA, COLOR_DEFAULTS, COLOR_EXPRESSION, COLOR_LENGTHS, COLOR_MAX, COLOR_TYPE } from "../constants.mjs";
3
3
  import { getHexValue, getPercentage } from "../misc/get.mjs";
4
4
  import { isHexColor } from "../misc/is.mjs";
@@ -1,4 +1,4 @@
1
- import { join } from "../../internal/string.mjs";
1
+ import { join } from "../../internal/string/misc.mjs";
2
2
  import { COLOR_DEFAULTS, COLOR_MAX, COLOR_TYPE } from "../constants.mjs";
3
3
  import { getAlpha, getAlphaValue } from "../misc/alpha.mjs";
4
4
  import { getHexValue } from "../misc/get.mjs";
@@ -1,3 +1,2 @@
1
1
  import { noop } from "../internal/function/misc.mjs";
2
- import { Memoized, MemoizedOptions, memoize } from "./memoize.mjs";
3
- export { type Memoized, type MemoizedOptions, memoize, noop };
2
+ export { noop };
@@ -1,3 +1,2 @@
1
1
  import { noop } from "../internal/function/misc.mjs";
2
- import { memoize } from "./memoize.mjs";
3
- export { memoize, noop };
2
+ export { noop };
@@ -1,4 +1,4 @@
1
- import { assert } from "./assert.mjs";
1
+ import { assert } from "../internal/function/assert.mjs";
2
2
  //#region src/function/once.ts
3
3
  /**
4
4
  * Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
package/dist/herald.d.mts CHANGED
@@ -1,71 +1,2 @@
1
- import { GenericCallback } from "./models.mjs";
2
- import { Subscription, SubscriptionProperty } from "./internal/subscription.mjs";
3
- //#region src/herald.d.ts
4
- type Herald<Events extends Record<string, GenericCallback>> = {
5
- readonly events: HeraldEvents<Events>;
6
- /**
7
- * Remove all event subscribers
8
- */
9
- clear(): void;
10
- /**
11
- * Emit an event with parameters
12
- *
13
- * @param event Event name
14
- * @param parameters Event parameters
15
- */
16
- emit<Event extends keyof Events>(event: Event, ...parameters: Parameters<Events[Event]>): void;
17
- /**
18
- * Is the event observed by any subscribers?
19
- *
20
- * @param event Event name
21
- * @returns `true` if the event is observed, otherwise `false`
22
- */
23
- observed<Event extends keyof Events>(event: Event): boolean;
24
- /**
25
- * Subscribe to an event with a callback
26
- *
27
- * @param event Event name
28
- * @param callback Callback function
29
- * @param signal Optional abort signal to cancel the subscription
30
- * @returns Subscription instance
31
- */
32
- subscribe<Event extends keyof Events>(event: Event, callback: Events[Event], signal?: AbortSignal): Subscription;
33
- };
34
- type HeraldEvents<Events extends Record<string, GenericCallback>> = { [Key in keyof Events]: Key extends '*' ? never : (callback: Events[Key], signal?: AbortSignal) => void; };
35
- type HeraldOnCreate<Events extends Record<string, GenericCallback>> = <Event extends keyof Events>(event: Event, callback: Events[Event], subscription: Subscription) => void;
36
- type HeraldOptions<Events extends Record<string, GenericCallback>> = {
37
- names: Array<keyof Events>;
38
- property?: SubscriptionProperty;
39
- onCreate?: HeraldOnCreate<Events>;
40
- };
41
- /**
42
- * Create a _Herald_ for announcing named events
43
- *
44
- * @param names Event names
45
- * @param property Optional property for subscription identification _(defaults to `$herald`)_
46
- * @returns _Herald_ instance
47
- */
48
- declare function herald<Events extends Record<string, GenericCallback>>(options: HeraldOptions<Events>): Herald<Events>;
49
- /**
50
- * Is the value events for a herald?
51
- *
52
- * @param value Value to check
53
- * @returns `true` if the value is events for a herald, otherwise `false`
54
- */
55
- declare function isHeraldEvents<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is HeraldEvents<Events>;
56
- /**
57
- * Is the value a herald?
58
- *
59
- * @param value Value to check
60
- * @returns `true` if the value is a herald, otherwise `false`
61
- */
62
- declare function isHerald<Events extends Record<string, GenericCallback> = Record<string, GenericCallback>>(value: unknown): value is Herald<Events>;
63
- /**
64
- * Is the value a herald subscription?
65
- *
66
- * @param value Value to check
67
- * @returns `true` if the value is a herald subscription, otherwise `false`
68
- */
69
- declare function isHeraldSubscription(value: unknown): value is Subscription;
70
- //#endregion
71
- export { Herald, HeraldEvents, HeraldOptions, herald, isHerald, isHeraldEvents, isHeraldSubscription };
1
+ import { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
2
+ export { herald, isHerald, isHeraldEvents, isHeraldSubscription };
package/dist/herald.mjs CHANGED
@@ -1,110 +1,2 @@
1
- import { isPlainObject } from "./internal/is.mjs";
2
- import { createSubscriptions, isSubscription } from "./internal/subscription.mjs";
3
- //#region src/herald.ts
4
- function createEvents(herald, state) {
5
- const events = {};
6
- Object.defineProperty(events, HERALD_PROPERTY, { value: HERALD_NAME_EVENTS });
7
- for (const key of state.keys) events[key] = (callback, signal) => herald.subscribe(key, callback, signal);
8
- return Object.freeze(events);
9
- }
10
- function emitForHerald(state, event, ...parameters) {
11
- const items = state.subscriptions.state.values.from.keyed?.get(event);
12
- if (items == null || items.size === 0) return;
13
- for (const [callback] of items) callback(...parameters);
14
- }
15
- function getHeraldSubscriptionProperty(input) {
16
- if (input == null) return heraldSubscription;
17
- const property = isPlainObject(input) ? input : {};
18
- if (typeof property.key !== "string" || property.value != null && typeof property.value !== "string") throw new Error(HERALD_MESSAGE_PROPERTY);
19
- return {
20
- key: property.key,
21
- value: property.value
22
- };
23
- }
24
- function getHeraldState(input) {
25
- const options = isPlainObject(input) ? input : {};
26
- if (!Array.isArray(options.names) || options.names.length === 0 || !options.names.every((name) => typeof name === "string")) throw new Error(HERALD_MESSAGE_ARRAY);
27
- if (options.onCreate != null && typeof options.onCreate !== "function") throw new Error(HERALD_MESSAGE_ONCREATE);
28
- const keys = new Set(options.names);
29
- const property = getHeraldSubscriptionProperty(options.property);
30
- return {
31
- keys,
32
- subscriptions: createSubscriptions({
33
- keys,
34
- property
35
- }),
36
- onCreate: options.onCreate
37
- };
38
- }
39
- /**
40
- * Create a _Herald_ for announcing named events
41
- *
42
- * @param names Event names
43
- * @param property Optional property for subscription identification _(defaults to `$herald`)_
44
- * @returns _Herald_ instance
45
- */
46
- function herald(options) {
47
- const state = getHeraldState(options);
48
- const instance = {
49
- clear: () => state.subscriptions.clear(),
50
- emit: (event, ...parameters) => emitForHerald(state, event, ...parameters),
51
- observed: (event) => (state.subscriptions.state.items.keyed?.get(event)?.size ?? 0) > 0,
52
- subscribe: (key, callback, signal) => subscribeToHerald(state, key, callback, signal)
53
- };
54
- Object.defineProperties(instance, {
55
- [HERALD_PROPERTY]: { value: HERALD_NAME_HERALD },
56
- events: {
57
- enumerable: true,
58
- value: createEvents(instance, state)
59
- }
60
- });
61
- return Object.freeze(instance);
62
- }
63
- /**
64
- * Is the value events for a herald?
65
- *
66
- * @param value Value to check
67
- * @returns `true` if the value is events for a herald, otherwise `false`
68
- */
69
- function isHeraldEvents(value) {
70
- return isHeraldInstance(HERALD_NAME_EVENTS, value);
71
- }
72
- /**
73
- * Is the value a herald?
74
- *
75
- * @param value Value to check
76
- * @returns `true` if the value is a herald, otherwise `false`
77
- */
78
- function isHerald(value) {
79
- return isHeraldInstance(HERALD_NAME_HERALD, value);
80
- }
81
- function isHeraldInstance(name, value) {
82
- return isPlainObject(value) && HERALD_PROPERTY in value && value[HERALD_PROPERTY] === name;
83
- }
84
- /**
85
- * Is the value a herald subscription?
86
- *
87
- * @param value Value to check
88
- * @returns `true` if the value is a herald subscription, otherwise `false`
89
- */
90
- function isHeraldSubscription(value) {
91
- return isSubscription(value) && value[HERALD_PROPERTY] === "subscription";
92
- }
93
- function subscribeToHerald(state, key, callback, signal) {
94
- const [subscription, existing] = state.subscriptions.create({
95
- key,
96
- signal,
97
- value: callback
98
- });
99
- if (!existing) state.onCreate?.(key, callback, subscription);
100
- return subscription;
101
- }
102
- const HERALD_PROPERTY = "$herald";
103
- const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
104
- const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
105
- const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
106
- const HERALD_NAME_EVENTS = "events";
107
- const HERALD_NAME_HERALD = "herald";
108
- const heraldSubscription = { key: HERALD_PROPERTY };
109
- //#endregion
1
+ import { herald, isHerald, isHeraldEvents, isHeraldSubscription } from "./internal/herald.mjs";
110
2
  export { herald, isHerald, isHeraldEvents, isHeraldSubscription };