@oscarpalmer/atoms 0.177.0 → 0.179.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.
@@ -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 };
@@ -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,4 @@
1
+ //#region src/array/reverse.d.ts
2
+ declare function reverse<Item>(array: Item[]): Item[];
3
+ //#endregion
4
+ export { reverse };
@@ -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
@@ -2666,7 +2669,116 @@ declare function titleCase(value: string): string;
2666
2669
  */
2667
2670
  declare function upperCase(value: string): string;
2668
2671
  //#endregion
2672
+ //#region src/string/fuzzy.d.ts
2673
+ /**
2674
+ * Fuzzy searcher for an array of items
2675
+ */
2676
+ declare class Fuzzy<Item> {
2677
+ #private;
2678
+ /**
2679
+ * Get items currently being searched through
2680
+ */
2681
+ get items(): Item[];
2682
+ /**
2683
+ * Set new items to search through
2684
+ */
2685
+ set items(items: Item[]);
2686
+ /**
2687
+ * Get strings currently being searched through _(the stringified version of `items`)_
2688
+ */
2689
+ get strings(): string[];
2690
+ constructor(state: FuzzyState<Item>);
2691
+ /**
2692
+ * Search for items matching the given value
2693
+ * @param value Value to search for
2694
+ * @param options Search options
2695
+ * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_
2696
+ */
2697
+ search(value: string, options?: FuzzyOptions): FuzzyResult<Item>;
2698
+ /**
2699
+ * Search for items matching the given value
2700
+ * @param value Value to search for
2701
+ * @param limit Maximum number of combined items to return in `exact` and `similar`
2702
+ * @returns Search results, with exact matches _(ordered)_ and similar matches _(ordered by relevance)_
2703
+ */
2704
+ search(value: string, limit: number): FuzzyResult<Item>;
2705
+ }
2706
+ type FuzzyConfiguration<Item> = {
2707
+ /**
2708
+ * Handler to stringify items
2709
+ *
2710
+ * May be a function that takes an item and returns a string, or if items are plain objects, a key of the item to use to grab a string value from
2711
+ *
2712
+ * Defaults to `getString`
2713
+ */
2714
+ handler?: (item: Item) => string;
2715
+ } & (Item extends PlainObject ? {
2716
+ /**
2717
+ * Key to use to stringify items
2718
+ *
2719
+ * Prioritized over `handler`
2720
+ */
2721
+ key?: keyof Item;
2722
+ } : {}) & FuzzyOptions;
2723
+ type FuzzyOptions = {
2724
+ /**
2725
+ * Maximum number of combined items to return in `exact` and `similar` _(defaults to all matches)_
2726
+ */
2727
+ limit?: number;
2728
+ /**
2729
+ * Maximum score difference between the best and worst similar matches included in results; higher values cast a wider net _(defaults to 5)_
2730
+ */
2731
+ tolerance?: number;
2732
+ };
2733
+ /**
2734
+ * Search results from a fuzzy search, with exact and similar matches
2735
+ */
2736
+ type FuzzyResult<Item> = {
2737
+ /**
2738
+ * Ordered items that exactly match the search value
2739
+ */
2740
+ exact: Item[];
2741
+ /**
2742
+ * Ordered items that are similar to the search value, ranked by relevance
2743
+ */
2744
+ similar: Item[];
2745
+ };
2746
+ /**
2747
+ * Options for fuzzy searching
2748
+ */
2749
+ type FuzzySearchOptions = FuzzyOptions;
2750
+ type FuzzyState<Item> = {
2751
+ handler: (item: Item) => string;
2752
+ items: Item[];
2753
+ limit?: number;
2754
+ strings: string[];
2755
+ tolerance: number;
2756
+ };
2757
+ /**
2758
+ * Create a fuzzy searcher for an array of items
2759
+ * @param items Items to search through
2760
+ * @param key Key to use to stringify items
2761
+ * @returns Fuzzy searcher
2762
+ */
2763
+ declare function fuzzy<Item extends PlainObject, ItemKey extends keyof Item>(items: Item[], key?: ItemKey): Fuzzy<Item>;
2764
+ /**
2765
+ * Create a fuzzy searcher for an array of items
2766
+ * @param items Items to search through
2767
+ * @param handler Handler to stringify items
2768
+ * @returns Fuzzy searcher
2769
+ */
2770
+ declare function fuzzy<Item>(items: Item[], handler?: (item: Item) => string): Fuzzy<Item>;
2771
+ /**
2772
+ * Create a fuzzy searcher for an array of items
2773
+ * @param items Items to search through
2774
+ * @param configuration Fuzzy configuration
2775
+ * @returns Fuzzy searcher
2776
+ */
2777
+ declare function fuzzy<Item>(items: Item[], configuration?: FuzzyConfiguration<Item>): Fuzzy<Item>;
2778
+ //#endregion
2669
2779
  //#region src/string/index.d.ts
2780
+ declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
2781
+ declare function dedent(value: string): string;
2670
2782
  /**
2671
2783
  * Get a new UUID-string _(version 4)_
2672
2784
  * @returns UUID string
@@ -3343,13 +3455,54 @@ declare function isInstanceOf<Instance>(constructor: Constructor<Instance>, valu
3343
3455
  * @returns `true` if the value is a `Key` _(`number` or `string`)_, otherwise `false`
3344
3456
  */
3345
3457
  declare function isKey(value: unknown): value is Key;
3458
+ /**
3459
+ * Is the value not an array or a plain object?
3460
+ * @param value Value to check
3461
+ * @returns `true` if the value is not an array or a plain object, otherwise `false`
3462
+ */
3346
3463
  declare function isNonArrayOrPlainObject<Value>(value: Value): value is Exclude<Value, ArrayOrPlainObject>;
3464
+ /**
3465
+ * Is the value not a constructor function?
3466
+ * @param value Value to check
3467
+ * @returns `true` if the value is not a constructor function, otherwise `false`
3468
+ */
3347
3469
  declare function isNonConstructor<Value>(value: Value): value is Exclude<Value, Constructor>;
3470
+ /**
3471
+ * Is the value not an instance of the constructor?
3472
+ * @param constructor Class constructor
3473
+ * @param value Value to check
3474
+ * @returns `true` if the value is not an instance of the constructor, otherwise `false`
3475
+ */
3348
3476
  declare function isNonInstanceOf<Instance, Value>(constructor: Constructor<Instance>, value: Value): value is Exclude<Value, Instance>;
3477
+ /**
3478
+ * Is the value not a key?
3479
+ * @param value Value to check
3480
+ * @returns `true` if the value is not a `Key` _(`number` or `string`)_, otherwise `false`
3481
+ */
3349
3482
  declare function isNonKey<Value>(value: Value): value is Exclude<Value, Key>;
3483
+ /**
3484
+ * Is the value not a number?
3485
+ * @param value Value to check
3486
+ * @returns `true` if the value is not a `number`, otherwise `false`
3487
+ */
3350
3488
  declare function isNonNumber<Value>(value: Value): value is Exclude<Value, number>;
3489
+ /**
3490
+ * Is the value not a plain object?
3491
+ * @param value Value to check
3492
+ * @returns `true` if the value is not a plain object, otherwise `false`
3493
+ */
3351
3494
  declare function isNonPlainObject<Value>(value: Value): value is Exclude<Value, PlainObject>;
3495
+ /**
3496
+ * Is the value not a primitive value?
3497
+ * @param value Value to check
3498
+ * @returns `true` if the value is not a primitive value, otherwise `false`
3499
+ */
3352
3500
  declare function isNonPrimitive<Value>(value: Value): value is Exclude<Value, Primitive>;
3501
+ /**
3502
+ * Is the value not a typed array?
3503
+ * @param value Value to check
3504
+ * @returns `true` if the value is not a typed array, otherwise `false`
3505
+ */
3353
3506
  declare function isNonTypedArray<Value>(value: Value): value is Exclude<Value, TypedArray>;
3354
3507
  /**
3355
3508
  * Is the value a number?
@@ -4780,4 +4933,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
4780
4933
  get(value: Value, update?: boolean): Value | undefined;
4781
4934
  }
4782
4935
  //#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 };
4936
+ 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, FuzzyConfiguration, FuzzyOptions, FuzzyResult, FuzzySearchOptions, 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, fuzzy, 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 };