@oscarpalmer/atoms 0.184.2 → 0.185.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 (88) hide show
  1. package/dist/array/index.d.mts +2 -2
  2. package/dist/array/index.mjs +2 -2
  3. package/dist/array/{position.d.mts → match.d.mts} +9 -6
  4. package/dist/array/{position.mjs → match.mjs} +16 -16
  5. package/dist/array/move.mjs +1 -1
  6. package/dist/array/sort.d.mts +9 -4
  7. package/dist/array/sort.mjs +1 -1
  8. package/dist/array/swap.mjs +1 -1
  9. package/dist/beacon.d.mts +12 -0
  10. package/dist/beacon.mjs +9 -0
  11. package/dist/color/instance.d.mts +8 -0
  12. package/dist/color/instance.mjs +3 -0
  13. package/dist/color/models.d.mts +30 -0
  14. package/dist/function/assert.d.mts +29 -8
  15. package/dist/function/assert.mjs +29 -8
  16. package/dist/function/memoize.d.mts +3 -0
  17. package/dist/function/memoize.mjs +3 -0
  18. package/dist/function/retry.d.mts +3 -0
  19. package/dist/function/retry.mjs +3 -0
  20. package/dist/function/work.mjs +1 -1
  21. package/dist/index.d.mts +271 -158
  22. package/dist/index.mjs +230 -163
  23. package/dist/internal/value/compare.d.mts +2 -1
  24. package/dist/internal/value/equal.d.mts +5 -0
  25. package/dist/internal/value/get.d.mts +2 -2
  26. package/dist/internal/value/has.d.mts +3 -3
  27. package/dist/internal/value/has.mjs +1 -1
  28. package/dist/internal/value/misc.d.mts +2 -2
  29. package/dist/internal/value/misc.mjs +10 -4
  30. package/dist/logger.d.mts +11 -0
  31. package/dist/logger.mjs +11 -0
  32. package/dist/promise/helpers.mjs +1 -1
  33. package/dist/promise/index.d.mts +0 -6
  34. package/dist/promise/models.d.mts +36 -0
  35. package/dist/promise/models.mjs +6 -0
  36. package/dist/queue.d.mts +13 -1
  37. package/dist/queue.mjs +9 -0
  38. package/dist/result/index.d.mts +0 -8
  39. package/dist/result/index.mjs +0 -8
  40. package/dist/result/match.d.mts +4 -4
  41. package/dist/result/work/flow.d.mts +12 -36
  42. package/dist/result/work/pipe.d.mts +11 -33
  43. package/dist/sized/set.d.mts +3 -2
  44. package/dist/sized/set.mjs +3 -2
  45. package/dist/value/handle.mjs +1 -1
  46. package/dist/value/shake.d.mts +3 -0
  47. package/dist/value/smush.d.mts +3 -0
  48. package/dist/value/transform.d.mts +9 -0
  49. package/dist/value/unsmush.d.mts +3 -0
  50. package/package.json +2 -2
  51. package/src/array/difference.ts +4 -0
  52. package/src/array/from.ts +4 -0
  53. package/src/array/index.ts +1 -1
  54. package/src/array/intersection.ts +4 -0
  55. package/src/array/{position.ts → match.ts} +28 -25
  56. package/src/array/move.ts +5 -1
  57. package/src/array/reverse.ts +4 -0
  58. package/src/array/select.ts +2 -0
  59. package/src/array/sort.ts +9 -4
  60. package/src/array/swap.ts +5 -1
  61. package/src/array/toggle.ts +4 -0
  62. package/src/array/union.ts +4 -0
  63. package/src/beacon.ts +12 -0
  64. package/src/color/index.ts +0 -3
  65. package/src/color/instance.ts +9 -1
  66. package/src/color/models.ts +30 -0
  67. package/src/function/assert.ts +66 -7
  68. package/src/function/memoize.ts +3 -0
  69. package/src/function/once.ts +5 -1
  70. package/src/function/retry.ts +3 -0
  71. package/src/internal/value/compare.ts +2 -1
  72. package/src/internal/value/equal.ts +5 -0
  73. package/src/internal/value/get.ts +2 -2
  74. package/src/internal/value/has.ts +6 -6
  75. package/src/internal/value/misc.ts +24 -13
  76. package/src/logger.ts +11 -0
  77. package/src/promise/index.ts +0 -6
  78. package/src/promise/models.ts +36 -0
  79. package/src/queue.ts +13 -1
  80. package/src/result/index.ts +0 -8
  81. package/src/result/match.ts +4 -4
  82. package/src/result/work/flow.ts +12 -36
  83. package/src/result/work/pipe.ts +11 -33
  84. package/src/sized/set.ts +4 -3
  85. package/src/value/shake.ts +3 -0
  86. package/src/value/smush.ts +3 -0
  87. package/src/value/transform.ts +9 -0
  88. package/src/value/unsmush.ts +3 -0
package/dist/index.mjs CHANGED
@@ -525,16 +525,16 @@ function partition(array, ...parameters) {
525
525
  return [matched, notMatched];
526
526
  }
527
527
  //#endregion
528
- //#region src/array/position.ts
528
+ //#region src/array/match.ts
529
529
  function endsWithArray(haystack, needle, key) {
530
530
  return endings.has(getPosition(haystack, needle, key)[1]);
531
531
  }
532
- function getArrayPosition(haystack, needle, key) {
532
+ function getArrayComparison(haystack, needle, key) {
533
533
  return getPosition(haystack, needle, key)[1];
534
534
  }
535
535
  function getName(start, haystack, needle) {
536
- if (start === 0) return haystack === needle ? POSITION_SAME : POSITION_START;
537
- return start + needle === haystack ? POSITION_END : POSITION_INSIDE;
536
+ if (start === 0) return haystack === needle ? COMPARISON_SAME : COMPARISON_START;
537
+ return start + needle === haystack ? COMPARISON_END : COMPARISON_INSIDE;
538
538
  }
539
539
  function getPosition(haystack, needle, key) {
540
540
  if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
@@ -569,17 +569,17 @@ function indexOfArray(haystack, needle, key) {
569
569
  function startsWithArray(haystack, needle, key) {
570
570
  return starts.has(getPosition(haystack, needle, key)[1]);
571
571
  }
572
- const POSITION_END = "end";
573
- const POSITION_INSIDE = "inside";
574
- const POSITION_INVALID = "invalid";
575
- const POSITION_OUTSIDE = "outside";
576
- const POSITION_SAME = "same";
577
- const POSITION_START = "start";
578
- const endings = new Set([POSITION_END, POSITION_SAME]);
579
- const invalid = [-1, POSITION_INVALID];
580
- const outside = [-1, POSITION_OUTSIDE];
581
- const outsides = new Set([POSITION_INVALID, POSITION_OUTSIDE]);
582
- const starts = new Set([POSITION_START, POSITION_SAME]);
572
+ const COMPARISON_END = "end";
573
+ const COMPARISON_INSIDE = "inside";
574
+ const COMPARISON_INVALID = "invalid";
575
+ const COMPARISON_OUTSIDE = "outside";
576
+ const COMPARISON_SAME = "same";
577
+ const COMPARISON_START = "start";
578
+ const endings = new Set([COMPARISON_END, COMPARISON_SAME]);
579
+ const invalid = [-1, COMPARISON_INVALID];
580
+ const outside = [-1, COMPARISON_OUTSIDE];
581
+ const outsides = new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
582
+ const starts = new Set([COMPARISON_START, COMPARISON_SAME]);
583
583
  //#endregion
584
584
  //#region src/array/push.ts
585
585
  /**
@@ -1196,7 +1196,7 @@ function sortArray(array, sorters) {
1196
1196
  const { length } = sorters;
1197
1197
  return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
1198
1198
  }
1199
- sort.index = getSortedIndex;
1199
+ sort.getIndex = getSortedIndex;
1200
1200
  sort.initialize = initializeSorter;
1201
1201
  sort.is = isSorted;
1202
1202
  const SORT_PEEK_PERCENTAGE = 10;
@@ -1299,12 +1299,132 @@ function toRecordArrays(array, first, second) {
1299
1299
  return groupValues(array, first, second, true);
1300
1300
  }
1301
1301
  //#endregion
1302
+ //#region src/internal/result.ts
1303
+ function _isResult(value, okValue) {
1304
+ if (isNonPlainObject(value)) return false;
1305
+ return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
1306
+ }
1307
+ function isError(value, extended) {
1308
+ return _isResult(value, false) && (extended === true ? value.original instanceof Error : true);
1309
+ }
1310
+ /**
1311
+ * Is the result ok?
1312
+ * @param result Result to check
1313
+ * @returns `true` if the result is ok, `false` otherwise
1314
+ */
1315
+ function isOk(value) {
1316
+ return _isResult(value, true);
1317
+ }
1318
+ /**
1319
+ * Is the value a result?
1320
+ * @param value Value to check
1321
+ * @returns `true` if the value is a result, `false` otherwise
1322
+ */
1323
+ function isResult(value) {
1324
+ return _isResult(value, true) || _isResult(value, false);
1325
+ }
1326
+ const PROPERTY_ERROR = "error";
1327
+ const PROPERTY_VALUE = "value";
1328
+ //#endregion
1329
+ //#region src/result/misc.ts
1330
+ function error(value, original) {
1331
+ return getError(value, original);
1332
+ }
1333
+ function getError(value, original) {
1334
+ const errorResult = {
1335
+ error: value,
1336
+ ok: false
1337
+ };
1338
+ if (original instanceof Error) errorResult.original = original;
1339
+ return errorResult;
1340
+ }
1341
+ /**
1342
+ * Creates an ok result
1343
+ * @param value Value
1344
+ * @returns Ok result
1345
+ */
1346
+ function ok(value) {
1347
+ return {
1348
+ ok: true,
1349
+ value
1350
+ };
1351
+ }
1352
+ /**
1353
+ * Converts a result to a promise
1354
+ *
1355
+ * Resolves if ok, rejects for error
1356
+ * @param result Result to convert
1357
+ * @returns Promised result
1358
+ */
1359
+ async function toPromise(result) {
1360
+ const actual = typeof result === "function" ? result() : result;
1361
+ if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
1362
+ return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
1363
+ }
1364
+ function unwrap(value, defaultValue) {
1365
+ return isOk(value) ? value.value : defaultValue;
1366
+ }
1367
+ const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
1368
+ //#endregion
1369
+ //#region src/internal/value/misc.ts
1370
+ function findKey(needle, haystack) {
1371
+ const keys = Object.keys(haystack);
1372
+ const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
1373
+ return index > -1 ? keys[index] : needle;
1374
+ }
1375
+ function getNestedValue(data, path, ignoreCase) {
1376
+ if (typeof data !== "object" || data === null) return error(NESTED_MESSAGE_INPUT);
1377
+ if (typeof path !== "string" || path.trim().length === 0) return error(NESTED_MESSAGE_PATH);
1378
+ const shouldIgnoreCase = ignoreCase === true;
1379
+ const paths = getPaths(path, shouldIgnoreCase);
1380
+ if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
1381
+ const { length } = paths;
1382
+ let current = data;
1383
+ for (let index = 0; index < length; index += 1) {
1384
+ const part = paths[index];
1385
+ const handled = handleValue(current, part, null, true, shouldIgnoreCase);
1386
+ if (!handled.ok) return handled;
1387
+ current = handled.value;
1388
+ }
1389
+ return ok(current);
1390
+ }
1391
+ function getPaths(path, lowercase) {
1392
+ const normalized = lowercase ? path.toLowerCase() : path;
1393
+ if (!EXPRESSION_NESTED.test(normalized)) return normalized;
1394
+ return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
1395
+ }
1396
+ function handleValue(data, path, value, get, ignoreCase) {
1397
+ if (typeof data === "object" && data !== null) {
1398
+ if (ignoreKey(path)) return error(NESTED_MESSAGE_UNSAFE);
1399
+ const key = ignoreCase ? findKey(path, data) : path;
1400
+ if (get) return key in data ? ok(data[key]) : error(NESTED_MESSAGE_MISSING);
1401
+ data[key] = typeof value === "function" ? value(data[key]) : value;
1402
+ }
1403
+ if (get) return error(NESTED_MESSAGE_MISSING);
1404
+ }
1405
+ const EXPRESSION_BRACKET = /\[(\w+)\]/g;
1406
+ const EXPRESSION_DOTS = /^\.|\.$/g;
1407
+ const EXPRESSION_NESTED = /\.|\[\w+\]/;
1408
+ const NESTED_MESSAGE_INPUT = "Expected data to be an object";
1409
+ const NESTED_MESSAGE_MISSING = "Expected property to exist in object";
1410
+ const NESTED_MESSAGE_PATH = "Expected path to be a string";
1411
+ const NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
1412
+ //#endregion
1413
+ //#region src/internal/value/has.ts
1414
+ function hasValue(data, path, ignoreCase) {
1415
+ return getNestedValue(data, path, ignoreCase === true).ok;
1416
+ }
1417
+ hasValue.get = hasValueResult;
1418
+ function hasValueResult(data, path, ignoreCase) {
1419
+ return getNestedValue(data, path, ignoreCase === true);
1420
+ }
1421
+ //#endregion
1302
1422
  //#region src/function/assert.ts
1303
1423
  /**
1304
1424
  * Asserts that a condition is true, throwing an error if it is not
1305
1425
  * @param condition Condition to assert
1306
1426
  * @param message Error message
1307
- * @param error Error constructor
1427
+ * @param error Error constructor _(defaults to `Error`)_
1308
1428
  */
1309
1429
  function assert(condition, message, error) {
1310
1430
  if (!condition()) throw new (error ?? Error)(message);
@@ -1313,13 +1433,14 @@ assert.condition = assertCondition;
1313
1433
  assert.defined = assertDefined;
1314
1434
  assert.instanceOf = assertInstanceOf;
1315
1435
  assert.is = assertIs;
1436
+ assert.property = assertProperty;
1316
1437
  /**
1317
1438
  * Creates an asserter that asserts a condition is true, throwing an error if it is not
1318
1439
  *
1319
1440
  * Available as `assertCondition` and `assert.condition`
1320
1441
  * @param condition Condition to assert
1321
1442
  * @param message Error message
1322
- * @param error Error constructor
1443
+ * @param error Error constructor _(defaults to `Error`)_
1323
1444
  * @returns Asserter
1324
1445
  */
1325
1446
  function assertCondition(condition, message, error) {
@@ -1328,14 +1449,15 @@ function assertCondition(condition, message, error) {
1328
1449
  };
1329
1450
  }
1330
1451
  /**
1331
- * Asserts that a value is defined throwing an error if it is not
1452
+ * Asserts that a value is defined, throwing an error if it is not
1332
1453
  *
1333
1454
  * Available as `assertDefined` and `assert.defined`
1334
1455
  * @param value Value to assert
1335
1456
  * @param message Error message
1457
+ * @param error Error constructor _(defaults to `Error`)_
1336
1458
  */
1337
- function assertDefined(value, message) {
1338
- assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED);
1459
+ function assertDefined(value, message, error) {
1460
+ assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED, error);
1339
1461
  }
1340
1462
  /**
1341
1463
  * Creates an asserter that asserts a value is an instance of a constructor, throwing an error if it is not
@@ -1343,7 +1465,7 @@ function assertDefined(value, message) {
1343
1465
  * Available as `assertInstanceOf` and `assert.instanceOf`
1344
1466
  * @param constructor Constructor to check against
1345
1467
  * @param message Error message
1346
- * @param error Error constructor
1468
+ * @param error Error constructor _(defaults to `Error`)_
1347
1469
  * @returns Asserter
1348
1470
  */
1349
1471
  function assertInstanceOf(constructor, message, error) {
@@ -1357,7 +1479,7 @@ function assertInstanceOf(constructor, message, error) {
1357
1479
  * Available as `assertIs` and `assert.is`
1358
1480
  * @param condition Type guard function to check the value
1359
1481
  * @param message Error message
1360
- * @param error Error constructor
1482
+ * @param error Error constructor _(defaults to `Error`)_
1361
1483
  * @returns Asserter
1362
1484
  */
1363
1485
  function assertIs(condition, message, error) {
@@ -1365,6 +1487,24 @@ function assertIs(condition, message, error) {
1365
1487
  assert(() => condition(value), message, error);
1366
1488
  };
1367
1489
  }
1490
+ /**
1491
+ * Creates an asserter that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
1492
+ *
1493
+ * Available as `assertProperty` and `assert.property`
1494
+ * @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
1495
+ * @param condition Condition to assert for the property
1496
+ * @param message Error message
1497
+ * @param error Error constructor _(defaults to `Error`)_
1498
+ * @returns Asserter
1499
+ */
1500
+ function assertProperty(path, condition, message, error) {
1501
+ return (value) => {
1502
+ assert(() => {
1503
+ const result = hasValueResult(value, path, false);
1504
+ return result.ok && condition(result.value);
1505
+ }, message, error);
1506
+ };
1507
+ }
1368
1508
  const MESSAGE_VALUE_DEFINED = "Expected value to be defined";
1369
1509
  //#endregion
1370
1510
  //#region src/internal/function/misc.ts
@@ -1500,6 +1640,9 @@ var SizedMap = class extends Map {
1500
1640
  };
1501
1641
  //#endregion
1502
1642
  //#region src/function/memoize.ts
1643
+ /**
1644
+ * A memoized function, caching and retrieving results based on the its parameters _(or a custom cache key)_
1645
+ */
1503
1646
  var Memoized = class {
1504
1647
  #state;
1505
1648
  /**
@@ -1833,6 +1976,9 @@ const ONCE_MESSAGE_CLEARED = "Once has been cleared";
1833
1976
  const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
1834
1977
  //#endregion
1835
1978
  //#region src/function/retry.ts
1979
+ /**
1980
+ * An error thrown when a retry fails
1981
+ */
1836
1982
  var RetryError = class extends Error {
1837
1983
  constructor(message, original) {
1838
1984
  super(message);
@@ -1912,33 +2058,6 @@ const RETRY_ERROR_NAME = "RetryError";
1912
2058
  const RETRY_MESSAGE_EXPECTATION = "Retry expected a function";
1913
2059
  const RETRY_MESSAGE_FAILED = "Retry failed";
1914
2060
  //#endregion
1915
- //#region src/internal/result.ts
1916
- function _isResult(value, okValue) {
1917
- if (isNonPlainObject(value)) return false;
1918
- return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
1919
- }
1920
- function isError(value, extended) {
1921
- return _isResult(value, false) && (extended === true ? value.original instanceof Error : true);
1922
- }
1923
- /**
1924
- * Is the result ok?
1925
- * @param result Result to check
1926
- * @returns `true` if the result is ok, `false` otherwise
1927
- */
1928
- function isOk(value) {
1929
- return _isResult(value, true);
1930
- }
1931
- /**
1932
- * Is the value a result?
1933
- * @param value Value to check
1934
- * @returns `true` if the value is a result, `false` otherwise
1935
- */
1936
- function isResult(value) {
1937
- return _isResult(value, true) || _isResult(value, false);
1938
- }
1939
- const PROPERTY_ERROR = "error";
1940
- const PROPERTY_VALUE = "value";
1941
- //#endregion
1942
2061
  //#region src/function/work.ts
1943
2062
  function asyncFlow(...fns) {
1944
2063
  assertFlowFunctions(fns);
@@ -2169,98 +2288,11 @@ const ERROR_PROPERTIES = ["name", "message"];
2169
2288
  const EXPRESSION_PROPERTIES = ["source", "flags"];
2170
2289
  const MINIMUM_LENGTH_FOR_SET = 16;
2171
2290
  //#endregion
2172
- //#region src/result/misc.ts
2173
- function error(value, original) {
2174
- return getError(value, original);
2175
- }
2176
- function getError(value, original) {
2177
- const errorResult = {
2178
- error: value,
2179
- ok: false
2180
- };
2181
- if (original instanceof Error) errorResult.original = original;
2182
- return errorResult;
2183
- }
2184
- /**
2185
- * Creates an ok result
2186
- * @param value Value
2187
- * @returns Ok result
2188
- */
2189
- function ok(value) {
2190
- return {
2191
- ok: true,
2192
- value
2193
- };
2194
- }
2195
- /**
2196
- * Converts a result to a promise
2197
- *
2198
- * Resolves if ok, rejects for error
2199
- * @param result Result to convert
2200
- * @returns Promised result
2201
- */
2202
- async function toPromise(result) {
2203
- const actual = typeof result === "function" ? result() : result;
2204
- if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
2205
- return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
2206
- }
2207
- function unwrap(value, defaultValue) {
2208
- return isOk(value) ? value.value : defaultValue;
2209
- }
2210
- const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
2211
- //#endregion
2212
- //#region src/internal/value/misc.ts
2213
- function findKey(needle, haystack) {
2214
- const keys = Object.keys(haystack);
2215
- const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
2216
- return index > -1 ? keys[index] : needle;
2217
- }
2218
- function getNestedValue(data, path, ignoreCase) {
2219
- if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return error(void 0);
2220
- const shouldIgnoreCase = ignoreCase === true;
2221
- const paths = getPaths(path, shouldIgnoreCase);
2222
- if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
2223
- const { length } = paths;
2224
- let current = data;
2225
- for (let index = 0; index < length; index += 1) {
2226
- const part = paths[index];
2227
- const handled = handleValue(current, part, null, true, shouldIgnoreCase);
2228
- if (!handled.ok) return handled;
2229
- current = handled.value;
2230
- }
2231
- return ok(current);
2232
- }
2233
- function getPaths(path, lowercase) {
2234
- const normalized = lowercase ? path.toLowerCase() : path;
2235
- if (!EXPRESSION_NESTED.test(normalized)) return normalized;
2236
- return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
2237
- }
2238
- function handleValue(data, path, value, get, ignoreCase) {
2239
- if (typeof data === "object" && data !== null && !ignoreKey(path)) {
2240
- const key = ignoreCase ? findKey(path, data) : path;
2241
- if (get) return key in data ? ok(data[key]) : error(void 0);
2242
- data[key] = typeof value === "function" ? value(data[key]) : value;
2243
- }
2244
- if (get) return error(void 0);
2245
- }
2246
- const EXPRESSION_BRACKET = /\[(\w+)\]/g;
2247
- const EXPRESSION_DOTS = /^\.|\.$/g;
2248
- const EXPRESSION_NESTED = /\.|\[\w+\]/;
2249
- //#endregion
2250
2291
  //#region src/internal/value/get.ts
2251
2292
  function getValue(data, path, ignoreCase) {
2252
2293
  return getNestedValue(data, path, ignoreCase === true).value;
2253
2294
  }
2254
2295
  //#endregion
2255
- //#region src/internal/value/has.ts
2256
- function hasValue(data, path, ignoreCase) {
2257
- return getNestedValue(data, path, ignoreCase === true).ok;
2258
- }
2259
- hasValue.get = hasValueResult;
2260
- function hasValueResult(data, path, ignoreCase) {
2261
- return getNestedValue(data, path, ignoreCase === true);
2262
- }
2263
- //#endregion
2264
2296
  //#region src/internal/value/set.ts
2265
2297
  function setValue(data, path, value, ignoreCase) {
2266
2298
  if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return data;
@@ -3603,6 +3635,9 @@ function transformValue(value, transformer) {
3603
3635
  }
3604
3636
  //#endregion
3605
3637
  //#region src/beacon.ts
3638
+ /**
3639
+ * A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
3640
+ */
3606
3641
  var Beacon = class {
3607
3642
  #options;
3608
3643
  #state;
@@ -3673,6 +3708,9 @@ var Beacon = class {
3673
3708
  if (finish === true) finishBeacon(this.#state, true);
3674
3709
  }
3675
3710
  };
3711
+ /**
3712
+ * An observable holds a value and allows observers to subscribe to changes in that value
3713
+ */
3676
3714
  var Observable = class {
3677
3715
  #state;
3678
3716
  constructor(instance, observers) {
@@ -3697,6 +3735,9 @@ var Observable = class {
3697
3735
  return instance;
3698
3736
  }
3699
3737
  };
3738
+ /**
3739
+ * A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
3740
+ */
3700
3741
  var Subscription = class {
3701
3742
  #state;
3702
3743
  constructor(state) {
@@ -4317,6 +4358,9 @@ function setRGBColor(state, value, alpha) {
4317
4358
  }
4318
4359
  //#endregion
4319
4360
  //#region src/color/instance.ts
4361
+ /**
4362
+ * A color that is represented in multiple color formats
4363
+ */
4320
4364
  var Color = class {
4321
4365
  #state;
4322
4366
  /**
@@ -4438,6 +4482,11 @@ function getColor(value) {
4438
4482
  }
4439
4483
  //#endregion
4440
4484
  //#region src/logger.ts
4485
+ /**
4486
+ * A logger that can be used to log messages to the console
4487
+ *
4488
+ * _(Logging can be enabled or disabled by setting the `enabled` property)_
4489
+ */
4441
4490
  var Logger = class {
4442
4491
  /**
4443
4492
  * Log any number of values at the "debug" log level
@@ -4508,10 +4557,16 @@ var Logger = class {
4508
4557
  return new Time(label);
4509
4558
  }
4510
4559
  };
4560
+ /**
4561
+ * A named timer that can be used to log durations to the console
4562
+ */
4511
4563
  var Time = class {
4512
4564
  #logger;
4513
4565
  #stopper;
4514
4566
  #state;
4567
+ /**
4568
+ * Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
4569
+ */
4515
4570
  get active() {
4516
4571
  return this.#state.started && !this.#state.stopped && enabled;
4517
4572
  }
@@ -4624,6 +4679,9 @@ function sum(array, key) {
4624
4679
  }
4625
4680
  //#endregion
4626
4681
  //#region src/promise/models.ts
4682
+ /**
4683
+ * A promise that can be canceled
4684
+ */
4627
4685
  var CancelablePromise = class extends Promise {
4628
4686
  #rejector;
4629
4687
  constructor(executor) {
@@ -4642,6 +4700,9 @@ var CancelablePromise = class extends Promise {
4642
4700
  this.#rejector(reason);
4643
4701
  }
4644
4702
  };
4703
+ /**
4704
+ * An error thrown when a promise times out
4705
+ */
4645
4706
  var PromiseTimeoutError = class extends Error {
4646
4707
  constructor() {
4647
4708
  super(PROMISE_MESSAGE_TIMEOUT);
@@ -4941,6 +5002,9 @@ const TYPES = new Set([
4941
5002
  ]);
4942
5003
  //#endregion
4943
5004
  //#region src/queue.ts
5005
+ /**
5006
+ * A queue that can be used to manage (a)synchronous tasks with a specific key
5007
+ */
4944
5008
  var KeyedQueue = class {
4945
5009
  #callback;
4946
5010
  #options;
@@ -5090,6 +5154,9 @@ var KeyedQueue = class {
5090
5154
  for (const queue of queues) queue[type]();
5091
5155
  }
5092
5156
  };
5157
+ /**
5158
+ * A queue that can be used to manage (a)synchronous tasks
5159
+ */
5093
5160
  var Queue = class {
5094
5161
  #callback;
5095
5162
  #handled = [];
@@ -5267,6 +5334,9 @@ var Queue = class {
5267
5334
  this.#runners -= 1;
5268
5335
  }
5269
5336
  };
5337
+ /**
5338
+ * An error thrown by the Queue when an operation fails
5339
+ */
5270
5340
  var QueueError = class extends Error {
5271
5341
  constructor(message) {
5272
5342
  super(message);
@@ -5374,6 +5444,25 @@ const BOOLEAN_MODIFIER = .5;
5374
5444
  const HEX_CHARACTERS = "0123456789ABCDEF";
5375
5445
  const HEX_MAXIMUM = 15;
5376
5446
  //#endregion
5447
+ //#region src/result/index.ts
5448
+ async function asyncAttempt(value, err) {
5449
+ try {
5450
+ let result = typeof value === "function" ? value() : await value;
5451
+ if (result instanceof Promise) result = await result;
5452
+ return ok(result);
5453
+ } catch (thrown) {
5454
+ return getError(err ?? thrown, err == null ? void 0 : thrown);
5455
+ }
5456
+ }
5457
+ function attempt(callback, err) {
5458
+ try {
5459
+ return ok(callback());
5460
+ } catch (thrown) {
5461
+ return getError(err ?? thrown, err == null ? void 0 : thrown);
5462
+ }
5463
+ }
5464
+ attempt.async = asyncAttempt;
5465
+ //#endregion
5377
5466
  //#region src/result/match.ts
5378
5467
  async function asyncMatchResult(result, first, error) {
5379
5468
  let value;
@@ -5441,33 +5530,11 @@ function attemptPipe(initial, first, ...seconds) {
5441
5530
  }
5442
5531
  attemptPipe.async = attemptAsyncPipe;
5443
5532
  //#endregion
5444
- //#region src/result/index.ts
5445
- async function asyncAttempt(value, err) {
5446
- try {
5447
- let result = typeof value === "function" ? value() : await value;
5448
- if (result instanceof Promise) result = await result;
5449
- return ok(result);
5450
- } catch (thrown) {
5451
- return getError(err ?? thrown, err == null ? void 0 : thrown);
5452
- }
5453
- }
5454
- function attempt(callback, err) {
5455
- try {
5456
- return ok(callback());
5457
- } catch (thrown) {
5458
- return getError(err ?? thrown, err == null ? void 0 : thrown);
5459
- }
5460
- }
5461
- attempt.async = asyncAttempt;
5462
- attempt.flow = attemptFlow;
5463
- attempt.match = matchResult;
5464
- attempt.pipe = attemptPipe;
5465
- attempt.promise = attemptPromise;
5466
- //#endregion
5467
5533
  //#region src/sized/set.ts
5468
5534
  /**
5469
- * - A Set with a maximum size
5470
- * - Behavior is similar to a _LRU_-cache, where the oldest values are removed
5535
+ * A Set with a maximum size
5536
+ *
5537
+ * Behavior is similar to a _LRU_-cache, where the oldest values are removed
5471
5538
  */
5472
5539
  var SizedSet = class extends Set {
5473
5540
  /**
@@ -5518,4 +5585,4 @@ var SizedSet = class extends Set {
5518
5585
  }
5519
5586
  };
5520
5587
  //#endregion
5521
- 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, 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, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, 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, kalas, 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 };
5588
+ 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, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, 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, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, 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, kalas, 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 };
@@ -1,6 +1,7 @@
1
1
  import { Constructor, GenericCallback } from "../../models.mjs";
2
2
 
3
3
  //#region src/internal/value/compare.d.ts
4
+ type Comparator<Value = any> = (first: Value, second: Value) => number;
4
5
  /**
5
6
  * Compare two values _(for sorting purposes)_
6
7
  * @param first First value
@@ -31,6 +32,6 @@ declare function deregisterComparator<Instance>(constructor: Constructor<Instanc
31
32
  * @param constructor Class constructor
32
33
  * @param handler Method name or comparison function _(defaults to `compare`)_
33
34
  */
34
- declare function registerComparator<Instance>(constructor: Constructor<Instance>, handler?: string | ((first: Instance, second: Instance) => number)): void;
35
+ declare function registerComparator<Instance>(constructor: Constructor<Instance>, handler?: string | Comparator<Instance>): void;
35
36
  //#endregion
36
37
  export { compare, deregisterComparator, registerComparator };
@@ -18,6 +18,11 @@ type EqualOptions = {
18
18
  */
19
19
  relaxedNullish?: boolean;
20
20
  };
21
+ /**
22
+ * An equalizer function for comparing values for equality, with predefined options
23
+ *
24
+ * Can be used to compare values, and register or deregister equality comparison handlers for specific classes
25
+ */
21
26
  type Equalizer = {
22
27
  /**
23
28
  * Are two strings equal?
@@ -1,4 +1,4 @@
1
- import { NestedKeys, NestedValue, PlainObject, ToString } from "../../models.mjs";
1
+ import { NestedKeys, NestedValue, PlainObject } from "../../models.mjs";
2
2
 
3
3
  //#region src/internal/value/get.d.ts
4
4
  /**
@@ -7,7 +7,7 @@ import { NestedKeys, NestedValue, PlainObject, ToString } from "../../models.mjs
7
7
  * @param path Path for value, e.g., `foo.bar.baz`
8
8
  * @returns Found value, or `undefined`
9
9
  */
10
- declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, ToString<Path>>;
10
+ declare function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path): NestedValue<Data, Path>;
11
11
  /**
12
12
  * Get the value from an object using an unknown path
13
13
  * @param data Object to get value from
@@ -29,7 +29,7 @@ declare namespace hasValue {
29
29
  * @param ignoreCase If `true`, the path matching is case-insensitive
30
30
  * @return Result object
31
31
  */
32
- declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, ignoreCase?: boolean): Result<NestedValue<Data, ToString<Path>>, undefined>;
32
+ declare function hasValueResult<Data extends PlainObject, Path extends NestedKeys<Data>>(data: Data, path: Path, ignoreCase?: boolean): Result<NestedValue<Data, ToString<Path>>, string>;
33
33
  /**
34
34
  * Check if a nested property is defined in an object, and get its value if it is
35
35
  *
@@ -39,6 +39,6 @@ declare function hasValueResult<Data extends PlainObject, Path extends NestedKey
39
39
  * @param ignoreCase If `true`, the path matching is case-insensitive
40
40
  * @return Result object
41
41
  */
42
- declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, undefined>;
42
+ declare function hasValueResult<Data extends PlainObject>(data: Data, path: string, ignoreCase?: boolean): Result<unknown, string>;
43
43
  //#endregion
44
- export { hasValue };
44
+ export { hasValue, hasValueResult };
@@ -8,4 +8,4 @@ function hasValueResult(data, path, ignoreCase) {
8
8
  return getNestedValue(data, path, ignoreCase === true);
9
9
  }
10
10
  //#endregion
11
- export { hasValue };
11
+ export { hasValue, hasValueResult };