@oscarpalmer/atoms 0.158.0 → 0.160.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.
- package/dist/array/difference.js +2 -0
- package/dist/array/exists.js +2 -0
- package/dist/array/filter.js +2 -0
- package/dist/array/find.js +2 -0
- package/dist/array/flatten.js +2 -0
- package/dist/array/from.js +2 -0
- package/dist/array/get.js +2 -0
- package/dist/array/group-by.js +2 -0
- package/dist/array/index-of.js +2 -0
- package/dist/array/index.js +2 -1
- package/dist/array/insert.js +2 -0
- package/dist/array/intersection.js +2 -0
- package/dist/array/partition.js +2 -0
- package/dist/array/position.js +58 -0
- package/dist/array/push.js +2 -0
- package/dist/array/select.js +2 -0
- package/dist/array/slice.js +2 -0
- package/dist/array/sort.js +2 -0
- package/dist/array/splice.js +2 -0
- package/dist/array/to-map.js +2 -0
- package/dist/array/to-record.js +2 -0
- package/dist/array/to-set.js +2 -0
- package/dist/array/toggle.js +2 -0
- package/dist/array/union.js +2 -0
- package/dist/array/unique.js +2 -0
- package/dist/array/update.js +2 -0
- package/dist/atoms.full.js +223 -162
- package/dist/beacon.js +2 -0
- package/dist/color/constants.js +35 -33
- package/dist/color/index.js +2 -0
- package/dist/color/instance.js +2 -0
- package/dist/color/misc/alpha.js +2 -0
- package/dist/color/misc/get.js +2 -0
- package/dist/color/misc/index.js +2 -0
- package/dist/color/misc/is.js +2 -0
- package/dist/color/misc/state.js +2 -0
- package/dist/color/space/hex.js +2 -0
- package/dist/color/space/hsl.js +2 -0
- package/dist/color/space/rgb.js +2 -0
- package/dist/function/assert.js +2 -0
- package/dist/function/index.js +2 -0
- package/dist/function/memoize.js +2 -0
- package/dist/function/once.js +2 -0
- package/dist/function/retry.js +2 -0
- package/dist/function/work.js +2 -0
- package/dist/index.js +5 -4
- package/dist/internal/array/callbacks.js +2 -0
- package/dist/internal/array/chunk.js +2 -0
- package/dist/internal/array/compact.js +2 -0
- package/dist/internal/array/find.js +6 -4
- package/dist/internal/array/group.js +2 -0
- package/dist/internal/array/insert.js +2 -0
- package/dist/internal/array/sets.js +8 -6
- package/dist/internal/array/shuffle.js +3 -1
- package/dist/internal/array/update.js +2 -0
- package/dist/internal/function/misc.js +2 -0
- package/dist/internal/function/timer.js +5 -3
- package/dist/internal/is.js +2 -0
- package/dist/internal/math/aggregate.js +2 -0
- package/dist/internal/number.js +2 -0
- package/dist/internal/random.js +2 -0
- package/dist/internal/result.js +2 -0
- package/dist/internal/sized.js +2 -0
- package/dist/internal/string.js +2 -0
- package/dist/internal/value/compare.js +2 -0
- package/dist/internal/value/equal.js +2 -0
- package/dist/internal/value/get.js +2 -0
- package/dist/internal/value/handlers.js +2 -0
- package/dist/internal/value/has.js +2 -0
- package/dist/internal/value/misc.js +2 -0
- package/dist/internal/value/partial.js +2 -0
- package/dist/internal/value/set.js +2 -0
- package/dist/is.js +2 -0
- package/dist/logger.js +2 -0
- package/dist/math.js +2 -0
- package/dist/promise/delay.js +3 -1
- package/dist/promise/helpers.js +8 -1
- package/dist/promise/index.js +9 -3
- package/dist/promise/misc.js +3 -1
- package/dist/promise/models.js +14 -12
- package/dist/promise/timed.js +3 -1
- package/dist/query.js +2 -0
- package/dist/queue.js +2 -0
- package/dist/random.js +2 -0
- package/dist/result/index.js +5 -3
- package/dist/result/match.js +2 -0
- package/dist/result/misc.js +2 -0
- package/dist/result/work/flow.js +2 -0
- package/dist/result/work/pipe.js +2 -0
- package/dist/sized/map.js +2 -0
- package/dist/sized/set.js +2 -0
- package/dist/string/case.js +2 -0
- package/dist/string/index.js +2 -0
- package/dist/string/match.js +2 -0
- package/dist/string/template.js +2 -0
- package/dist/value/clone.js +3 -1
- package/dist/value/diff.js +2 -0
- package/dist/value/merge.js +2 -0
- package/dist/value/omit.js +2 -0
- package/dist/value/pick.js +2 -0
- package/dist/value/smush.js +3 -1
- package/dist/value/unsmush.js +3 -1
- package/package.json +3 -3
- package/src/array/index.ts +1 -0
- package/src/array/position.ts +303 -0
- package/src/internal/array/sets.ts +3 -3
- package/src/internal/array/shuffle.ts +1 -1
- package/src/promise/helpers.ts +13 -3
- package/src/promise/index.ts +89 -19
- package/src/promise/misc.ts +1 -4
- package/src/promise/models.ts +18 -12
- package/src/value/clone.ts +1 -1
- package/src/value/smush.ts +1 -1
- package/src/value/unsmush.ts +1 -1
- package/types/array/index.d.ts +1 -0
- package/types/array/position.d.ts +117 -0
- package/types/promise/helpers.d.ts +3 -1
- package/types/promise/index.d.ts +52 -5
- package/types/promise/misc.d.ts +1 -1
- package/types/promise/models.d.ts +15 -11
package/dist/atoms.full.js
CHANGED
|
@@ -175,7 +175,7 @@ function getRandomInteger(minimum, maximum) {
|
|
|
175
175
|
*/
|
|
176
176
|
function shuffle(array) {
|
|
177
177
|
if (!Array.isArray(array)) return [];
|
|
178
|
-
const shuffled =
|
|
178
|
+
const shuffled = array.slice();
|
|
179
179
|
if (shuffled.length < 2) return shuffled;
|
|
180
180
|
let index = Number(shuffled.length);
|
|
181
181
|
while (--index >= 0) {
|
|
@@ -189,8 +189,8 @@ function compareSets(type, first, second, key) {
|
|
|
189
189
|
const isDifference = type === COMPARE_SETS_DIFFERENCE;
|
|
190
190
|
const isIntersection = type === COMPARE_SETS_INTERSECTION;
|
|
191
191
|
const isUnion = type === COMPARE_SETS_UNION;
|
|
192
|
-
if (first.length === 0) return isDifference ?
|
|
193
|
-
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] :
|
|
192
|
+
if (first.length === 0) return isDifference ? first.slice() : isIntersection ? [] : second.slice();
|
|
193
|
+
if (!Array.isArray(second) || second.length === 0) return isIntersection ? [] : first.slice();
|
|
194
194
|
const callback = getArrayCallback(key);
|
|
195
195
|
const values = isUnion ? first : second;
|
|
196
196
|
let { length } = values;
|
|
@@ -201,7 +201,7 @@ function compareSets(type, first, second, key) {
|
|
|
201
201
|
}
|
|
202
202
|
const source = isUnion ? second : first;
|
|
203
203
|
length = source.length;
|
|
204
|
-
const result = isUnion ?
|
|
204
|
+
const result = isUnion ? first.slice() : [];
|
|
205
205
|
for (let index = 0; index < length; index += 1) {
|
|
206
206
|
const item = source[index];
|
|
207
207
|
const value = callback?.(item, index, source) ?? item;
|
|
@@ -368,6 +368,60 @@ function partition(array, ...parameters) {
|
|
|
368
368
|
const { matched, notMatched } = findValues("all", array, parameters);
|
|
369
369
|
return [matched, notMatched];
|
|
370
370
|
}
|
|
371
|
+
function endsWithArray(haystack, needle, key) {
|
|
372
|
+
return endings.has(getPosition(haystack, needle, key)[1]);
|
|
373
|
+
}
|
|
374
|
+
function getArrayPosition(haystack, needle, key) {
|
|
375
|
+
return getPosition(haystack, needle, key)[1];
|
|
376
|
+
}
|
|
377
|
+
function getName(start, haystack, needle) {
|
|
378
|
+
if (start === 0) return haystack === needle ? POSITION_SAME : POSITION_START;
|
|
379
|
+
return start + needle === haystack ? POSITION_END : POSITION_INSIDE;
|
|
380
|
+
}
|
|
381
|
+
function getPosition(haystack, needle, key) {
|
|
382
|
+
if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
|
|
383
|
+
const haystackLength = haystack.length;
|
|
384
|
+
const needleLength = needle.length;
|
|
385
|
+
if (haystackLength === 0 || needleLength === 0) return outside;
|
|
386
|
+
if (needleLength > haystackLength) return outside;
|
|
387
|
+
const callback = getArrayCallback(key);
|
|
388
|
+
const limit = haystackLength - needleLength + 1;
|
|
389
|
+
let needleValues = callback == null ? needle : needle.slice();
|
|
390
|
+
if (callback != null) for (let needleIndex = 0; needleIndex < needleLength; needleIndex += 1) needleValues[needleIndex] = callback(needle[needleIndex], needleIndex, needle);
|
|
391
|
+
for (let haystackIndex = 0; haystackIndex < limit; haystackIndex += 1) {
|
|
392
|
+
let haystackItem = haystack[haystackIndex];
|
|
393
|
+
let haystackValue = callback?.(haystackItem, haystackIndex, haystack) ?? haystackItem;
|
|
394
|
+
if (!Object.is(haystackValue, needleValues[0])) continue;
|
|
395
|
+
if (needleLength === 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
396
|
+
for (let needleIndex = 1; needleIndex < needleLength; needleIndex += 1) {
|
|
397
|
+
haystackItem = haystack[haystackIndex + needleIndex];
|
|
398
|
+
haystackValue = callback?.(haystackItem, haystackIndex + needleIndex, haystack) ?? haystackItem;
|
|
399
|
+
if (!Object.is(haystackValue, needleValues[needleIndex])) break;
|
|
400
|
+
if (needleIndex === needleLength - 1) return [haystackIndex, getName(haystackIndex, haystackLength, needleLength)];
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return outside;
|
|
404
|
+
}
|
|
405
|
+
function includesArray(haystack, needle, key) {
|
|
406
|
+
return !outsides.has(getPosition(haystack, needle, key)[1]);
|
|
407
|
+
}
|
|
408
|
+
function indexOfArray(haystack, needle, key) {
|
|
409
|
+
return getPosition(haystack, needle, key)[0];
|
|
410
|
+
}
|
|
411
|
+
function startsWithArray(haystack, needle, key) {
|
|
412
|
+
return starts.has(getPosition(haystack, needle, key)[1]);
|
|
413
|
+
}
|
|
414
|
+
const POSITION_END = "end";
|
|
415
|
+
const POSITION_INSIDE = "inside";
|
|
416
|
+
const POSITION_INVALID = "invalid";
|
|
417
|
+
const POSITION_OUTSIDE = "outside";
|
|
418
|
+
const POSITION_SAME = "same";
|
|
419
|
+
const POSITION_START = "start";
|
|
420
|
+
const endings = new Set([POSITION_END, POSITION_SAME]);
|
|
421
|
+
const invalid = [-1, POSITION_INVALID];
|
|
422
|
+
const outside = [-1, POSITION_OUTSIDE];
|
|
423
|
+
const outsides = new Set([POSITION_INVALID, POSITION_OUTSIDE]);
|
|
424
|
+
const starts = new Set([POSITION_START, POSITION_SAME]);
|
|
371
425
|
/**
|
|
372
426
|
* Push items into an array _(at the end)_
|
|
373
427
|
* @param array Original array
|
|
@@ -1906,7 +1960,7 @@ function cloneNode(node, depth, references) {
|
|
|
1906
1960
|
return cloned;
|
|
1907
1961
|
}
|
|
1908
1962
|
function clonePlainObject(value, depth, references) {
|
|
1909
|
-
if (depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ?
|
|
1963
|
+
if (depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
|
|
1910
1964
|
const cloned = Array.isArray(value) ? [] : {};
|
|
1911
1965
|
const keys = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)];
|
|
1912
1966
|
const { length } = keys;
|
|
@@ -2102,7 +2156,7 @@ function flattenObject(value, depth, smushed, prefix) {
|
|
|
2102
2156
|
const val = value[key];
|
|
2103
2157
|
if (isArrayOrPlainObject(val)) {
|
|
2104
2158
|
const prefixedKey = join([prefix, key], ".");
|
|
2105
|
-
flattened[prefixedKey] = Array.isArray(val) ?
|
|
2159
|
+
flattened[prefixedKey] = Array.isArray(val) ? val.slice() : { ...val };
|
|
2106
2160
|
const nested = flattenObject(val, depth + 1, smushed, prefixedKey);
|
|
2107
2161
|
const nestedKeys = Object.keys(nested);
|
|
2108
2162
|
const nestedLength = nestedKeys.length;
|
|
@@ -2151,7 +2205,7 @@ function unsmush(value) {
|
|
|
2151
2205
|
const key = keys[index].value;
|
|
2152
2206
|
const val = value[key];
|
|
2153
2207
|
let next = val;
|
|
2154
|
-
if (isArrayOrPlainObject(val)) next = Array.isArray(val) ?
|
|
2208
|
+
if (isArrayOrPlainObject(val)) next = Array.isArray(val) ? val.slice() : { ...val };
|
|
2155
2209
|
setValue(unsmushed, key, next);
|
|
2156
2210
|
}
|
|
2157
2211
|
return unsmushed;
|
|
@@ -3275,6 +3329,105 @@ function roundNumber(callback, value, decimals) {
|
|
|
3275
3329
|
function sum(array, key) {
|
|
3276
3330
|
return getAggregated("sum", array, key);
|
|
3277
3331
|
}
|
|
3332
|
+
async function asyncMatchResult(result, first, error) {
|
|
3333
|
+
let value;
|
|
3334
|
+
if (typeof result === "function") value = await result();
|
|
3335
|
+
else if (result instanceof Promise) value = await result;
|
|
3336
|
+
else value = result;
|
|
3337
|
+
if (!isResult(value)) throw new Error(MESSAGE_RESULT);
|
|
3338
|
+
const hasObj = typeof first === "object" && first !== null;
|
|
3339
|
+
const okHandler = hasObj ? first.ok : first;
|
|
3340
|
+
const errorHandler = hasObj ? first.error : error;
|
|
3341
|
+
if (isOk(value)) return okHandler(value.value);
|
|
3342
|
+
return errorHandler(value.error, value.original);
|
|
3343
|
+
}
|
|
3344
|
+
function matchResult(result, first, error) {
|
|
3345
|
+
const value = typeof result === "function" ? result() : result;
|
|
3346
|
+
if (!isResult(value)) throw new Error(MESSAGE_RESULT);
|
|
3347
|
+
const hasObj = typeof first === "object" && first !== null;
|
|
3348
|
+
const okHandler = hasObj ? first.ok : first;
|
|
3349
|
+
const errorHandler = hasObj ? first.error : error;
|
|
3350
|
+
if (isOk(value)) return okHandler(value.value);
|
|
3351
|
+
return errorHandler(value.error, value.original);
|
|
3352
|
+
}
|
|
3353
|
+
matchResult.async = asyncMatchResult;
|
|
3354
|
+
const MESSAGE_RESULT = "`result.match` expected a Result or a function that returns a Result";
|
|
3355
|
+
function error(value, original) {
|
|
3356
|
+
return getError(value, original);
|
|
3357
|
+
}
|
|
3358
|
+
function getError(value, original) {
|
|
3359
|
+
const errorResult = {
|
|
3360
|
+
error: value,
|
|
3361
|
+
ok: false
|
|
3362
|
+
};
|
|
3363
|
+
if (original instanceof Error) errorResult.original = original;
|
|
3364
|
+
return errorResult;
|
|
3365
|
+
}
|
|
3366
|
+
/**
|
|
3367
|
+
* Creates an ok result
|
|
3368
|
+
* @param value Value
|
|
3369
|
+
* @returns Ok result
|
|
3370
|
+
*/
|
|
3371
|
+
function ok(value) {
|
|
3372
|
+
return {
|
|
3373
|
+
ok: true,
|
|
3374
|
+
value
|
|
3375
|
+
};
|
|
3376
|
+
}
|
|
3377
|
+
/**
|
|
3378
|
+
* Converts a result to a promise
|
|
3379
|
+
*
|
|
3380
|
+
* Resolves if ok, rejects for error
|
|
3381
|
+
* @param result Result to convert
|
|
3382
|
+
* @returns Promised result
|
|
3383
|
+
*/
|
|
3384
|
+
async function toPromise(result) {
|
|
3385
|
+
const actual = typeof result === "function" ? result() : result;
|
|
3386
|
+
if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
|
|
3387
|
+
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
3388
|
+
}
|
|
3389
|
+
function unwrap(value, defaultValue) {
|
|
3390
|
+
return isOk(value) ? value.value : defaultValue;
|
|
3391
|
+
}
|
|
3392
|
+
const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
|
|
3393
|
+
function attemptAsyncFlow(...fns) {
|
|
3394
|
+
let Flow;
|
|
3395
|
+
return (...args) => attempt.async(() => {
|
|
3396
|
+
Flow ??= flow.async(...fns);
|
|
3397
|
+
return Flow(...args.map((value) => {
|
|
3398
|
+
if (isError(value)) throw value.error;
|
|
3399
|
+
return isOk(value) ? value.value : value;
|
|
3400
|
+
}));
|
|
3401
|
+
});
|
|
3402
|
+
}
|
|
3403
|
+
function attemptFlow(...fns) {
|
|
3404
|
+
let Flow;
|
|
3405
|
+
return (...args) => attempt(() => {
|
|
3406
|
+
Flow ??= flow(...fns);
|
|
3407
|
+
return Flow(...args.map((value) => {
|
|
3408
|
+
if (isError(value)) throw value.error;
|
|
3409
|
+
return isOk(value) ? value.value : value;
|
|
3410
|
+
}));
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
3413
|
+
attemptFlow.async = attemptAsyncFlow;
|
|
3414
|
+
async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
3415
|
+
return attempt.async(() => {
|
|
3416
|
+
if (isError(initial)) throw initial.error;
|
|
3417
|
+
const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
|
|
3418
|
+
if (first == null) return value;
|
|
3419
|
+
return pipe.async(value, ...[first, ...seconds]);
|
|
3420
|
+
});
|
|
3421
|
+
}
|
|
3422
|
+
function attemptPipe(initial, first, ...seconds) {
|
|
3423
|
+
return attempt(() => {
|
|
3424
|
+
if (isError(initial)) throw initial.error;
|
|
3425
|
+
const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
|
|
3426
|
+
if (first == null) return value;
|
|
3427
|
+
return pipe(value, ...[first, ...seconds]);
|
|
3428
|
+
});
|
|
3429
|
+
}
|
|
3430
|
+
attemptPipe.async = attemptAsyncPipe;
|
|
3278
3431
|
var CancelablePromise = class extends Promise {
|
|
3279
3432
|
#rejector;
|
|
3280
3433
|
constructor(executor) {
|
|
@@ -3311,6 +3464,60 @@ const PROMISE_STRATEGY_ALL = new Set(["complete", "first"]);
|
|
|
3311
3464
|
const PROMISE_STRATEGY_DEFAULT = "complete";
|
|
3312
3465
|
const PROMISE_TYPE_FULFILLED = "fulfilled";
|
|
3313
3466
|
const PROMISE_TYPE_REJECTED = "rejected";
|
|
3467
|
+
/**
|
|
3468
|
+
* Create a cancelable promise
|
|
3469
|
+
* @param executor Executor function for the promise
|
|
3470
|
+
* @returns Cancelable promise
|
|
3471
|
+
*/
|
|
3472
|
+
function cancelable(executor) {
|
|
3473
|
+
return new CancelablePromise(executor);
|
|
3474
|
+
}
|
|
3475
|
+
function handleResult(status, parameters) {
|
|
3476
|
+
const { abort, complete, data, handlers, index, signal, value } = parameters;
|
|
3477
|
+
if (signal?.aborted ?? false) return;
|
|
3478
|
+
if (!complete && status === "rejected") {
|
|
3479
|
+
settlePromise(abort, handlers.reject, value, signal);
|
|
3480
|
+
return;
|
|
3481
|
+
}
|
|
3482
|
+
data.result[index] = !complete ? value : status === "fulfilled" ? {
|
|
3483
|
+
status,
|
|
3484
|
+
value
|
|
3485
|
+
} : {
|
|
3486
|
+
status,
|
|
3487
|
+
reason: value
|
|
3488
|
+
};
|
|
3489
|
+
if (index === data.last) settlePromise(abort, handlers.resolve, data.result, signal);
|
|
3490
|
+
}
|
|
3491
|
+
function settlePromise(aborter, settler, value, signal) {
|
|
3492
|
+
signal?.removeEventListener(PROMISE_EVENT_NAME, aborter);
|
|
3493
|
+
settler(value);
|
|
3494
|
+
}
|
|
3495
|
+
async function toResult(value) {
|
|
3496
|
+
const actual = typeof value === "function" ? value() : value;
|
|
3497
|
+
if (!(actual instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT));
|
|
3498
|
+
return actual.then((result) => ok(result)).catch((reason) => error(reason));
|
|
3499
|
+
}
|
|
3500
|
+
async function asyncAttempt(value, err) {
|
|
3501
|
+
try {
|
|
3502
|
+
let result = typeof value === "function" ? value() : await value;
|
|
3503
|
+
if (result instanceof Promise) result = await result;
|
|
3504
|
+
return ok(result);
|
|
3505
|
+
} catch (thrown) {
|
|
3506
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
function attempt(callback, err) {
|
|
3510
|
+
try {
|
|
3511
|
+
return ok(callback());
|
|
3512
|
+
} catch (thrown) {
|
|
3513
|
+
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
attempt.async = asyncAttempt;
|
|
3517
|
+
attempt.flow = attemptFlow;
|
|
3518
|
+
attempt.match = matchResult;
|
|
3519
|
+
attempt.pipe = attemptPipe;
|
|
3520
|
+
attempt.promise = attemptPromise;
|
|
3314
3521
|
function getNumberOrDefault$1(value) {
|
|
3315
3522
|
return typeof value === "number" && value > 0 ? value : 0;
|
|
3316
3523
|
}
|
|
@@ -3338,6 +3545,9 @@ function getPromisesOptions(input) {
|
|
|
3338
3545
|
strategy: getStrategyOrDefault(options.strategy)
|
|
3339
3546
|
};
|
|
3340
3547
|
}
|
|
3548
|
+
function getResultsFromPromises(promised) {
|
|
3549
|
+
return promised.map((result) => isFulfilled(result) ? ok(result.value) : error(result.reason));
|
|
3550
|
+
}
|
|
3341
3551
|
function getStrategyOrDefault(value) {
|
|
3342
3552
|
return PROMISE_STRATEGY_ALL.has(value) ? value : PROMISE_STRATEGY_DEFAULT;
|
|
3343
3553
|
}
|
|
@@ -3360,77 +3570,6 @@ function isRejected(value) {
|
|
|
3360
3570
|
function isType(value, type) {
|
|
3361
3571
|
return typeof value === "object" && value !== null && value.status === type;
|
|
3362
3572
|
}
|
|
3363
|
-
function error(value, original) {
|
|
3364
|
-
return getError(value, original);
|
|
3365
|
-
}
|
|
3366
|
-
function getError(value, original) {
|
|
3367
|
-
const errorResult = {
|
|
3368
|
-
error: value,
|
|
3369
|
-
ok: false
|
|
3370
|
-
};
|
|
3371
|
-
if (original instanceof Error) errorResult.original = original;
|
|
3372
|
-
return errorResult;
|
|
3373
|
-
}
|
|
3374
|
-
/**
|
|
3375
|
-
* Creates an ok result
|
|
3376
|
-
* @param value Value
|
|
3377
|
-
* @returns Ok result
|
|
3378
|
-
*/
|
|
3379
|
-
function ok(value) {
|
|
3380
|
-
return {
|
|
3381
|
-
ok: true,
|
|
3382
|
-
value
|
|
3383
|
-
};
|
|
3384
|
-
}
|
|
3385
|
-
/**
|
|
3386
|
-
* Converts a result to a promise
|
|
3387
|
-
*
|
|
3388
|
-
* Resolves if ok, rejects for error
|
|
3389
|
-
* @param result Result to convert
|
|
3390
|
-
* @returns Promised result
|
|
3391
|
-
*/
|
|
3392
|
-
async function toPromise(result) {
|
|
3393
|
-
const actual = typeof result === "function" ? result() : result;
|
|
3394
|
-
if (!isResult(actual)) return Promise.reject(new Error(MESSAGE_PROMISE_RESULT));
|
|
3395
|
-
return isOk(actual) ? Promise.resolve(actual.value) : Promise.reject(actual.error);
|
|
3396
|
-
}
|
|
3397
|
-
function unwrap(value, defaultValue) {
|
|
3398
|
-
return isOk(value) ? value.value : defaultValue;
|
|
3399
|
-
}
|
|
3400
|
-
const MESSAGE_PROMISE_RESULT = "toPromise expected to receive a Result";
|
|
3401
|
-
/**
|
|
3402
|
-
* Create a cancelable promise
|
|
3403
|
-
* @param executor Executor function for the promise
|
|
3404
|
-
* @returns Cancelable promise
|
|
3405
|
-
*/
|
|
3406
|
-
function cancelable(executor) {
|
|
3407
|
-
return new CancelablePromise(executor);
|
|
3408
|
-
}
|
|
3409
|
-
function handleResult(status, parameters) {
|
|
3410
|
-
const { abort, complete, data, handlers, index, signal, value } = parameters;
|
|
3411
|
-
if (signal?.aborted ?? false) return;
|
|
3412
|
-
if (!complete && status === "rejected") {
|
|
3413
|
-
settlePromise(abort, handlers.reject, value, signal);
|
|
3414
|
-
return;
|
|
3415
|
-
}
|
|
3416
|
-
data.result[index] = !complete ? value : status === "fulfilled" ? {
|
|
3417
|
-
status,
|
|
3418
|
-
value
|
|
3419
|
-
} : {
|
|
3420
|
-
status,
|
|
3421
|
-
reason: value
|
|
3422
|
-
};
|
|
3423
|
-
if (index === data.last) settlePromise(abort, handlers.resolve, data.result, signal);
|
|
3424
|
-
}
|
|
3425
|
-
function settlePromise(aborter, settler, value, signal) {
|
|
3426
|
-
signal?.removeEventListener(PROMISE_EVENT_NAME, aborter);
|
|
3427
|
-
settler(value);
|
|
3428
|
-
}
|
|
3429
|
-
async function toResult(value) {
|
|
3430
|
-
const actual = typeof value === "function" ? value() : value;
|
|
3431
|
-
if (!(actual instanceof Promise)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_RESULT));
|
|
3432
|
-
return actual.then((result) => ok(result)).catch((reason) => error(reason));
|
|
3433
|
-
}
|
|
3434
3573
|
async function getTimedPromise(promise, time, signal) {
|
|
3435
3574
|
function abort() {
|
|
3436
3575
|
timer.cancel();
|
|
@@ -3507,7 +3646,7 @@ async function promises(items, options) {
|
|
|
3507
3646
|
if (!Array.isArray(items)) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_PROMISES));
|
|
3508
3647
|
const actual = items.filter((item) => item instanceof Promise);
|
|
3509
3648
|
const { length } = actual;
|
|
3510
|
-
if (length === 0) return
|
|
3649
|
+
if (length === 0) return Promise.reject(new TypeError(PROMISE_MESSAGE_EXPECTATION_PROMISES));
|
|
3511
3650
|
const complete = strategy === PROMISE_STRATEGY_DEFAULT;
|
|
3512
3651
|
function abort() {
|
|
3513
3652
|
handlers.reject(signal.reason);
|
|
@@ -3542,6 +3681,10 @@ async function promises(items, options) {
|
|
|
3542
3681
|
}));
|
|
3543
3682
|
});
|
|
3544
3683
|
}
|
|
3684
|
+
promises.result = resultPromises;
|
|
3685
|
+
async function resultPromises(items, signal) {
|
|
3686
|
+
return promises(items, signal).then(getResultsFromPromises);
|
|
3687
|
+
}
|
|
3545
3688
|
/**
|
|
3546
3689
|
* Convert a query string to a plain _(nested)_ object
|
|
3547
3690
|
* @param query Query string to convert
|
|
@@ -3869,88 +4012,6 @@ const ALPHABET = "abcdefghijklmnopqrstuvwxyz";
|
|
|
3869
4012
|
const BOOLEAN_MODIFIER = .5;
|
|
3870
4013
|
const HEX_CHARACTERS = "0123456789ABCDEF";
|
|
3871
4014
|
const HEX_MAXIMUM = 15;
|
|
3872
|
-
async function asyncMatchResult(result, first, error) {
|
|
3873
|
-
let value;
|
|
3874
|
-
if (typeof result === "function") value = await result();
|
|
3875
|
-
else if (result instanceof Promise) value = await result;
|
|
3876
|
-
else value = result;
|
|
3877
|
-
if (!isResult(value)) throw new Error(MESSAGE_RESULT);
|
|
3878
|
-
const hasObj = typeof first === "object" && first !== null;
|
|
3879
|
-
const okHandler = hasObj ? first.ok : first;
|
|
3880
|
-
const errorHandler = hasObj ? first.error : error;
|
|
3881
|
-
if (isOk(value)) return okHandler(value.value);
|
|
3882
|
-
return errorHandler(value.error, value.original);
|
|
3883
|
-
}
|
|
3884
|
-
function matchResult(result, first, error) {
|
|
3885
|
-
const value = typeof result === "function" ? result() : result;
|
|
3886
|
-
if (!isResult(value)) throw new Error(MESSAGE_RESULT);
|
|
3887
|
-
const hasObj = typeof first === "object" && first !== null;
|
|
3888
|
-
const okHandler = hasObj ? first.ok : first;
|
|
3889
|
-
const errorHandler = hasObj ? first.error : error;
|
|
3890
|
-
if (isOk(value)) return okHandler(value.value);
|
|
3891
|
-
return errorHandler(value.error, value.original);
|
|
3892
|
-
}
|
|
3893
|
-
matchResult.async = asyncMatchResult;
|
|
3894
|
-
const MESSAGE_RESULT = "`result.match` expected a Result or a function that returns a Result";
|
|
3895
|
-
function attemptAsyncFlow(...fns) {
|
|
3896
|
-
let Flow;
|
|
3897
|
-
return (...args) => attempt.async(() => {
|
|
3898
|
-
Flow ??= flow.async(...fns);
|
|
3899
|
-
return Flow(...args.map((value) => {
|
|
3900
|
-
if (isError(value)) throw value.error;
|
|
3901
|
-
return isOk(value) ? value.value : value;
|
|
3902
|
-
}));
|
|
3903
|
-
});
|
|
3904
|
-
}
|
|
3905
|
-
function attemptFlow(...fns) {
|
|
3906
|
-
let Flow;
|
|
3907
|
-
return (...args) => attempt(() => {
|
|
3908
|
-
Flow ??= flow(...fns);
|
|
3909
|
-
return Flow(...args.map((value) => {
|
|
3910
|
-
if (isError(value)) throw value.error;
|
|
3911
|
-
return isOk(value) ? value.value : value;
|
|
3912
|
-
}));
|
|
3913
|
-
});
|
|
3914
|
-
}
|
|
3915
|
-
attemptFlow.async = attemptAsyncFlow;
|
|
3916
|
-
async function attemptAsyncPipe(initial, first, ...seconds) {
|
|
3917
|
-
return attempt.async(() => {
|
|
3918
|
-
if (isError(initial)) throw initial.error;
|
|
3919
|
-
const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
|
|
3920
|
-
if (first == null) return value;
|
|
3921
|
-
return pipe.async(value, ...[first, ...seconds]);
|
|
3922
|
-
});
|
|
3923
|
-
}
|
|
3924
|
-
function attemptPipe(initial, first, ...seconds) {
|
|
3925
|
-
return attempt(() => {
|
|
3926
|
-
if (isError(initial)) throw initial.error;
|
|
3927
|
-
const value = typeof initial === "function" ? initial() : isOk(initial) ? initial.value : initial;
|
|
3928
|
-
if (first == null) return value;
|
|
3929
|
-
return pipe(value, ...[first, ...seconds]);
|
|
3930
|
-
});
|
|
3931
|
-
}
|
|
3932
|
-
attemptPipe.async = attemptAsyncPipe;
|
|
3933
|
-
async function asyncAttempt(value, err) {
|
|
3934
|
-
try {
|
|
3935
|
-
let result = typeof value === "function" ? value() : await value;
|
|
3936
|
-
if (result instanceof Promise) result = await result;
|
|
3937
|
-
return ok(result);
|
|
3938
|
-
} catch (thrown) {
|
|
3939
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
3940
|
-
}
|
|
3941
|
-
}
|
|
3942
|
-
function attempt(callback, err) {
|
|
3943
|
-
try {
|
|
3944
|
-
return ok(callback());
|
|
3945
|
-
} catch (thrown) {
|
|
3946
|
-
return getError(err ?? thrown, err == null ? void 0 : thrown);
|
|
3947
|
-
}
|
|
3948
|
-
}
|
|
3949
|
-
attempt.async = asyncAttempt;
|
|
3950
|
-
attempt.flow = attemptFlow;
|
|
3951
|
-
attempt.match = matchResult;
|
|
3952
|
-
attempt.pipe = attemptPipe;
|
|
3953
|
-
attempt.promise = attemptPromise;
|
|
3954
4015
|
/**
|
|
3955
4016
|
* - A Set with a maximum size
|
|
3956
4017
|
* - Behavior is similar to a _LRU_-cache, where the oldest values are removed
|
|
@@ -4003,4 +4064,4 @@ var SizedSet = class extends Set {
|
|
|
4003
4064
|
}
|
|
4004
4065
|
}
|
|
4005
4066
|
};
|
|
4006
|
-
export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, sum, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
4067
|
+
export { CancelablePromise, PromiseTimeoutError, QueueError, RetryError, SizedMap, SizedSet, attempt, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, flatten, floor, flow, toResult as fromPromise, toResult, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, includesArray, indexOf, indexOfArray, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, median, memoize, merge, min, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, shuffle, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/beacon.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isPlainObject } from "./internal/is.js";
|
|
2
2
|
import { noop } from "./internal/function/misc.js";
|
|
3
|
+
//#region src/beacon.ts
|
|
3
4
|
var Beacon = class {
|
|
4
5
|
#options;
|
|
5
6
|
#state;
|
|
@@ -170,4 +171,5 @@ function getObserver(first, second, third) {
|
|
|
170
171
|
}
|
|
171
172
|
var MESSAGE_BEACON = "Cannot retrieve observable from a destroyed beacon";
|
|
172
173
|
var MESSAGE_OBSERVABLE = "Cannot subscribe to a destroyed observable";
|
|
174
|
+
//#endregion
|
|
173
175
|
export { beacon };
|
package/dist/color/constants.js
CHANGED
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region src/color/constants.ts
|
|
2
|
+
var ALPHA_FULL_HEX_SHORT = "f";
|
|
3
|
+
var ALPHA_FULL_HEX_LONG = `ff`;
|
|
4
|
+
var ALPHA_FULL_VALUE = 1;
|
|
5
|
+
var ALPHA_NONE_HEX = "00";
|
|
6
|
+
var ALPHA_NONE_VALUE = 0;
|
|
7
|
+
var DEFAULT_ALPHA = {
|
|
7
8
|
hex: ALPHA_FULL_HEX_LONG,
|
|
8
9
|
value: 1
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
var DEFAULT_HSL = {
|
|
11
12
|
hue: 0,
|
|
12
13
|
lightness: 0,
|
|
13
14
|
saturation: 0
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
var DEFAULT_RGB = {
|
|
16
17
|
blue: 0,
|
|
17
18
|
green: 0,
|
|
18
19
|
red: 0
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
var EXPRESSION_HEX_LONG = /^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?$/i;
|
|
22
|
+
var EXPRESSION_HEX_SHORT = /^#?([a-f0-9]{3,4})$/i;
|
|
23
|
+
var EXPRESSION_PREFIX = /^#/;
|
|
24
|
+
var HEX_BLACK = "000000";
|
|
25
|
+
var HEX_WHITE = "ffffff";
|
|
26
|
+
var LENGTH_LONG = 6;
|
|
27
|
+
var LENGTH_SHORT = 3;
|
|
28
|
+
var KEYS_HSL = [
|
|
28
29
|
"hue",
|
|
29
30
|
"saturation",
|
|
30
31
|
"lightness"
|
|
31
32
|
];
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
var KEYS_HSLA = [...KEYS_HSL, "alpha"];
|
|
34
|
+
var KEYS_RGB = [
|
|
34
35
|
"red",
|
|
35
36
|
"green",
|
|
36
37
|
"blue"
|
|
37
38
|
];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
var KEYS_RGBA = [...KEYS_RGB, "alpha"];
|
|
40
|
+
var MAX_DEGREE = 360;
|
|
41
|
+
var MAX_HEX = 255;
|
|
42
|
+
var MAX_PERCENT = 100;
|
|
43
|
+
var SPACE_HSL = "hsl";
|
|
44
|
+
var SPACE_RGB = "rgb";
|
|
45
|
+
var SRGB_LUMINANCE_BLUE = .0722;
|
|
46
|
+
var SRGB_LUMINANCE_EXPONENT = 2.4;
|
|
47
|
+
var SRGB_LUMINANCE_GREEN = .7152;
|
|
48
|
+
var SRGB_LUMINANCE_MINIMUM = .03928;
|
|
49
|
+
var SRGB_LUMINANCE_MODIFIER = 1.055;
|
|
50
|
+
var SRGB_LUMINANCE_MULTIPLIER = 12.92;
|
|
51
|
+
var SRGB_LUMINANCE_OFFSET = .055;
|
|
52
|
+
var SRGB_LUMINANCE_RED = .2126;
|
|
53
|
+
var SRGB_LUMINANCE_THRESHOLD = .625;
|
|
54
|
+
//#endregion
|
|
53
55
|
export { ALPHA_FULL_HEX_LONG, ALPHA_FULL_HEX_SHORT, ALPHA_FULL_VALUE, ALPHA_NONE_HEX, ALPHA_NONE_VALUE, DEFAULT_ALPHA, DEFAULT_HSL, DEFAULT_RGB, EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, EXPRESSION_PREFIX, HEX_BLACK, HEX_WHITE, KEYS_HSL, KEYS_HSLA, KEYS_RGB, KEYS_RGBA, LENGTH_LONG, LENGTH_SHORT, MAX_DEGREE, MAX_HEX, MAX_PERCENT, SPACE_HSL, SPACE_RGB, SRGB_LUMINANCE_BLUE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_GREEN, SRGB_LUMINANCE_MINIMUM, SRGB_LUMINANCE_MODIFIER, SRGB_LUMINANCE_MULTIPLIER, SRGB_LUMINANCE_OFFSET, SRGB_LUMINANCE_RED, SRGB_LUMINANCE_THRESHOLD };
|
package/dist/color/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { rgbToHex, rgbToHsl, rgbToHsla } from "./space/rgb.js";
|
|
|
4
4
|
import { getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba } from "./space/hex.js";
|
|
5
5
|
import { hslToHex, hslToRgb, hslToRgba } from "./space/hsl.js";
|
|
6
6
|
import { Color } from "./instance.js";
|
|
7
|
+
//#region src/color/index.ts
|
|
7
8
|
/**
|
|
8
9
|
* Get a Color from any kind of value
|
|
9
10
|
* @param value Original value
|
|
@@ -12,4 +13,5 @@ import { Color } from "./instance.js";
|
|
|
12
13
|
function getColor(value) {
|
|
13
14
|
return isColor(value) ? value : new Color(value);
|
|
14
15
|
}
|
|
16
|
+
//#endregion
|
|
15
17
|
export { getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getRgbColor, getRgbaColor, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isRgbColor, isRgbLike, isRgbaColor, rgbToHex, rgbToHsl, rgbToHsla };
|
package/dist/color/instance.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatColor } from "./misc/index.js";
|
|
2
2
|
import { getAlpha } from "./misc/alpha.js";
|
|
3
3
|
import { getState, setHSLColor, setHexColor, setRGBColor } from "./misc/state.js";
|
|
4
|
+
//#region src/color/instance.ts
|
|
4
5
|
var Color = class {
|
|
5
6
|
#state;
|
|
6
7
|
/**
|
|
@@ -110,4 +111,5 @@ var Color = class {
|
|
|
110
111
|
return this.toHexString();
|
|
111
112
|
}
|
|
112
113
|
};
|
|
114
|
+
//#endregion
|
|
113
115
|
export { Color };
|
package/dist/color/misc/alpha.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ALPHA_FULL_HEX_LONG, DEFAULT_ALPHA } from "../constants.js";
|
|
2
|
+
//#region src/color/misc/alpha.ts
|
|
2
3
|
function getAlpha(value) {
|
|
3
4
|
if (typeof value === "number") return getAlphaFromValue(value);
|
|
4
5
|
if (typeof value === "string" && value !== ALPHA_FULL_HEX_LONG) return {
|
|
@@ -24,4 +25,5 @@ function getAlphaValue(original) {
|
|
|
24
25
|
if (original < 0) return 0;
|
|
25
26
|
return original <= 1 ? original : original / 100;
|
|
26
27
|
}
|
|
28
|
+
//#endregion
|
|
27
29
|
export { getAlpha, getAlphaHexadecimal, getAlphaValue };
|
package/dist/color/misc/get.js
CHANGED
|
@@ -2,6 +2,7 @@ import { HEX_BLACK, HEX_WHITE, SRGB_LUMINANCE_EXPONENT, SRGB_LUMINANCE_MODIFIER,
|
|
|
2
2
|
import { clamp } from "../../internal/number.js";
|
|
3
3
|
import { getState } from "./state.js";
|
|
4
4
|
import { Color } from "../instance.js";
|
|
5
|
+
//#region src/color/misc/get.ts
|
|
5
6
|
function getClampedValue(value, minimum, maximum) {
|
|
6
7
|
return typeof value === "number" ? clamp(value, minimum, maximum) : minimum;
|
|
7
8
|
}
|
|
@@ -91,4 +92,5 @@ function getRgbaColor(value) {
|
|
|
91
92
|
function getRgbColor(value) {
|
|
92
93
|
return getState(value).rgb;
|
|
93
94
|
}
|
|
95
|
+
//#endregion
|
|
94
96
|
export { getDegrees, getForegroundColor, getHexColor, getHexValue, getHexaColor, getHslColor, getHslaColor, getPercentage, getRgbColor, getRgbaColor };
|
package/dist/color/misc/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from "../../internal/string.js";
|
|
2
2
|
import { KEYS_HSL, KEYS_RGB } from "../constants.js";
|
|
3
|
+
//#region src/color/misc/index.ts
|
|
3
4
|
function formatColor(space, color, alpha) {
|
|
4
5
|
const suffix = alpha ? ` / ${color.alpha}` : "";
|
|
5
6
|
const value = color[space];
|
|
@@ -9,4 +10,5 @@ var formattingKeys = {
|
|
|
9
10
|
hsl: KEYS_HSL,
|
|
10
11
|
rgb: KEYS_RGB
|
|
11
12
|
};
|
|
13
|
+
//#endregion
|
|
12
14
|
export { formatColor };
|
package/dist/color/misc/is.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EXPRESSION_HEX_LONG, EXPRESSION_HEX_SHORT, KEYS_HSL, KEYS_HSLA, KEYS_RGB, KEYS_RGBA } from "../constants.js";
|
|
2
2
|
import { between } from "../../internal/number.js";
|
|
3
|
+
//#region src/color/misc/is.ts
|
|
3
4
|
function hasKeys(value, keys) {
|
|
4
5
|
return typeof value === "object" && value !== null && keys.every((key) => key in value);
|
|
5
6
|
}
|
|
@@ -93,4 +94,5 @@ var validators = {
|
|
|
93
94
|
saturation: isPercentage,
|
|
94
95
|
red: isBytey
|
|
95
96
|
};
|
|
97
|
+
//#endregion
|
|
96
98
|
export { isColor, isHexColor, isHslColor, isHslLike, isHslaColor, isRgbColor, isRgbLike, isRgbaColor };
|