@oscarpalmer/atoms 0.198.0 → 0.199.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.
@@ -1,7 +1,7 @@
1
1
  import { isNonConstructor } from "../is.mjs";
2
2
  //#region src/internal/value/handlers.ts
3
- function getCompareHandlers(owner, options) {
4
- const handlers = getHandlers(owner, options);
3
+ function createCompareHandlers(owner, options) {
4
+ const handlers = createHandlers(owner, options);
5
5
  return {
6
6
  deregister(constructor) {
7
7
  handlers.deregister(constructor);
@@ -16,7 +16,7 @@ function getCompareHandlers(owner, options) {
16
16
  }
17
17
  };
18
18
  }
19
- function getHandlers(owner, options) {
19
+ function createHandlers(owner, options) {
20
20
  const handlers = /* @__PURE__ */ new WeakMap();
21
21
  return {
22
22
  deregister(constructor) {
@@ -34,8 +34,8 @@ function getHandlers(owner, options) {
34
34
  }
35
35
  };
36
36
  }
37
- function getSelfHandlers(owner, options) {
38
- const handlers = getHandlers(owner, options);
37
+ function createSelfHandlers(owner, options) {
38
+ const handlers = createHandlers(owner, options);
39
39
  return {
40
40
  deregister(constructor) {
41
41
  handlers.deregister(constructor);
@@ -54,4 +54,4 @@ function isConstructable(value) {
54
54
  return typeof value === "object" && value !== null;
55
55
  }
56
56
  //#endregion
57
- export { getCompareHandlers, getSelfHandlers };
57
+ export { createCompareHandlers, createSelfHandlers };
@@ -1,10 +1,10 @@
1
1
  import { createAborter } from "../internal/abort.mjs";
2
2
  import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
3
- import { getPromiseOptions } from "./helpers.mjs";
3
+ import { createPromiseOptions } from "./helpers.mjs";
4
4
  import { settlePromise } from "./misc.mjs";
5
5
  //#region src/promise/delay.ts
6
6
  function delay(options) {
7
- const { signal, time } = getPromiseOptions(options);
7
+ const { signal, time } = createPromiseOptions(options);
8
8
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
9
9
  const aborter = createAborter(signal, () => {
10
10
  timer.cancel();
@@ -2,8 +2,8 @@ import { RequiredKeys } from "../models.mjs";
2
2
  import { Result } from "../internal/result/models.mjs";
3
3
  import { FulfilledPromise, PromiseOptions, PromiseStrategy, PromisesOptions, PromisesValue, RejectedPromise } from "./models.mjs";
4
4
  //#region src/promise/helpers.d.ts
5
- declare function getPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, 'time'>;
6
- declare function getPromisesOptions(input: unknown): RequiredKeys<PromisesOptions, 'strategy'>;
5
+ declare function createPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, 'time'>;
6
+ declare function createPromisesOptions(input: unknown): RequiredKeys<PromisesOptions, 'strategy'>;
7
7
  declare function getResultsFromPromises<Value>(promised: PromisesValue<Value>[]): Result<Value>[];
8
8
  declare function getStrategyOrDefault(value: unknown): PromiseStrategy;
9
9
  /**
@@ -21,4 +21,4 @@ declare function isFulfilled<Value>(value: unknown): value is FulfilledPromise<V
21
21
  */
22
22
  declare function isRejected(value: unknown): value is RejectedPromise;
23
23
  //#endregion
24
- export { getPromiseOptions, getPromisesOptions, getResultsFromPromises, getStrategyOrDefault, isFulfilled, isRejected };
24
+ export { createPromiseOptions, createPromisesOptions, getResultsFromPromises, getStrategyOrDefault, isFulfilled, isRejected };
@@ -1,8 +1,8 @@
1
- import { error, ok } from "../internal/result/misc.mjs";
2
1
  import { getNumberOrDefault } from "../internal/defaults.mjs";
2
+ import { error, ok } from "../internal/result/misc.mjs";
3
3
  import { PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
4
4
  //#region src/promise/helpers.ts
5
- function getPromiseOptions(input) {
5
+ function createPromiseOptions(input) {
6
6
  if (typeof input === "number") return { time: getNumberOrDefault(input, 0) };
7
7
  if (input instanceof AbortSignal) return {
8
8
  signal: input,
@@ -14,7 +14,7 @@ function getPromiseOptions(input) {
14
14
  time: getNumberOrDefault(options.time, 0)
15
15
  };
16
16
  }
17
- function getPromisesOptions(input) {
17
+ function createPromisesOptions(input) {
18
18
  if (typeof input === "string") return { strategy: getStrategyOrDefault(input) };
19
19
  if (input instanceof AbortSignal) return {
20
20
  signal: input,
@@ -54,4 +54,4 @@ function isType(value, type) {
54
54
  return typeof value === "object" && value !== null && value.status === type;
55
55
  }
56
56
  //#endregion
57
- export { getPromiseOptions, getPromisesOptions, getResultsFromPromises, getStrategyOrDefault, isFulfilled, isRejected };
57
+ export { createPromiseOptions, createPromisesOptions, getResultsFromPromises, getStrategyOrDefault, isFulfilled, isRejected };
@@ -1,13 +1,13 @@
1
1
  import { createAborter } from "../internal/abort.mjs";
2
2
  import { PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED } from "./constants.mjs";
3
- import { getPromiseOptions, getPromisesOptions, getResultsFromPromises } from "./helpers.mjs";
3
+ import { createPromiseOptions, createPromisesOptions, getResultsFromPromises } from "./helpers.mjs";
4
4
  import { handleResult, settlePromise } from "./misc.mjs";
5
5
  import { getTimedPromise } from "./timed.mjs";
6
6
  //#region src/promise/index.ts
7
7
  async function attemptPromise(value, options) {
8
8
  const isFunction = typeof value === "function";
9
9
  if (!isFunction && !(value instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT));
10
- const { signal, time } = getPromiseOptions(options);
10
+ const { signal, time } = createPromiseOptions(options);
11
11
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
12
12
  const aborter = createAborter(signal, () => {
13
13
  rejector(signal?.reason);
@@ -29,7 +29,7 @@ async function attemptPromise(value, options) {
29
29
  return time > 0 ? getTimedPromise(promise, time, signal) : promise;
30
30
  }
31
31
  async function promises(items, options) {
32
- const { signal, strategy } = getPromisesOptions(options);
32
+ const { signal, strategy } = createPromisesOptions(options);
33
33
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
34
34
  if (!Array.isArray(items)) return Promise.resolve([]);
35
35
  const actual = items.map((item) => typeof item === "function" ? item() : item).filter((item) => item instanceof Promise);
@@ -2,7 +2,7 @@ import { createAborter } from "../internal/abort.mjs";
2
2
  import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
3
3
  import { PROMISE_MESSAGE_EXPECTATION_TIMED } from "./constants.mjs";
4
4
  import { PromiseTimeoutError } from "./models.mjs";
5
- import { getPromiseOptions } from "./helpers.mjs";
5
+ import { createPromiseOptions } from "./helpers.mjs";
6
6
  import { settlePromise } from "./misc.mjs";
7
7
  //#region src/promise/timed.ts
8
8
  async function getTimedPromise(promise, time, signal) {
@@ -24,7 +24,7 @@ async function getTimedPromise(promise, time, signal) {
24
24
  }
25
25
  async function timed(promise, options) {
26
26
  if (!(promise instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED));
27
- const { signal, time } = getPromiseOptions(options);
27
+ const { signal, time } = createPromiseOptions(options);
28
28
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
29
29
  return time > 0 ? getTimedPromise(promise, time, signal) : promise;
30
30
  }
package/dist/queue.mjs CHANGED
@@ -54,7 +54,7 @@ function createQueue(callback, options, key) {
54
54
  handled: [],
55
55
  id: 0,
56
56
  items: [],
57
- options: getOptions(options),
57
+ options: createQueueOptions(options),
58
58
  paused: !getBooleanOrDefault(options?.autostart, true),
59
59
  runners: 0
60
60
  };
@@ -104,7 +104,7 @@ function createQueue(callback, options, key) {
104
104
  });
105
105
  return Object.freeze(instance);
106
106
  }
107
- function getOptions(input) {
107
+ function createQueueOptions(input) {
108
108
  const options = typeof input === "object" && input != null ? input : {};
109
109
  return {
110
110
  autostart: getBooleanOrDefault(options.autostart, true),
@@ -182,7 +182,7 @@ function keyedQueue(callback, options) {
182
182
  if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
183
183
  const state = {
184
184
  callback,
185
- options: getOptions(options),
185
+ options: createQueueOptions(options),
186
186
  queues: /* @__PURE__ */ new Map()
187
187
  };
188
188
  const instance = {
@@ -3,20 +3,7 @@ import { getString } from "../internal/string/misc.mjs";
3
3
  import { lowerCase } from "../internal/string/case.mjs";
4
4
  import { includes } from "./match.mjs";
5
5
  //#region src/string/fuzzy.ts
6
- function getHandler(input) {
7
- if (input == null || input === getString) return getString;
8
- switch (typeof input) {
9
- case "function": return input;
10
- case "string": return (item) => item[input];
11
- default:
12
- if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
13
- throw new TypeError(FUZZY_MESSAGE_HANDLER);
14
- }
15
- }
16
- function getFuzzyItems(items) {
17
- return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
18
- }
19
- function getFuzzyOptions(input, state) {
6
+ function createFuzzyOptions(input, state) {
20
7
  const options = isPlainObject(input) ? input : {};
21
8
  const limit = typeof input === "number" ? input : options.limit;
22
9
  if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = Math.floor(limit);
@@ -24,9 +11,9 @@ function getFuzzyOptions(input, state) {
24
11
  options.tolerance = getTolerance(options.tolerance, state);
25
12
  return options;
26
13
  }
27
- function getFuzzyState(items, input) {
14
+ function createFuzzyState(items, input) {
28
15
  const handler = getHandler(input);
29
- const options = getFuzzyOptions(input);
16
+ const options = createFuzzyOptions(input);
30
17
  return {
31
18
  handler,
32
19
  items: items.slice(),
@@ -35,14 +22,27 @@ function getFuzzyState(items, input) {
35
22
  tolerance: options.tolerance
36
23
  };
37
24
  }
25
+ function getHandler(input) {
26
+ if (input == null || input === getString) return getString;
27
+ switch (typeof input) {
28
+ case "function": return input;
29
+ case "string": return (item) => item[input];
30
+ default:
31
+ if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
32
+ throw new TypeError(FUZZY_MESSAGE_HANDLER);
33
+ }
34
+ }
35
+ function getFuzzyItems(items) {
36
+ return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
37
+ }
38
38
  function getTolerance(input, state) {
39
39
  if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
40
40
  return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
41
41
  }
42
42
  function fuzzy(items, configuration) {
43
43
  if (!Array.isArray(items)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
44
- const state = getFuzzyState(items, configuration);
45
- const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : getFuzzyOptions(options, state)) };
44
+ const state = createFuzzyState(items, configuration);
45
+ const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : createFuzzyOptions(options, state)) };
46
46
  Object.defineProperties(instance, {
47
47
  items: {
48
48
  enumerable: true,
@@ -2,6 +2,16 @@ import { isPlainObject } from "../internal/is.mjs";
2
2
  import { memoize } from "../internal/function/memoize.mjs";
3
3
  import { lowerCase } from "../internal/string/case.mjs";
4
4
  //#region src/string/normalize.ts
5
+ function createNormalizeOptions(input) {
6
+ const options = isPlainObject(input) ? input : {};
7
+ return {
8
+ deburr: options.deburr !== false,
9
+ lowerCase: options.lowerCase !== false,
10
+ special: options.special === true,
11
+ trim: options.trim !== false,
12
+ whitespace: options.whitespace !== false
13
+ };
14
+ }
5
15
  /**
6
16
  * Deburr a string, removing diacritical marks
7
17
  *
@@ -17,16 +27,6 @@ function deburr(value) {
17
27
  });
18
28
  return deburrMemoizer.run(value);
19
29
  }
20
- function getNormalizeOptions(input) {
21
- const options = isPlainObject(input) ? input : {};
22
- return {
23
- deburr: options.deburr !== false,
24
- lowerCase: options.lowerCase !== false,
25
- special: options.special === true,
26
- trim: options.trim !== false,
27
- whitespace: options.whitespace !== false
28
- };
29
- }
30
30
  /**
31
31
  * Initialize a string normalizer
32
32
  *
@@ -36,7 +36,7 @@ function getNormalizeOptions(input) {
36
36
  * @returns Normalizer function
37
37
  */
38
38
  function initializeNormalizer(options) {
39
- const normalization = getNormalizeOptions(options);
39
+ const normalization = createNormalizeOptions(options);
40
40
  return (value) => normalizeString(value, normalization);
41
41
  }
42
42
  /**
@@ -49,7 +49,7 @@ function initializeNormalizer(options) {
49
49
  * @returns Normalized string
50
50
  */
51
51
  function normalize(value, options) {
52
- return normalizeString(value, getNormalizeOptions(options));
52
+ return normalizeString(value, createNormalizeOptions(options));
53
53
  }
54
54
  function normalizeString(value, options) {
55
55
  if (typeof value !== "string") return "";
@@ -2,18 +2,18 @@ import { isPlainObject, isTemplateStringsArray } from "../internal/is.mjs";
2
2
  import { getString, interpolate } from "../internal/string/misc.mjs";
3
3
  import { getValue } from "../internal/value/get.mjs";
4
4
  //#region src/string/template.ts
5
- function getRenderer(strings, values) {
6
- return (variables, options) => {
7
- return template(interpolate(strings, values), variables, options);
8
- };
9
- }
10
- function getTemplateOptions(input) {
5
+ function createTemplateOptions(input) {
11
6
  const options = isPlainObject(input) ? input : {};
12
7
  return {
13
8
  ignoreCase: options.ignoreCase === true,
14
9
  pattern: options.pattern instanceof RegExp ? options.pattern : TEMPLATE_EXPRESSION_VARIABLE
15
10
  };
16
11
  }
12
+ function getRenderer(strings, values) {
13
+ return (variables, options) => {
14
+ return template(interpolate(strings, values), variables, options);
15
+ };
16
+ }
17
17
  function handleTemplate(value, pattern, ignoreCase, variables) {
18
18
  if (typeof value !== "string") return "";
19
19
  if (typeof variables !== "object" || variables === null || Object.keys(variables).length === 0) return value;
@@ -35,14 +35,14 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
35
35
  * @returns _Templater_ function
36
36
  */
37
37
  function initializeTemplater(options) {
38
- const { ignoreCase, pattern } = getTemplateOptions(options);
38
+ const { ignoreCase, pattern } = createTemplateOptions(options);
39
39
  return ((value, ...parameters) => {
40
40
  return isTemplateStringsArray(value) ? (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables) : handleTemplate(value, pattern, ignoreCase, parameters[0]);
41
41
  });
42
42
  }
43
43
  function template(value, ...parameters) {
44
44
  if (isTemplateStringsArray(value)) return getRenderer(value, parameters);
45
- const { ignoreCase, pattern } = getTemplateOptions(parameters[1]);
45
+ const { ignoreCase, pattern } = createTemplateOptions(parameters[1]);
46
46
  return handleTemplate(value, pattern, ignoreCase, parameters[0]);
47
47
  }
48
48
  const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
@@ -1,2 +1,2 @@
1
- import { Subscription, isSubscription } from "./internal/subscription.mjs";
2
- export { type Subscription, isSubscription };
1
+ import { Subscription, SubscriptionParameters, SubscriptionProperty, Subscriptions, SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
2
+ export { type Subscription, type SubscriptionParameters, type SubscriptionProperty, type Subscriptions, type SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions };
@@ -1,2 +1,2 @@
1
- import { isSubscription } from "./internal/subscription.mjs";
2
- export { isSubscription };
1
+ import { isSubscription, isSubscriptions, subscriptions } from "./internal/subscription.mjs";
2
+ export { isSubscription, isSubscriptions, subscriptions };
@@ -1,5 +1,5 @@
1
1
  import { isArrayOrPlainObject, isTypedArray } from "../internal/is.mjs";
2
- import { getSelfHandlers } from "../internal/value/handlers.mjs";
2
+ import { createSelfHandlers } from "../internal/value/handlers.mjs";
3
3
  //#region src/value/clone.ts
4
4
  const CLONE_NAME = "clone";
5
5
  function clone(value, options) {
@@ -10,13 +10,13 @@ function cloneAny(value, parameters, depth, options) {
10
10
  case value === null || CLONE_PRIMITIVES[typeof value]: return value;
11
11
  case value instanceof Date: return new Date(value.getTime());
12
12
  case typeof value === "function":
13
- parameters.options ??= getCloneOptions(options);
13
+ parameters.options ??= createCloneOptions(options);
14
14
  return parameters.options.copyFunctions ? value : void 0;
15
15
  case typeof value === "symbol":
16
- parameters.options ??= getCloneOptions(options);
16
+ parameters.options ??= createCloneOptions(options);
17
17
  return parameters.options.copySymbols ? value : Symbol(value.description);
18
18
  }
19
- parameters.options ??= getCloneOptions(options);
19
+ parameters.options ??= createCloneOptions(options);
20
20
  parameters.references ??= /* @__PURE__ */ new WeakMap();
21
21
  switch (true) {
22
22
  case parameters.references.has(value): return parameters.references.get(value);
@@ -101,6 +101,13 @@ function copy(value) {
101
101
  references: void 0
102
102
  }, 0);
103
103
  }
104
+ function createCloneOptions(input) {
105
+ if (typeof input !== "object" || input === null) return CLONE_DEFAULT_OPTIONS;
106
+ return {
107
+ copyFunctions: input.copyFunctions === true,
108
+ copySymbols: input.copySymbols === true
109
+ };
110
+ }
104
111
  /**
105
112
  * Deregister a clone handler for a specific class
106
113
  *
@@ -111,13 +118,6 @@ function copy(value) {
111
118
  function deregisterCloner(constructor) {
112
119
  clone.handlers.deregister(constructor);
113
120
  }
114
- function getCloneOptions(input) {
115
- if (typeof input !== "object" || input === null) return CLONE_DEFAULT_OPTIONS;
116
- return {
117
- copyFunctions: input.copyFunctions === true,
118
- copySymbols: input.copySymbols === true
119
- };
120
- }
121
121
  /**
122
122
  * Create a cloner with predefined options
123
123
  *
@@ -127,7 +127,7 @@ function getCloneOptions(input) {
127
127
  * @returns Cloner function
128
128
  */
129
129
  function initializeCloner(options) {
130
- const opts = getCloneOptions(options);
130
+ const opts = createCloneOptions(options);
131
131
  function cloner(value) {
132
132
  return cloneAny(value, {
133
133
  copy: false,
@@ -173,7 +173,7 @@ const CLONE_DEFAULT_OPTIONS = {
173
173
  copySymbols: false
174
174
  };
175
175
  const CLONE_MAX_DEPTH = 100;
176
- const cloneHandlers = getSelfHandlers(clone, {
176
+ const cloneHandlers = createSelfHandlers(clone, {
177
177
  callback: tryStructuredClone,
178
178
  method: CLONE_NAME
179
179
  });
@@ -9,11 +9,11 @@ import { isArrayOrPlainObject } from "../internal/is.mjs";
9
9
  * @returns Assigned value
10
10
  */
11
11
  function assign(to, from, options) {
12
- const actual = getMergeOptions(options);
12
+ const actual = createMergeOptions(options);
13
13
  actual.assignValues = true;
14
14
  return mergeValues([to, ...from], actual);
15
15
  }
16
- function getMergeOptions(options) {
16
+ function createMergeOptions(options) {
17
17
  const actual = {
18
18
  assignValues: false,
19
19
  replaceableObjects: void 0,
@@ -40,7 +40,7 @@ function getReplaceableObjects(value) {
40
40
  * @returns Assigner function
41
41
  */
42
42
  function initializeAssigner(options) {
43
- const actual = getMergeOptions(options);
43
+ const actual = createMergeOptions(options);
44
44
  actual.assignValues = true;
45
45
  return ((to, from) => mergeValues([to, ...from], actual));
46
46
  }
@@ -53,7 +53,7 @@ function initializeAssigner(options) {
53
53
  * @returns Merger function
54
54
  */
55
55
  function initializeMerger(options) {
56
- const actual = getMergeOptions(options);
56
+ const actual = createMergeOptions(options);
57
57
  return ((values) => mergeValues(values, actual));
58
58
  }
59
59
  /**
@@ -64,7 +64,7 @@ function initializeMerger(options) {
64
64
  * @returns Merged value
65
65
  */
66
66
  function merge(values, options) {
67
- return mergeValues(values, getMergeOptions(options));
67
+ return mergeValues(values, createMergeOptions(options));
68
68
  }
69
69
  function mergeObjects(values, options, destination, prefix) {
70
70
  const { length } = values;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.198.0",
3
+ "version": "0.199.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "array",