@oscarpalmer/atoms 0.177.0 → 0.178.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/index.d.mts +2 -1
- package/dist/array/index.mjs +2 -1
- package/dist/array/reverse.d.mts +4 -0
- package/dist/array/reverse.mjs +16 -0
- package/dist/index.d.mts +47 -1
- package/dist/index.mjs +95 -1
- package/dist/internal/is.d.mts +54 -1
- package/dist/internal/is.mjs +58 -1
- package/dist/string/index.d.mts +3 -1
- package/dist/string/index.mjs +32 -1
- package/package.json +2 -2
- package/src/array/index.ts +1 -0
- package/src/array/reverse.ts +23 -0
- package/src/internal/is.ts +20 -0
- package/src/string/index.ts +76 -0
package/dist/array/index.d.mts
CHANGED
|
@@ -13,6 +13,7 @@ import { intersection } from "./intersection.mjs";
|
|
|
13
13
|
import { partition } from "./partition.mjs";
|
|
14
14
|
import { ArrayPosition, endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray } from "./position.mjs";
|
|
15
15
|
import { push } from "./push.mjs";
|
|
16
|
+
import { reverse } from "./reverse.mjs";
|
|
16
17
|
import { select } from "./select.mjs";
|
|
17
18
|
import { single } from "./single.mjs";
|
|
18
19
|
import { drop, slice, take } from "./slice.mjs";
|
|
@@ -22,4 +23,4 @@ import { toggle } from "./toggle.mjs";
|
|
|
22
23
|
import { union } from "./union.mjs";
|
|
23
24
|
import { unique } from "./unique.mjs";
|
|
24
25
|
import { update } from "./update.mjs";
|
|
25
|
-
export { ArrayPosition, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
|
26
|
+
export { ArrayPosition, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
package/dist/array/index.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { intersection } from "./intersection.mjs";
|
|
|
13
13
|
import { partition } from "./partition.mjs";
|
|
14
14
|
import { endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray } from "./position.mjs";
|
|
15
15
|
import { push } from "./push.mjs";
|
|
16
|
+
import { reverse } from "./reverse.mjs";
|
|
16
17
|
import { select } from "./select.mjs";
|
|
17
18
|
import { single } from "./single.mjs";
|
|
18
19
|
import { drop, slice, take } from "./slice.mjs";
|
|
@@ -22,4 +23,4 @@ import { toggle } from "./toggle.mjs";
|
|
|
22
23
|
import { union } from "./union.mjs";
|
|
23
24
|
import { unique } from "./unique.mjs";
|
|
24
25
|
import { update } from "./update.mjs";
|
|
25
|
-
export { chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
|
26
|
+
export { chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/array/reverse.ts
|
|
2
|
+
function reverse(array) {
|
|
3
|
+
if (!Array.isArray(array)) return [];
|
|
4
|
+
const { length } = array;
|
|
5
|
+
if (length < 2) return array;
|
|
6
|
+
const half = Math.floor(length / 2);
|
|
7
|
+
for (let firstIndex = 0; firstIndex < half; firstIndex += 1) {
|
|
8
|
+
const temporaryItem = array[firstIndex];
|
|
9
|
+
const secondIndex = length - 1 - firstIndex;
|
|
10
|
+
array[firstIndex] = array[secondIndex];
|
|
11
|
+
array[secondIndex] = temporaryItem;
|
|
12
|
+
}
|
|
13
|
+
return array;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { reverse };
|
package/dist/index.d.mts
CHANGED
|
@@ -829,6 +829,9 @@ declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolea
|
|
|
829
829
|
*/
|
|
830
830
|
declare function push<Item>(array: Item[], pushed: Item[]): number;
|
|
831
831
|
//#endregion
|
|
832
|
+
//#region src/array/reverse.d.ts
|
|
833
|
+
declare function reverse<Item>(array: Item[]): Item[];
|
|
834
|
+
//#endregion
|
|
832
835
|
//#region src/array/select.d.ts
|
|
833
836
|
/**
|
|
834
837
|
* Get a filtered and mapped array of items
|
|
@@ -2667,6 +2670,8 @@ declare function titleCase(value: string): string;
|
|
|
2667
2670
|
declare function upperCase(value: string): string;
|
|
2668
2671
|
//#endregion
|
|
2669
2672
|
//#region src/string/index.d.ts
|
|
2673
|
+
declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
2674
|
+
declare function dedent(value: string): string;
|
|
2670
2675
|
/**
|
|
2671
2676
|
* Get a new UUID-string _(version 4)_
|
|
2672
2677
|
* @returns UUID string
|
|
@@ -3343,13 +3348,54 @@ declare function isInstanceOf<Instance>(constructor: Constructor<Instance>, valu
|
|
|
3343
3348
|
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
3344
3349
|
*/
|
|
3345
3350
|
declare function isKey(value: unknown): value is Key;
|
|
3351
|
+
/**
|
|
3352
|
+
* Is the value not an array or a plain object?
|
|
3353
|
+
* @param value Value to check
|
|
3354
|
+
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
3355
|
+
*/
|
|
3346
3356
|
declare function isNonArrayOrPlainObject<Value>(value: Value): value is Exclude<Value, ArrayOrPlainObject>;
|
|
3357
|
+
/**
|
|
3358
|
+
* Is the value not a constructor function?
|
|
3359
|
+
* @param value Value to check
|
|
3360
|
+
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
3361
|
+
*/
|
|
3347
3362
|
declare function isNonConstructor<Value>(value: Value): value is Exclude<Value, Constructor>;
|
|
3363
|
+
/**
|
|
3364
|
+
* Is the value not an instance of the constructor?
|
|
3365
|
+
* @param constructor Class constructor
|
|
3366
|
+
* @param value Value to check
|
|
3367
|
+
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
3368
|
+
*/
|
|
3348
3369
|
declare function isNonInstanceOf<Instance, Value>(constructor: Constructor<Instance>, value: Value): value is Exclude<Value, Instance>;
|
|
3370
|
+
/**
|
|
3371
|
+
* Is the value not a key?
|
|
3372
|
+
* @param value Value to check
|
|
3373
|
+
* @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
|
|
3374
|
+
*/
|
|
3349
3375
|
declare function isNonKey<Value>(value: Value): value is Exclude<Value, Key>;
|
|
3376
|
+
/**
|
|
3377
|
+
* Is the value not a number?
|
|
3378
|
+
* @param value Value to check
|
|
3379
|
+
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
3380
|
+
*/
|
|
3350
3381
|
declare function isNonNumber<Value>(value: Value): value is Exclude<Value, number>;
|
|
3382
|
+
/**
|
|
3383
|
+
* Is the value not a plain object?
|
|
3384
|
+
* @param value Value to check
|
|
3385
|
+
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
3386
|
+
*/
|
|
3351
3387
|
declare function isNonPlainObject<Value>(value: Value): value is Exclude<Value, PlainObject>;
|
|
3388
|
+
/**
|
|
3389
|
+
* Is the value not a primitive value?
|
|
3390
|
+
* @param value Value to check
|
|
3391
|
+
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
3392
|
+
*/
|
|
3352
3393
|
declare function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Primitive>;
|
|
3394
|
+
/**
|
|
3395
|
+
* Is the value not a typed array?
|
|
3396
|
+
* @param value Value to check
|
|
3397
|
+
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
3398
|
+
*/
|
|
3353
3399
|
declare function isNonTypedArray<Value>(value: Value): value is Exclude<Value, TypedArray>;
|
|
3354
3400
|
/**
|
|
3355
3401
|
* Is the value a number?
|
|
@@ -4780,4 +4826,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
|
|
|
4780
4826
|
get(value: Value, update?: boolean): Value | undefined;
|
|
4781
4827
|
}
|
|
4782
4828
|
//#endregion
|
|
4783
|
-
export { AnyResult, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayPosition, ArrayValueSorter, Asserter, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, ExtendedErr, ExtendedResult, Flow, FlowPromise, FulfilledPromise, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, HasValue, Key, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, 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, QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, Simplify, SizedMap, SizedSet, Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Time, ToString, TypedArray, Unsmushed, UnwrapValue, assert, attempt, attemptFlow, attemptPipe, 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, first, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, 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, isTypedArray, join, kebabCase, last, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
4829
|
+
export { AnyResult, ArrayComparisonSorter, ArrayKeySorter, ArrayOrPlainObject, ArrayPosition, ArrayValueSorter, Asserter, AsyncCancelableCallback, AttemptFlow, AttemptFlowPromise, type Beacon, type BeaconOptions, BuiltIns, CancelableCallback, CancelablePromise, type Color, Constructor, DiffOptions, DiffResult, DiffValue, EqualOptions, Err, EventPosition, ExtendedErr, ExtendedResult, Flow, FlowPromise, FulfilledPromise, GenericAsyncCallback, GenericCallback, type HSLAColor, type HSLColor, HasValue, Key, KeyedValue, type Logger, type Memoized, type MemoizedOptions, MergeOptions, Merger, NestedArray, NestedKeys, NestedPartial, NestedValue, NestedValues, 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, QueueError, type QueueOptions, type Queued, type QueuedResult, type RGBAColor, type RGBColor, RejectedPromise, RequiredKeys, Result, ResultMatch, RetryError, RetryOptions, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, Simplify, SizedMap, SizedSet, Smushed, SortDirection, Sorter, type Subscription, TemplateOptions, type Time, ToString, TypedArray, Unsmushed, UnwrapValue, assert, attempt, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, first, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, 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, isTypedArray, join, kebabCase, last, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/index.mjs
CHANGED
|
@@ -212,27 +212,68 @@ function isInstanceOf(constructor, value) {
|
|
|
212
212
|
function isKey(value) {
|
|
213
213
|
return typeof value === "number" || typeof value === "string";
|
|
214
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Is the value not an array or a plain object?
|
|
217
|
+
* @param value Value to check
|
|
218
|
+
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
219
|
+
*/
|
|
215
220
|
function isNonArrayOrPlainObject(value) {
|
|
216
221
|
return !isArrayOrPlainObject(value);
|
|
217
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Is the value not a constructor function?
|
|
225
|
+
* @param value Value to check
|
|
226
|
+
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
227
|
+
*/
|
|
218
228
|
function isNonConstructor(value) {
|
|
219
229
|
return !isConstructor(value);
|
|
220
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Is the value not an instance of the constructor?
|
|
233
|
+
* @param constructor Class constructor
|
|
234
|
+
* @param value Value to check
|
|
235
|
+
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
236
|
+
*/
|
|
221
237
|
function isNonInstanceOf(constructor, value) {
|
|
222
238
|
return !isInstanceOf(constructor, value);
|
|
223
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Is the value not a key?
|
|
242
|
+
* @param value Value to check
|
|
243
|
+
* @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
|
|
244
|
+
*/
|
|
224
245
|
function isNonKey(value) {
|
|
225
246
|
return !isKey(value);
|
|
226
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Is the value not a number?
|
|
250
|
+
* @param value Value to check
|
|
251
|
+
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
252
|
+
*/
|
|
227
253
|
function isNonNumber(value) {
|
|
228
254
|
return !isNumber(value);
|
|
229
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Is the value not a plain object?
|
|
258
|
+
* @param value Value to check
|
|
259
|
+
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
260
|
+
*/
|
|
230
261
|
function isNonPlainObject(value) {
|
|
231
262
|
return !isPlainObject(value);
|
|
232
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Is the value not a primitive value?
|
|
266
|
+
* @param value Value to check
|
|
267
|
+
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
268
|
+
*/
|
|
233
269
|
function isNonPrimitive(value) {
|
|
234
270
|
return !isPrimitive(value);
|
|
235
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Is the value not a typed array?
|
|
274
|
+
* @param value Value to check
|
|
275
|
+
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
276
|
+
*/
|
|
236
277
|
function isNonTypedArray(value) {
|
|
237
278
|
return !isTypedArray(value);
|
|
238
279
|
}
|
|
@@ -266,6 +307,14 @@ function isPrimitive(value) {
|
|
|
266
307
|
return type === "bigint" || type === "boolean" || type === "number" || type === "string" || type === "symbol";
|
|
267
308
|
}
|
|
268
309
|
/**
|
|
310
|
+
* Is the value a template strings array?
|
|
311
|
+
* @param value Value to check
|
|
312
|
+
* @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
|
|
313
|
+
*/
|
|
314
|
+
function isTemplateStringsArray(value) {
|
|
315
|
+
return Array.isArray(value) && Array.isArray(value.raw);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
269
318
|
* Is the value a typed array?
|
|
270
319
|
* @param value Value to check
|
|
271
320
|
* @returns `true` if the value is a typed array, otherwise `false`
|
|
@@ -532,6 +581,21 @@ function push(array, pushed) {
|
|
|
532
581
|
return insertValues(INSERT_TYPE_PUSH, array, pushed, array.length, 0);
|
|
533
582
|
}
|
|
534
583
|
//#endregion
|
|
584
|
+
//#region src/array/reverse.ts
|
|
585
|
+
function reverse(array) {
|
|
586
|
+
if (!Array.isArray(array)) return [];
|
|
587
|
+
const { length } = array;
|
|
588
|
+
if (length < 2) return array;
|
|
589
|
+
const half = Math.floor(length / 2);
|
|
590
|
+
for (let firstIndex = 0; firstIndex < half; firstIndex += 1) {
|
|
591
|
+
const temporaryItem = array[firstIndex];
|
|
592
|
+
const secondIndex = length - 1 - firstIndex;
|
|
593
|
+
array[firstIndex] = array[secondIndex];
|
|
594
|
+
array[secondIndex] = temporaryItem;
|
|
595
|
+
}
|
|
596
|
+
return array;
|
|
597
|
+
}
|
|
598
|
+
//#endregion
|
|
535
599
|
//#region src/array/select.ts
|
|
536
600
|
function select(array, ...parameters) {
|
|
537
601
|
return findValues("all", array, parameters, parameters.pop()).matched;
|
|
@@ -2253,6 +2317,30 @@ let memoizedCapitalize;
|
|
|
2253
2317
|
let memoizedTitleCase;
|
|
2254
2318
|
//#endregion
|
|
2255
2319
|
//#region src/string/index.ts
|
|
2320
|
+
function dedent(value, ...values) {
|
|
2321
|
+
let actual;
|
|
2322
|
+
if (isTemplateStringsArray(value)) actual = interpolate(value, values);
|
|
2323
|
+
else actual = value;
|
|
2324
|
+
if (typeof actual !== "string") return "";
|
|
2325
|
+
const lines = actual.split("\n");
|
|
2326
|
+
const { length } = lines;
|
|
2327
|
+
if (length === 1) return actual.trim();
|
|
2328
|
+
const lastIndex = length - 1;
|
|
2329
|
+
const lengths = [];
|
|
2330
|
+
for (let index = 0; index < length; index += 1) {
|
|
2331
|
+
const [, indentation] = /^(\s+)/.exec(lines[index]) ?? [];
|
|
2332
|
+
if (indentation != null) lengths.push(indentation.length);
|
|
2333
|
+
}
|
|
2334
|
+
if (lengths.length === 0) return actual.trim();
|
|
2335
|
+
const minimum = Math.min(...lengths);
|
|
2336
|
+
const pattern = new RegExp(`^\\s{0,${minimum}}`);
|
|
2337
|
+
let result = "";
|
|
2338
|
+
for (let index = 0; index < length; index += 1) {
|
|
2339
|
+
const line = lines[index];
|
|
2340
|
+
result += line.replace(pattern, "") + (index === lastIndex ? "" : "\n");
|
|
2341
|
+
}
|
|
2342
|
+
return result.trim();
|
|
2343
|
+
}
|
|
2256
2344
|
/**
|
|
2257
2345
|
* Get a new UUID-string _(version 4)_
|
|
2258
2346
|
* @returns UUID string
|
|
@@ -2271,6 +2359,12 @@ function getUuid() {
|
|
|
2271
2359
|
hex.substring(20, 32)
|
|
2272
2360
|
].join("-");
|
|
2273
2361
|
}
|
|
2362
|
+
function interpolate(strings, values) {
|
|
2363
|
+
const { length } = strings;
|
|
2364
|
+
let interpolated = "";
|
|
2365
|
+
for (let index = 0; index < length; index += 1) interpolated += `${strings[index]}${getString(values[index])}`;
|
|
2366
|
+
return interpolated;
|
|
2367
|
+
}
|
|
2274
2368
|
/**
|
|
2275
2369
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
2276
2370
|
* @param value JSON string to parse
|
|
@@ -4706,4 +4800,4 @@ var SizedSet = class extends Set {
|
|
|
4706
4800
|
}
|
|
4707
4801
|
};
|
|
4708
4802
|
//#endregion
|
|
4709
|
-
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, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, attempt, attemptFlow, attemptPipe, 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, first, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, 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, isTypedArray, join, kebabCase, last, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
4803
|
+
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, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, attempt, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, count, debounce, dedent, delay, diff, difference, drop, endsWith, endsWithArray, equal, error, exists, filter, find, first, flatten, floor, flow, fromQuery, toPromise as fromResult, toPromise, getArray, getArrayPosition, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getTimedPromise, getUuid, getValue, groupBy, handleResult, hasValue, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, 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, isTypedArray, join, kebabCase, last, logger, lowerCase, matchResult, max, median, memoize, merge, min, move, noop, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toQuery, toRecord, toResult, toSet, toggle, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
package/dist/internal/is.d.mts
CHANGED
|
@@ -26,13 +26,60 @@ declare function isInstanceOf<Instance>(constructor: Constructor<Instance>, valu
|
|
|
26
26
|
* @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
|
|
27
27
|
*/
|
|
28
28
|
declare function isKey(value: unknown): value is Key;
|
|
29
|
+
/**
|
|
30
|
+
* Is the value not an array or a plain object?
|
|
31
|
+
* @param value Value to check
|
|
32
|
+
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
33
|
+
*/
|
|
29
34
|
declare function isNonArrayOrPlainObject<Value>(value: Value): value is Exclude<Value, ArrayOrPlainObject>;
|
|
35
|
+
/**
|
|
36
|
+
* Is the value not a constructor function?
|
|
37
|
+
* @param value Value to check
|
|
38
|
+
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
39
|
+
*/
|
|
30
40
|
declare function isNonConstructor<Value>(value: Value): value is Exclude<Value, Constructor>;
|
|
41
|
+
/**
|
|
42
|
+
* Is the value not an instance of the constructor?
|
|
43
|
+
* @param constructor Class constructor
|
|
44
|
+
* @param value Value to check
|
|
45
|
+
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
46
|
+
*/
|
|
31
47
|
declare function isNonInstanceOf<Instance, Value>(constructor: Constructor<Instance>, value: Value): value is Exclude<Value, Instance>;
|
|
48
|
+
/**
|
|
49
|
+
* Is the value not a key?
|
|
50
|
+
* @param value Value to check
|
|
51
|
+
* @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
|
|
52
|
+
*/
|
|
32
53
|
declare function isNonKey<Value>(value: Value): value is Exclude<Value, Key>;
|
|
54
|
+
/**
|
|
55
|
+
* Is the value not a number?
|
|
56
|
+
* @param value Value to check
|
|
57
|
+
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
58
|
+
*/
|
|
33
59
|
declare function isNonNumber<Value>(value: Value): value is Exclude<Value, number>;
|
|
60
|
+
/**
|
|
61
|
+
* Is the value not a plain object?
|
|
62
|
+
* @param value Value to check
|
|
63
|
+
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
64
|
+
*/
|
|
34
65
|
declare function isNonPlainObject<Value>(value: Value): value is Exclude<Value, PlainObject>;
|
|
66
|
+
/**
|
|
67
|
+
* Is the value not a primitive value?
|
|
68
|
+
* @param value Value to check
|
|
69
|
+
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
70
|
+
*/
|
|
35
71
|
declare function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Primitive>;
|
|
72
|
+
/**
|
|
73
|
+
* Is the value not a template strings array?
|
|
74
|
+
* @param value Value to check
|
|
75
|
+
* @returns `true` if the value is not a `TemplateStringsArray`, otherwise `false`
|
|
76
|
+
*/
|
|
77
|
+
declare function isNonTemplateStringsArray<Value>(value: Value): value is Exclude<Value, TemplateStringsArray>;
|
|
78
|
+
/**
|
|
79
|
+
* Is the value not a typed array?
|
|
80
|
+
* @param value Value to check
|
|
81
|
+
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
82
|
+
*/
|
|
36
83
|
declare function isNonTypedArray<Value>(value: Value): value is Exclude<Value, TypedArray>;
|
|
37
84
|
/**
|
|
38
85
|
* Is the value a number?
|
|
@@ -52,6 +99,12 @@ declare function isPlainObject(value: unknown): value is PlainObject;
|
|
|
52
99
|
* @returns `true` if the value matches, otherwise `false`
|
|
53
100
|
*/
|
|
54
101
|
declare function isPrimitive(value: unknown): value is Primitive;
|
|
102
|
+
/**
|
|
103
|
+
* Is the value a template strings array?
|
|
104
|
+
* @param value Value to check
|
|
105
|
+
* @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
|
|
106
|
+
*/
|
|
107
|
+
declare function isTemplateStringsArray(value: unknown): value is TemplateStringsArray;
|
|
55
108
|
/**
|
|
56
109
|
* Is the value a typed array?
|
|
57
110
|
* @param value Value to check
|
|
@@ -59,4 +112,4 @@ declare function isPrimitive(value: unknown): value is Primitive;
|
|
|
59
112
|
*/
|
|
60
113
|
declare function isTypedArray(value: unknown): value is TypedArray;
|
|
61
114
|
//#endregion
|
|
62
|
-
export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTypedArray };
|
|
115
|
+
export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTemplateStringsArray, isTypedArray };
|
package/dist/internal/is.mjs
CHANGED
|
@@ -32,27 +32,76 @@ function isInstanceOf(constructor, value) {
|
|
|
32
32
|
function isKey(value) {
|
|
33
33
|
return typeof value === "number" || typeof value === "string";
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Is the value not an array or a plain object?
|
|
37
|
+
* @param value Value to check
|
|
38
|
+
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
39
|
+
*/
|
|
35
40
|
function isNonArrayOrPlainObject(value) {
|
|
36
41
|
return !isArrayOrPlainObject(value);
|
|
37
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Is the value not a constructor function?
|
|
45
|
+
* @param value Value to check
|
|
46
|
+
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
47
|
+
*/
|
|
38
48
|
function isNonConstructor(value) {
|
|
39
49
|
return !isConstructor(value);
|
|
40
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Is the value not an instance of the constructor?
|
|
53
|
+
* @param constructor Class constructor
|
|
54
|
+
* @param value Value to check
|
|
55
|
+
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
56
|
+
*/
|
|
41
57
|
function isNonInstanceOf(constructor, value) {
|
|
42
58
|
return !isInstanceOf(constructor, value);
|
|
43
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Is the value not a key?
|
|
62
|
+
* @param value Value to check
|
|
63
|
+
* @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
|
|
64
|
+
*/
|
|
44
65
|
function isNonKey(value) {
|
|
45
66
|
return !isKey(value);
|
|
46
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Is the value not a number?
|
|
70
|
+
* @param value Value to check
|
|
71
|
+
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
72
|
+
*/
|
|
47
73
|
function isNonNumber(value) {
|
|
48
74
|
return !isNumber(value);
|
|
49
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Is the value not a plain object?
|
|
78
|
+
* @param value Value to check
|
|
79
|
+
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
80
|
+
*/
|
|
50
81
|
function isNonPlainObject(value) {
|
|
51
82
|
return !isPlainObject(value);
|
|
52
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Is the value not a primitive value?
|
|
86
|
+
* @param value Value to check
|
|
87
|
+
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
88
|
+
*/
|
|
53
89
|
function isNonPrimitive(value) {
|
|
54
90
|
return !isPrimitive(value);
|
|
55
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Is the value not a template strings array?
|
|
94
|
+
* @param value Value to check
|
|
95
|
+
* @returns `true` if the value is not a `TemplateStringsArray`, otherwise `false`
|
|
96
|
+
*/
|
|
97
|
+
function isNonTemplateStringsArray(value) {
|
|
98
|
+
return !isTemplateStringsArray(value);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Is the value not a typed array?
|
|
102
|
+
* @param value Value to check
|
|
103
|
+
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
104
|
+
*/
|
|
56
105
|
function isNonTypedArray(value) {
|
|
57
106
|
return !isTypedArray(value);
|
|
58
107
|
}
|
|
@@ -86,6 +135,14 @@ function isPrimitive(value) {
|
|
|
86
135
|
return type === "bigint" || type === "boolean" || type === "number" || type === "string" || type === "symbol";
|
|
87
136
|
}
|
|
88
137
|
/**
|
|
138
|
+
* Is the value a template strings array?
|
|
139
|
+
* @param value Value to check
|
|
140
|
+
* @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
|
|
141
|
+
*/
|
|
142
|
+
function isTemplateStringsArray(value) {
|
|
143
|
+
return Array.isArray(value) && Array.isArray(value.raw);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
89
146
|
* Is the value a typed array?
|
|
90
147
|
* @param value Value to check
|
|
91
148
|
* @returns `true` if the value is a typed array, otherwise `false`
|
|
@@ -107,4 +164,4 @@ function isTypedArray(value) {
|
|
|
107
164
|
return isTypedArray.types.has(value?.constructor);
|
|
108
165
|
}
|
|
109
166
|
//#endregion
|
|
110
|
-
export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTypedArray };
|
|
167
|
+
export { isArrayOrPlainObject, isConstructor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonInstanceOf, isNonKey, isNonNumber, isNonPlainObject, isNonPrimitive, isNonTemplateStringsArray, isNonTypedArray, isNumber, isPlainObject, isPrimitive, isTemplateStringsArray, isTypedArray };
|
package/dist/string/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getString, join, words } from "../internal/string.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/string/index.d.ts
|
|
4
|
+
declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
5
|
+
declare function dedent(value: string): string;
|
|
4
6
|
/**
|
|
5
7
|
* Get a new UUID-string _(version 4)_
|
|
6
8
|
* @returns UUID string
|
|
@@ -28,4 +30,4 @@ declare function trim(value: string): string;
|
|
|
28
30
|
*/
|
|
29
31
|
declare function truncate(value: string, length: number, suffix?: string): string;
|
|
30
32
|
//#endregion
|
|
31
|
-
export { getString, getUuid, join, parse, trim, truncate, words };
|
|
33
|
+
export { dedent, getString, getUuid, join, parse, trim, truncate, words };
|
package/dist/string/index.mjs
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
import { isTemplateStringsArray } from "../internal/is.mjs";
|
|
1
2
|
import { getString, join, words } from "../internal/string.mjs";
|
|
2
3
|
//#region src/string/index.ts
|
|
4
|
+
function dedent(value, ...values) {
|
|
5
|
+
let actual;
|
|
6
|
+
if (isTemplateStringsArray(value)) actual = interpolate(value, values);
|
|
7
|
+
else actual = value;
|
|
8
|
+
if (typeof actual !== "string") return "";
|
|
9
|
+
const lines = actual.split("\n");
|
|
10
|
+
const { length } = lines;
|
|
11
|
+
if (length === 1) return actual.trim();
|
|
12
|
+
const lastIndex = length - 1;
|
|
13
|
+
const lengths = [];
|
|
14
|
+
for (let index = 0; index < length; index += 1) {
|
|
15
|
+
const [, indentation] = /^(\s+)/.exec(lines[index]) ?? [];
|
|
16
|
+
if (indentation != null) lengths.push(indentation.length);
|
|
17
|
+
}
|
|
18
|
+
if (lengths.length === 0) return actual.trim();
|
|
19
|
+
const minimum = Math.min(...lengths);
|
|
20
|
+
const pattern = new RegExp(`^\\s{0,${minimum}}`);
|
|
21
|
+
let result = "";
|
|
22
|
+
for (let index = 0; index < length; index += 1) {
|
|
23
|
+
const line = lines[index];
|
|
24
|
+
result += line.replace(pattern, "") + (index === lastIndex ? "" : "\n");
|
|
25
|
+
}
|
|
26
|
+
return result.trim();
|
|
27
|
+
}
|
|
3
28
|
/**
|
|
4
29
|
* Get a new UUID-string _(version 4)_
|
|
5
30
|
* @returns UUID string
|
|
@@ -18,6 +43,12 @@ function getUuid() {
|
|
|
18
43
|
hex.substring(20, 32)
|
|
19
44
|
].join("-");
|
|
20
45
|
}
|
|
46
|
+
function interpolate(strings, values) {
|
|
47
|
+
const { length } = strings;
|
|
48
|
+
let interpolated = "";
|
|
49
|
+
for (let index = 0; index < length; index += 1) interpolated += `${strings[index]}${getString(values[index])}`;
|
|
50
|
+
return interpolated;
|
|
51
|
+
}
|
|
21
52
|
/**
|
|
22
53
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
23
54
|
* @param value JSON string to parse
|
|
@@ -57,4 +88,4 @@ function truncate(value, length, suffix) {
|
|
|
57
88
|
}
|
|
58
89
|
const ZERO = "0";
|
|
59
90
|
//#endregion
|
|
60
|
-
export { getString, getUuid, join, parse, trim, truncate, words };
|
|
91
|
+
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.
|
|
3
|
+
"version": "0.178.0",
|
|
4
4
|
"description": "Atomic utilities for making your JavaScript better.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"helper",
|
|
@@ -241,7 +241,7 @@
|
|
|
241
241
|
"watch": "npx vite build --watch"
|
|
242
242
|
},
|
|
243
243
|
"devDependencies": {
|
|
244
|
-
"@oxlint/plugins": "^1.
|
|
244
|
+
"@oxlint/plugins": "^1.60",
|
|
245
245
|
"@types/node": "^25.6",
|
|
246
246
|
"@vitest/coverage-istanbul": "^4.1",
|
|
247
247
|
"eslint": "^10.2",
|
package/src/array/index.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function reverse<Item>(array: Item[]): Item[] {
|
|
2
|
+
if (!Array.isArray(array)) {
|
|
3
|
+
return [];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const {length} = array;
|
|
7
|
+
|
|
8
|
+
if (length < 2) {
|
|
9
|
+
return array;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const half = Math.floor(length / 2);
|
|
13
|
+
|
|
14
|
+
for (let firstIndex = 0; firstIndex < half; firstIndex += 1) {
|
|
15
|
+
const temporaryItem = array[firstIndex];
|
|
16
|
+
const secondIndex = length - 1 - firstIndex;
|
|
17
|
+
|
|
18
|
+
array[firstIndex] = array[secondIndex];
|
|
19
|
+
array[secondIndex] = temporaryItem;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return array;
|
|
23
|
+
}
|
package/src/internal/is.ts
CHANGED
|
@@ -118,6 +118,17 @@ export function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Pri
|
|
|
118
118
|
return !isPrimitive(value);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Is the value not a template strings array?
|
|
123
|
+
* @param value Value to check
|
|
124
|
+
* @returns `true` if the value is not a `TemplateStringsArray`, otherwise `false`
|
|
125
|
+
*/
|
|
126
|
+
export function isNonTemplateStringsArray<Value>(
|
|
127
|
+
value: Value,
|
|
128
|
+
): value is Exclude<Value, TemplateStringsArray> {
|
|
129
|
+
return !isTemplateStringsArray(value);
|
|
130
|
+
}
|
|
131
|
+
|
|
121
132
|
/**
|
|
122
133
|
* Is the value not a typed array?
|
|
123
134
|
* @param value Value to check
|
|
@@ -180,6 +191,15 @@ export function isPrimitive(value: unknown): value is Primitive {
|
|
|
180
191
|
);
|
|
181
192
|
}
|
|
182
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Is the value a template strings array?
|
|
196
|
+
* @param value Value to check
|
|
197
|
+
* @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
|
|
198
|
+
*/
|
|
199
|
+
export function isTemplateStringsArray(value: unknown): value is TemplateStringsArray {
|
|
200
|
+
return Array.isArray(value) && Array.isArray((value as unknown as TemplateStringsArray).raw);
|
|
201
|
+
}
|
|
202
|
+
|
|
183
203
|
/**
|
|
184
204
|
* Is the value a typed array?
|
|
185
205
|
* @param value Value to check
|
package/src/string/index.ts
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
|
+
import {isTemplateStringsArray} from '../internal/is';
|
|
2
|
+
import {getString} from '../internal/string';
|
|
3
|
+
|
|
1
4
|
// #region Functions
|
|
2
5
|
|
|
6
|
+
export function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
7
|
+
|
|
8
|
+
export function dedent(value: string): string;
|
|
9
|
+
|
|
10
|
+
export function dedent(value: string | TemplateStringsArray, ...values: unknown[]): string {
|
|
11
|
+
let actual: string;
|
|
12
|
+
|
|
13
|
+
if (isTemplateStringsArray(value)) {
|
|
14
|
+
actual = interpolate(value, values);
|
|
15
|
+
} else {
|
|
16
|
+
actual = value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof actual !== 'string') {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const lines = actual.split('\n');
|
|
24
|
+
const {length} = lines;
|
|
25
|
+
|
|
26
|
+
if (length === 1) {
|
|
27
|
+
return actual.trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const lastIndex = length - 1;
|
|
31
|
+
|
|
32
|
+
const lengths: number[] = [];
|
|
33
|
+
|
|
34
|
+
for (let index = 0; index < length; index += 1) {
|
|
35
|
+
const [, indentation] = /^(\s+)/.exec(lines[index]) ?? [];
|
|
36
|
+
|
|
37
|
+
if (indentation != null) {
|
|
38
|
+
lengths.push(indentation.length);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (lengths.length === 0) {
|
|
43
|
+
return actual.trim();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const minimum = Math.min(...lengths);
|
|
47
|
+
|
|
48
|
+
const pattern = new RegExp(`^\\s{0,${minimum}}`);
|
|
49
|
+
|
|
50
|
+
let result = '';
|
|
51
|
+
|
|
52
|
+
for (let index = 0; index < length; index += 1) {
|
|
53
|
+
const line = lines[index];
|
|
54
|
+
|
|
55
|
+
result += line.replace(pattern, '') + (index === lastIndex ? '' : '\n');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return result.trim();
|
|
59
|
+
}
|
|
60
|
+
|
|
3
61
|
/**
|
|
4
62
|
* Get a new UUID-string _(version 4)_
|
|
5
63
|
* @returns UUID string
|
|
@@ -24,6 +82,18 @@ export function getUuid(): string {
|
|
|
24
82
|
].join('-');
|
|
25
83
|
}
|
|
26
84
|
|
|
85
|
+
function interpolate(strings: TemplateStringsArray, values: unknown[]): string {
|
|
86
|
+
const {length} = strings;
|
|
87
|
+
|
|
88
|
+
let interpolated = '';
|
|
89
|
+
|
|
90
|
+
for (let index = 0; index < length; index += 1) {
|
|
91
|
+
interpolated += `${strings[index]}${getString(values[index])}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return interpolated;
|
|
95
|
+
}
|
|
96
|
+
|
|
27
97
|
/**
|
|
28
98
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
29
99
|
* @param value JSON string to parse
|
|
@@ -78,6 +148,8 @@ export function truncate(value: string, length: number, suffix?: string): string
|
|
|
78
148
|
return `${value.slice(0, truncatedLength)}${actualSuffix}`;
|
|
79
149
|
}
|
|
80
150
|
|
|
151
|
+
// #endregion
|
|
152
|
+
|
|
81
153
|
// #region Variables
|
|
82
154
|
|
|
83
155
|
const ZERO = '0';
|
|
@@ -86,4 +158,8 @@ const ZERO = '0';
|
|
|
86
158
|
|
|
87
159
|
// #endregion
|
|
88
160
|
|
|
161
|
+
// #region Exports
|
|
162
|
+
|
|
89
163
|
export {getString, join, words} from '../internal/string';
|
|
164
|
+
|
|
165
|
+
// #endregion
|