@oscarpalmer/atoms 0.187.1 → 0.188.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.
@@ -5,6 +5,7 @@ import { TIMER_WAIT, getTimer } from "../internal/function/timer.mjs";
5
5
  * An error thrown when a retry fails
6
6
  */
7
7
  var RetryError = class extends Error {
8
+ original;
8
9
  constructor(message, original) {
9
10
  super(message);
10
11
  this.original = original;
package/dist/index.d.mts CHANGED
@@ -5137,6 +5137,13 @@ declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): st
5137
5137
  * @returns Dedented string
5138
5138
  */
5139
5139
  declare function dedent(value: string): string;
5140
+ /**
5141
+ * Get a new UUID string _(version 4)_ for use in _HTML_
5142
+ *
5143
+ * @param html Use _HTML_-friendly format
5144
+ * @returns UUID string
5145
+ */
5146
+ declare function getUuid(html: true): string;
5140
5147
  /**
5141
5148
  * Get a new UUID string _(version 4)_
5142
5149
  *
@@ -6589,12 +6596,7 @@ declare function isNumerical(value: unknown): value is number | `${number}`;
6589
6596
  declare function isObject(value: unknown): value is object;
6590
6597
  //#endregion
6591
6598
  //#region src/logger.d.ts
6592
- /**
6593
- * A logger that can be used to log messages to the console
6594
- *
6595
- * _(Logging can be enabled or disabled by setting the `enabled` property)_
6596
- */
6597
- declare class Logger {
6599
+ type LoggerInstance = {
6598
6600
  /**
6599
6601
  * Log any number of values at the "debug" log level
6600
6602
  */
@@ -6639,14 +6641,14 @@ declare class Logger {
6639
6641
  * Start a timed logger with a label
6640
6642
  *
6641
6643
  * @param label Label for the logger
6642
- * @returns _Timed_ instance
6644
+ * @returns _TimedLogger_ instance
6643
6645
  */
6644
- time(label: string): Timed;
6645
- }
6646
+ time(label: string): TimedLogger;
6647
+ };
6646
6648
  /**
6647
6649
  * A named timer that can be used to log durations to the console
6648
6650
  */
6649
- declare class Timed {
6651
+ declare class TimedLogger {
6650
6652
  #private;
6651
6653
  /**
6652
6654
  * Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
@@ -6664,7 +6666,12 @@ declare class Timed {
6664
6666
  get stop(): () => void;
6665
6667
  constructor(label: string);
6666
6668
  }
6667
- declare const logger: Logger;
6669
+ /**
6670
+ * A logger that can be used to log messages to the console
6671
+ *
6672
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
6673
+ */
6674
+ declare const Logger: LoggerInstance;
6668
6675
  //#endregion
6669
6676
  //#region src/internal/math/aggregate.d.ts
6670
6677
  /**
@@ -8179,4 +8186,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
8179
8186
  get(value: Value, update?: boolean): Value | undefined;
8180
8187
  }
8181
8188
  //#endregion
8182
- export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayValueSorter, AssertProperty, Asserter, AssignOptions, Assigner, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, type Events, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type Herald, Key$1 as Key, type KeyedQueue, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, type QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, type Shaken, Simplify, SizedMap, SizedSet, type Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Timed, ToString, Transformer, TypedArray, UnionToIntersection, type Unsmushed, Unsubscriber, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
8189
+ export { AnyResult, ArrayComparison, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayValueSorter, AssertProperty, Asserter, AssignOptions, Assigner, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, type Events, ExtendedErr, ExtendedResult, Flow, FlowPromise, Frozen, FulfilledPromise, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, type Herald, Key$1 as Key, type KeyedQueue, KeyedValue, Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, NormalizeOptions, Normalizer, NumericalKeys, NumericalValues, type Observable, type Observer, Ok, OnceAsyncCallback, OnceCallback, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PlainObject, Primitive, PromiseData, PromiseHandlers, PromiseOptions, PromiseParameters, PromiseStrategy, PromiseTimeoutError, PromisesItems, PromisesOptions, PromisesResult, PromisesUnwrapped, PromisesValue, PromisesValues, type Queue, type QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, type Shaken, Simplify, SizedMap, SizedSet, type Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type TimedLogger, ToString, Transformer, TypedArray, UnionToIntersection, type Unsmushed, Unsubscriber, UnwrapValue, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
package/dist/index.mjs CHANGED
@@ -982,7 +982,7 @@ function join(array, delimiter) {
982
982
  const values = [];
983
983
  for (let index = 0; index < length; index += 1) {
984
984
  const item = getString(array[index]);
985
- if (item.trim().length > 0) values.push(item);
985
+ if (item.length > 0) values.push(item);
986
986
  }
987
987
  return values.join(typeof delimiter === "string" ? delimiter : "");
988
988
  }
@@ -3059,19 +3059,25 @@ function dedent(value, ...values) {
3059
3059
  *
3060
3060
  * @returns UUID string
3061
3061
  */
3062
- function getUuid() {
3063
- const bytes = new Uint8Array(16);
3064
- crypto.getRandomValues(bytes);
3065
- bytes[6] = bytes[6] & 15 | 64;
3066
- bytes[8] = bytes[8] & 63 | 128;
3067
- const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, ZERO)).join("");
3068
- return [
3069
- hex.substring(0, 8),
3070
- hex.substring(8, 12),
3071
- hex.substring(12, 16),
3072
- hex.substring(16, 20),
3073
- hex.substring(20, 32)
3074
- ].join("-");
3062
+ function getUuid(html) {
3063
+ const forHTML = html === true;
3064
+ let uuid;
3065
+ while (true) {
3066
+ const bytes = new Uint8Array(16);
3067
+ crypto.getRandomValues(bytes);
3068
+ bytes[6] = bytes[6] & 15 | 64;
3069
+ bytes[8] = bytes[8] & 63 | 128;
3070
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, ZERO)).join("");
3071
+ uuid = [
3072
+ hex.substring(0, 8),
3073
+ hex.substring(8, 12),
3074
+ hex.substring(12, 16),
3075
+ hex.substring(16, 20),
3076
+ hex.substring(20, 32)
3077
+ ].join("-");
3078
+ if (!forHTML || !NUMERICAL_PREFIX_PATTERN.test(uuid)) break;
3079
+ }
3080
+ return uuid;
3075
3081
  }
3076
3082
  /**
3077
3083
  * Parse a JSON string into its proper value _(or `undefined` if it fails)_
@@ -3113,6 +3119,7 @@ function truncate(value, length, suffix) {
3113
3119
  const truncatedLength = length - actualSuffixLength;
3114
3120
  return `${value.slice(0, truncatedLength)}${actualSuffix}`;
3115
3121
  }
3122
+ const NUMERICAL_PREFIX_PATTERN = /^\d/;
3116
3123
  const ZERO = "0";
3117
3124
  //#endregion
3118
3125
  //#region src/string/normalize.ts
@@ -4859,85 +4866,9 @@ function getColor(value) {
4859
4866
  //#endregion
4860
4867
  //#region src/logger.ts
4861
4868
  /**
4862
- * A logger that can be used to log messages to the console
4863
- *
4864
- * _(Logging can be enabled or disabled by setting the `enabled` property)_
4865
- */
4866
- var Logger = class {
4867
- /**
4868
- * Log any number of values at the "debug" log level
4869
- */
4870
- get debug() {
4871
- return enabled ? console.debug : noop;
4872
- }
4873
- /**
4874
- * Log the value and shows all its properties
4875
- */
4876
- get dir() {
4877
- return enabled ? console.dir : noop;
4878
- }
4879
- /**
4880
- * Is logging to the console enabled? _(defaults to `true`)_
4881
- */
4882
- get enabled() {
4883
- return enabled;
4884
- }
4885
- /**
4886
- * Enable or disable logging to the console
4887
- */
4888
- set enabled(value) {
4889
- enabled = typeof value === "boolean" ? value : enabled;
4890
- }
4891
- /**
4892
- * Log any number of values at the "error" log level
4893
- */
4894
- get error() {
4895
- return enabled ? console.error : noop;
4896
- }
4897
- /**
4898
- * Log any number of values at the "info" log level
4899
- */
4900
- get info() {
4901
- return enabled ? console.info : noop;
4902
- }
4903
- /**
4904
- * Log any number of values at the "log" log level
4905
- */
4906
- get log() {
4907
- return enabled ? console.log : noop;
4908
- }
4909
- /**
4910
- * Log data as a table, with optional properties to use as columns
4911
- */
4912
- get table() {
4913
- return enabled ? console.table : noop;
4914
- }
4915
- /**
4916
- * Log any number of values together with a trace from where it was called
4917
- */
4918
- get trace() {
4919
- return enabled ? console.trace : noop;
4920
- }
4921
- /**
4922
- * Log any number of values at the "warn" log level
4923
- */
4924
- get warn() {
4925
- return enabled ? console.warn : noop;
4926
- }
4927
- /**
4928
- * Start a timed logger with a label
4929
- *
4930
- * @param label Label for the logger
4931
- * @returns _Timed_ instance
4932
- */
4933
- time(label) {
4934
- return new Timed(label);
4935
- }
4936
- };
4937
- /**
4938
4869
  * A named timer that can be used to log durations to the console
4939
4870
  */
4940
- var Timed = class {
4871
+ var TimedLogger = class {
4941
4872
  #logger;
4942
4873
  #stopper;
4943
4874
  #state;
@@ -4979,7 +4910,41 @@ var Timed = class {
4979
4910
  return stopper;
4980
4911
  }
4981
4912
  };
4982
- const logger = new Logger();
4913
+ const methods = [
4914
+ "debug",
4915
+ "dir",
4916
+ "error",
4917
+ "info",
4918
+ "log",
4919
+ "table",
4920
+ "trace",
4921
+ "warn"
4922
+ ];
4923
+ /**
4924
+ * A logger that can be used to log messages to the console
4925
+ *
4926
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
4927
+ */
4928
+ const Logger = (() => {
4929
+ const instance = {};
4930
+ Object.defineProperties(instance, {
4931
+ enabled: {
4932
+ get() {
4933
+ return enabled;
4934
+ },
4935
+ set(value) {
4936
+ enabled = typeof value === "boolean" ? value : enabled;
4937
+ }
4938
+ },
4939
+ time: { value(label) {
4940
+ return new TimedLogger(label);
4941
+ } }
4942
+ });
4943
+ for (const method of methods) Object.defineProperty(instance, method, { get() {
4944
+ return enabled ? console[method].bind(console) : noop;
4945
+ } });
4946
+ return Object.freeze(instance);
4947
+ })();
4983
4948
  let enabled = true;
4984
4949
  //#endregion
4985
4950
  //#region src/math.ts
@@ -5187,7 +5152,7 @@ function settlePromise(aborter, settler, value, signal) {
5187
5152
  }
5188
5153
  async function toResult(value) {
5189
5154
  const actual = typeof value === "function" ? value() : value;
5190
- if (!(actual instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT));
5155
+ if (!(actual instanceof Promise)) return Promise.reject(/* @__PURE__ */ new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT));
5191
5156
  return actual.then((result) => ok(result)).catch((reason) => error(reason));
5192
5157
  }
5193
5158
  //#endregion
@@ -5235,7 +5200,7 @@ async function getTimedPromise(promise, time, signal) {
5235
5200
  });
5236
5201
  }
5237
5202
  async function timed(promise, options) {
5238
- if (!(promise instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED));
5203
+ if (!(promise instanceof Promise)) return Promise.reject(/* @__PURE__ */ new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED));
5239
5204
  const { signal, time } = getPromiseOptions(options);
5240
5205
  if (signal?.aborted ?? false) return Promise.reject(signal.reason);
5241
5206
  return time > 0 ? getTimedPromise(promise, time, signal) : promise;
@@ -5244,7 +5209,7 @@ async function timed(promise, options) {
5244
5209
  //#region src/promise/index.ts
5245
5210
  async function attemptPromise(value, options) {
5246
5211
  const isFunction = typeof value === "function";
5247
- if (!isFunction && !(value instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT));
5212
+ if (!isFunction && !(value instanceof Promise)) return Promise.reject(/* @__PURE__ */ new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT));
5248
5213
  const { signal, time } = getPromiseOptions(options);
5249
5214
  if (signal?.aborted ?? false) return Promise.reject(signal.reason);
5250
5215
  function abort() {
@@ -5992,4 +5957,4 @@ var SizedSet = class extends Set {
5992
5957
  }
5993
5958
  };
5994
5959
  //#endregion
5995
- export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
5960
+ export { CancelablePromise, Logger, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
@@ -52,7 +52,7 @@ function join(array, delimiter) {
52
52
  const values = [];
53
53
  for (let index = 0; index < length; index += 1) {
54
54
  const item = getString(array[index]);
55
- if (item.trim().length > 0) values.push(item);
55
+ if (item.length > 0) values.push(item);
56
56
  }
57
57
  return values.join(typeof delimiter === "string" ? delimiter : "");
58
58
  }
package/dist/logger.d.mts CHANGED
@@ -1,10 +1,5 @@
1
1
  //#region src/logger.d.ts
2
- /**
3
- * A logger that can be used to log messages to the console
4
- *
5
- * _(Logging can be enabled or disabled by setting the `enabled` property)_
6
- */
7
- declare class Logger {
2
+ type LoggerInstance = {
8
3
  /**
9
4
  * Log any number of values at the "debug" log level
10
5
  */
@@ -49,14 +44,14 @@ declare class Logger {
49
44
  * Start a timed logger with a label
50
45
  *
51
46
  * @param label Label for the logger
52
- * @returns _Timed_ instance
47
+ * @returns _TimedLogger_ instance
53
48
  */
54
- time(label: string): Timed;
55
- }
49
+ time(label: string): TimedLogger;
50
+ };
56
51
  /**
57
52
  * A named timer that can be used to log durations to the console
58
53
  */
59
- declare class Timed {
54
+ declare class TimedLogger {
60
55
  #private;
61
56
  /**
62
57
  * Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
@@ -74,6 +69,11 @@ declare class Timed {
74
69
  get stop(): () => void;
75
70
  constructor(label: string);
76
71
  }
77
- declare const logger: Logger;
72
+ /**
73
+ * A logger that can be used to log messages to the console
74
+ *
75
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
76
+ */
77
+ declare const Logger: LoggerInstance;
78
78
  //#endregion
79
- export { type Logger, type Timed, logger };
79
+ export { Logger, type TimedLogger };
package/dist/logger.mjs CHANGED
@@ -1,85 +1,9 @@
1
1
  import { noop } from "./internal/function/misc.mjs";
2
2
  //#region src/logger.ts
3
3
  /**
4
- * A logger that can be used to log messages to the console
5
- *
6
- * _(Logging can be enabled or disabled by setting the `enabled` property)_
7
- */
8
- var Logger = class {
9
- /**
10
- * Log any number of values at the "debug" log level
11
- */
12
- get debug() {
13
- return enabled ? console.debug : noop;
14
- }
15
- /**
16
- * Log the value and shows all its properties
17
- */
18
- get dir() {
19
- return enabled ? console.dir : noop;
20
- }
21
- /**
22
- * Is logging to the console enabled? _(defaults to `true`)_
23
- */
24
- get enabled() {
25
- return enabled;
26
- }
27
- /**
28
- * Enable or disable logging to the console
29
- */
30
- set enabled(value) {
31
- enabled = typeof value === "boolean" ? value : enabled;
32
- }
33
- /**
34
- * Log any number of values at the "error" log level
35
- */
36
- get error() {
37
- return enabled ? console.error : noop;
38
- }
39
- /**
40
- * Log any number of values at the "info" log level
41
- */
42
- get info() {
43
- return enabled ? console.info : noop;
44
- }
45
- /**
46
- * Log any number of values at the "log" log level
47
- */
48
- get log() {
49
- return enabled ? console.log : noop;
50
- }
51
- /**
52
- * Log data as a table, with optional properties to use as columns
53
- */
54
- get table() {
55
- return enabled ? console.table : noop;
56
- }
57
- /**
58
- * Log any number of values together with a trace from where it was called
59
- */
60
- get trace() {
61
- return enabled ? console.trace : noop;
62
- }
63
- /**
64
- * Log any number of values at the "warn" log level
65
- */
66
- get warn() {
67
- return enabled ? console.warn : noop;
68
- }
69
- /**
70
- * Start a timed logger with a label
71
- *
72
- * @param label Label for the logger
73
- * @returns _Timed_ instance
74
- */
75
- time(label) {
76
- return new Timed(label);
77
- }
78
- };
79
- /**
80
4
  * A named timer that can be used to log durations to the console
81
5
  */
82
- var Timed = class {
6
+ var TimedLogger = class {
83
7
  #logger;
84
8
  #stopper;
85
9
  #state;
@@ -121,7 +45,41 @@ var Timed = class {
121
45
  return stopper;
122
46
  }
123
47
  };
124
- const logger = new Logger();
48
+ const methods = [
49
+ "debug",
50
+ "dir",
51
+ "error",
52
+ "info",
53
+ "log",
54
+ "table",
55
+ "trace",
56
+ "warn"
57
+ ];
58
+ /**
59
+ * A logger that can be used to log messages to the console
60
+ *
61
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
62
+ */
63
+ const Logger = (() => {
64
+ const instance = {};
65
+ Object.defineProperties(instance, {
66
+ enabled: {
67
+ get() {
68
+ return enabled;
69
+ },
70
+ set(value) {
71
+ enabled = typeof value === "boolean" ? value : enabled;
72
+ }
73
+ },
74
+ time: { value(label) {
75
+ return new TimedLogger(label);
76
+ } }
77
+ });
78
+ for (const method of methods) Object.defineProperty(instance, method, { get() {
79
+ return enabled ? console[method].bind(console) : noop;
80
+ } });
81
+ return Object.freeze(instance);
82
+ })();
125
83
  let enabled = true;
126
84
  //#endregion
127
- export { logger };
85
+ export { Logger };
@@ -14,6 +14,13 @@ declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): st
14
14
  * @returns Dedented string
15
15
  */
16
16
  declare function dedent(value: string): string;
17
+ /**
18
+ * Get a new UUID string _(version 4)_ for use in _HTML_
19
+ *
20
+ * @param html Use _HTML_-friendly format
21
+ * @returns UUID string
22
+ */
23
+ declare function getUuid(html: true): string;
17
24
  /**
18
25
  * Get a new UUID string _(version 4)_
19
26
  *
@@ -30,19 +30,25 @@ function dedent(value, ...values) {
30
30
  *
31
31
  * @returns UUID string
32
32
  */
33
- function getUuid() {
34
- const bytes = new Uint8Array(16);
35
- crypto.getRandomValues(bytes);
36
- bytes[6] = bytes[6] & 15 | 64;
37
- bytes[8] = bytes[8] & 63 | 128;
38
- const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, ZERO)).join("");
39
- return [
40
- hex.substring(0, 8),
41
- hex.substring(8, 12),
42
- hex.substring(12, 16),
43
- hex.substring(16, 20),
44
- hex.substring(20, 32)
45
- ].join("-");
33
+ function getUuid(html) {
34
+ const forHTML = html === true;
35
+ let uuid;
36
+ while (true) {
37
+ const bytes = new Uint8Array(16);
38
+ crypto.getRandomValues(bytes);
39
+ bytes[6] = bytes[6] & 15 | 64;
40
+ bytes[8] = bytes[8] & 63 | 128;
41
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, ZERO)).join("");
42
+ uuid = [
43
+ hex.substring(0, 8),
44
+ hex.substring(8, 12),
45
+ hex.substring(12, 16),
46
+ hex.substring(16, 20),
47
+ hex.substring(20, 32)
48
+ ].join("-");
49
+ if (!forHTML || !NUMERICAL_PREFIX_PATTERN.test(uuid)) break;
50
+ }
51
+ return uuid;
46
52
  }
47
53
  /**
48
54
  * Parse a JSON string into its proper value _(or `undefined` if it fails)_
@@ -84,6 +90,7 @@ function truncate(value, length, suffix) {
84
90
  const truncatedLength = length - actualSuffixLength;
85
91
  return `${value.slice(0, truncatedLength)}${actualSuffix}`;
86
92
  }
93
+ const NUMERICAL_PREFIX_PATTERN = /^\d/;
87
94
  const ZERO = "0";
88
95
  //#endregion
89
96
  export { dedent, getString, getUuid, join, parse, trim, truncate, words };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.187.1",
3
+ "version": "0.188.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "helper",
@@ -257,7 +257,7 @@
257
257
  "watch": "npx vite build --watch"
258
258
  },
259
259
  "devDependencies": {
260
- "@oxlint/plugins": "^1.66",
260
+ "@oxlint/plugins": "^1.69",
261
261
  "@types/node": "^25.9",
262
262
  "@vitest/coverage-istanbul": "^4.1",
263
263
  "eslint": "^10.4",
@@ -82,7 +82,7 @@ export function join(array: unknown[], delimiter?: string): string {
82
82
  for (let index = 0; index < length; index += 1) {
83
83
  const item = getString(array[index]);
84
84
 
85
- if (item.trim().length > 0) {
85
+ if (item.length > 0) {
86
86
  values.push(item);
87
87
  }
88
88
  }
package/src/logger.ts CHANGED
@@ -2,97 +2,70 @@ import {noop} from './internal/function/misc';
2
2
 
3
3
  // #region Types
4
4
 
5
- /**
6
- * A logger that can be used to log messages to the console
7
- *
8
- * _(Logging can be enabled or disabled by setting the `enabled` property)_
9
- */
10
- class Logger {
5
+ type LoggerInstance = {
11
6
  /**
12
7
  * Log any number of values at the "debug" log level
13
8
  */
14
- get debug(): typeof console.debug {
15
- return enabled ? console.debug : noop;
16
- }
9
+ get debug(): typeof console.debug;
17
10
 
18
11
  /**
19
12
  * Log the value and shows all its properties
20
13
  */
21
- get dir(): typeof console.dir {
22
- return enabled ? console.dir : noop;
23
- }
14
+ get dir(): typeof console.dir;
24
15
 
25
16
  /**
26
17
  * Is logging to the console enabled? _(defaults to `true`)_
27
18
  */
28
- get enabled(): boolean {
29
- return enabled;
30
- }
19
+ get enabled(): boolean;
31
20
 
32
21
  /**
33
22
  * Enable or disable logging to the console
34
23
  */
35
- set enabled(value: boolean) {
36
- enabled = typeof value === 'boolean' ? value : enabled;
37
- }
24
+ set enabled(value: boolean);
38
25
 
39
26
  /**
40
27
  * Log any number of values at the "error" log level
41
28
  */
42
- get error(): typeof console.error {
43
- return enabled ? console.error : noop;
44
- }
29
+ get error(): typeof console.error;
45
30
 
46
31
  /**
47
32
  * Log any number of values at the "info" log level
48
33
  */
49
- get info(): typeof console.info {
50
- return enabled ? console.info : noop;
51
- }
34
+ get info(): typeof console.info;
52
35
 
53
36
  /**
54
37
  * Log any number of values at the "log" log level
55
38
  */
56
- get log(): typeof console.log {
57
- return enabled ? console.log : noop;
58
- }
39
+ get log(): typeof console.log;
59
40
 
60
41
  /**
61
42
  * Log data as a table, with optional properties to use as columns
62
43
  */
63
- get table(): typeof console.table {
64
- return enabled ? console.table : noop;
65
- }
44
+ get table(): typeof console.table;
66
45
 
67
46
  /**
68
47
  * Log any number of values together with a trace from where it was called
69
48
  */
70
- get trace(): typeof console.trace {
71
- return enabled ? console.trace : noop;
72
- }
49
+ get trace(): typeof console.trace;
73
50
 
74
51
  /**
75
52
  * Log any number of values at the "warn" log level
76
53
  */
77
- get warn(): typeof console.warn {
78
- return enabled ? console.warn : noop;
79
- }
54
+ get warn(): typeof console.warn;
80
55
 
81
56
  /**
82
57
  * Start a timed logger with a label
83
58
  *
84
59
  * @param label Label for the logger
85
- * @returns _Timed_ instance
60
+ * @returns _TimedLogger_ instance
86
61
  */
87
- time(label: string): Timed {
88
- return new Timed(label);
89
- }
90
- }
62
+ time(label: string): TimedLogger;
63
+ };
91
64
 
92
65
  /**
93
66
  * A named timer that can be used to log durations to the console
94
67
  */
95
- class Timed {
68
+ class TimedLogger {
96
69
  #logger: typeof console.timeLog | undefined;
97
70
  #stopper: typeof console.timeEnd | undefined;
98
71
 
@@ -158,7 +131,42 @@ type TimeState = {
158
131
 
159
132
  // #region Variables
160
133
 
161
- const logger = new Logger();
134
+ const methods = ['debug', 'dir', 'error', 'info', 'log', 'table', 'trace', 'warn'] as const;
135
+
136
+ /**
137
+ * A logger that can be used to log messages to the console
138
+ *
139
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
140
+ */
141
+ const Logger = (() => {
142
+ const instance = {};
143
+
144
+ Object.defineProperties(instance, {
145
+ enabled: {
146
+ get() {
147
+ return enabled;
148
+ },
149
+ set(value: boolean) {
150
+ enabled = typeof value === 'boolean' ? value : enabled;
151
+ },
152
+ },
153
+ time: {
154
+ value(label: string) {
155
+ return new TimedLogger(label);
156
+ },
157
+ },
158
+ });
159
+
160
+ for (const method of methods) {
161
+ Object.defineProperty(instance, method, {
162
+ get() {
163
+ return enabled ? console[method].bind(console) : noop;
164
+ },
165
+ });
166
+ }
167
+
168
+ return Object.freeze(instance);
169
+ })() as LoggerInstance;
162
170
 
163
171
  let enabled = true;
164
172
 
@@ -166,6 +174,6 @@ let enabled = true;
166
174
 
167
175
  // #region Exports
168
176
 
169
- export {logger, type Logger, type Timed};
177
+ export {Logger, type TimedLogger};
170
178
 
171
179
  // #endregion
@@ -69,29 +69,56 @@ export function dedent(value: string | TemplateStringsArray, ...values: unknown[
69
69
  return result.trim();
70
70
  }
71
71
 
72
+ /**
73
+ * Get a new UUID string _(version 4)_ for use in _HTML_
74
+ *
75
+ * @param html Use _HTML_-friendly format
76
+ * @returns UUID string
77
+ */
78
+ export function getUuid(html: true): string;
79
+
80
+ /**
81
+ * Get a new UUID string _(version 4)_
82
+ *
83
+ * @returns UUID string
84
+ */
85
+ export function getUuid(): string;
86
+
72
87
  /**
73
88
  * Get a new UUID string _(version 4)_
74
89
  *
75
90
  * @returns UUID string
76
91
  */
77
- export function getUuid(): string {
78
- const bytes = new Uint8Array(16);
92
+ export function getUuid(html?: unknown): string {
93
+ const forHTML = html === true;
94
+
95
+ let uuid: string;
96
+
97
+ while (true) {
98
+ const bytes = new Uint8Array(16);
99
+
100
+ crypto.getRandomValues(bytes);
79
101
 
80
- crypto.getRandomValues(bytes);
102
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
81
103
 
82
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
104
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
83
105
 
84
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
106
+ const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, ZERO)).join('');
85
107
 
86
- const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, ZERO)).join('');
108
+ uuid = [
109
+ hex.substring(0, 8),
110
+ hex.substring(8, 12),
111
+ hex.substring(12, 16),
112
+ hex.substring(16, 20),
113
+ hex.substring(20, 32),
114
+ ].join('-');
87
115
 
88
- return [
89
- hex.substring(0, 8),
90
- hex.substring(8, 12),
91
- hex.substring(12, 16),
92
- hex.substring(16, 20),
93
- hex.substring(20, 32),
94
- ].join('-');
116
+ if (!forHTML || !NUMERICAL_PREFIX_PATTERN.test(uuid)) {
117
+ break;
118
+ }
119
+ }
120
+
121
+ return uuid;
95
122
  }
96
123
 
97
124
  /**
@@ -155,6 +182,8 @@ export function truncate(value: string, length: number, suffix?: string): string
155
182
 
156
183
  // #region Variables
157
184
 
185
+ const NUMERICAL_PREFIX_PATTERN = /^\d/;
186
+
158
187
  const ZERO = '0';
159
188
 
160
189
  // #endregion