@oscarpalmer/atoms 0.175.0 → 0.176.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/index.d.mts CHANGED
@@ -2552,6 +2552,30 @@ declare function registerCloner<Instance>(constructor: Constructor<Instance>, ha
2552
2552
  */
2553
2553
  declare function unregisterCloner<Instance>(constructor: Constructor<Instance>): void;
2554
2554
  //#endregion
2555
+ //#region src/value/collection.d.ts
2556
+ /**
2557
+ * Does the value exist for a key in a map?
2558
+ * @param map Map to check in
2559
+ * @param value Value to check for
2560
+ * @returns `true` if the value exists, otherwise `false`
2561
+ */
2562
+ declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
2563
+ /**
2564
+ * Does the value exist for a key in a map?
2565
+ * @param map Map to check in
2566
+ * @param value Value to check for
2567
+ * @param key To return the key for the value
2568
+ * @return The key for the value if it exists, otherwise `undefined`
2569
+ */
2570
+ declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
2571
+ /**
2572
+ * Does the value exist in a set?
2573
+ * @param set Set to check in
2574
+ * @param value Value to check for
2575
+ * @returns `true` if the value exists, otherwise `false`
2576
+ */
2577
+ declare function inSet<Value>(set: Set<Value>, value: Value): boolean;
2578
+ //#endregion
2555
2579
  //#region src/value/diff.d.ts
2556
2580
  /**
2557
2581
  * Options for value comparison
@@ -4483,4 +4507,4 @@ declare class SizedSet<Value = unknown> extends Set<Value> {
4483
4507
  get(value: Value, update?: boolean): Value | undefined;
4484
4508
  }
4485
4509
  //#endregion
4486
- 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, 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, 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, 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, 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 };
4510
+ 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, 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, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, 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, 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
@@ -2464,6 +2464,26 @@ function tryStructuredClone(value, depth, references) {
2464
2464
  }
2465
2465
  const MAX_CLONE_DEPTH = 100;
2466
2466
  //#endregion
2467
+ //#region src/value/collection.ts
2468
+ function inMap(map, value, key) {
2469
+ const getKey = key === true;
2470
+ if (!(map instanceof Map)) return getKey ? void 0 : false;
2471
+ if (!getKey) return inSet(new Set(map.values()), value);
2472
+ for (const [key, item] of map) if (equal(item, value)) return key;
2473
+ }
2474
+ /**
2475
+ * Does the value exist in a set?
2476
+ * @param set Set to check in
2477
+ * @param value Value to check for
2478
+ * @returns `true` if the value exists, otherwise `false`
2479
+ */
2480
+ function inSet(set, value) {
2481
+ if (!(set instanceof Set)) return false;
2482
+ if (set.has(value)) return true;
2483
+ for (const item of set) if (equal(item, value)) return true;
2484
+ return false;
2485
+ }
2486
+ //#endregion
2467
2487
  //#region src/value/diff.ts
2468
2488
  /**
2469
2489
  * Find the differences between two values
@@ -4588,4 +4608,4 @@ var SizedSet = class extends Set {
4588
4608
  }
4589
4609
  };
4590
4610
  //#endregion
4591
- 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, 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, 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, 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, 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 };
4611
+ 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, 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, isNonNullable, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, 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, 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 };
@@ -0,0 +1,25 @@
1
+ //#region src/value/collection.d.ts
2
+ /**
3
+ * Does the value exist for a key in a map?
4
+ * @param map Map to check in
5
+ * @param value Value to check for
6
+ * @returns `true` if the value exists, otherwise `false`
7
+ */
8
+ declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
9
+ /**
10
+ * Does the value exist for a key in a map?
11
+ * @param map Map to check in
12
+ * @param value Value to check for
13
+ * @param key To return the key for the value
14
+ * @return The key for the value if it exists, otherwise `undefined`
15
+ */
16
+ declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
17
+ /**
18
+ * Does the value exist in a set?
19
+ * @param set Set to check in
20
+ * @param value Value to check for
21
+ * @returns `true` if the value exists, otherwise `false`
22
+ */
23
+ declare function inSet<Value>(set: Set<Value>, value: Value): boolean;
24
+ //#endregion
25
+ export { inMap, inSet };
@@ -0,0 +1,22 @@
1
+ import { equal } from "../internal/value/equal.mjs";
2
+ //#region src/value/collection.ts
3
+ function inMap(map, value, key) {
4
+ const getKey = key === true;
5
+ if (!(map instanceof Map)) return getKey ? void 0 : false;
6
+ if (!getKey) return inSet(new Set(map.values()), value);
7
+ for (const [key, item] of map) if (equal(item, value)) return key;
8
+ }
9
+ /**
10
+ * Does the value exist in a set?
11
+ * @param set Set to check in
12
+ * @param value Value to check for
13
+ * @returns `true` if the value exists, otherwise `false`
14
+ */
15
+ function inSet(set, value) {
16
+ if (!(set instanceof Set)) return false;
17
+ if (set.has(value)) return true;
18
+ for (const item of set) if (equal(item, value)) return true;
19
+ return false;
20
+ }
21
+ //#endregion
22
+ export { inMap, inSet };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.175.0",
3
+ "version": "0.176.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "helper",
@@ -200,6 +200,10 @@
200
200
  "types": "./dist/value/clone.d.mts",
201
201
  "default": "./dist/value/clone.mjs"
202
202
  },
203
+ "./value/collection": {
204
+ "types": "./dist/value/collection.d.mts",
205
+ "default": "./dist/value/collection.mjs"
206
+ },
203
207
  "./value/compare": {
204
208
  "types": "./dist/internal/value/compare.d.mts",
205
209
  "default": "./dist/internal/value/compare.mjs"
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ export * from './string/match';
29
29
  export * from './string/template';
30
30
 
31
31
  export * from './value/clone';
32
+ export * from './value/collection';
32
33
  export * from './value/diff';
33
34
  export * from './value/index';
34
35
  export * from './value/merge';
@@ -0,0 +1,60 @@
1
+ import {equal} from '../internal/value/equal';
2
+
3
+ /**
4
+ * Does the value exist for a key in a map?
5
+ * @param map Map to check in
6
+ * @param value Value to check for
7
+ * @returns `true` if the value exists, otherwise `false`
8
+ */
9
+ export function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
10
+
11
+ /**
12
+ * Does the value exist for a key in a map?
13
+ * @param map Map to check in
14
+ * @param value Value to check for
15
+ * @param key To return the key for the value
16
+ * @return The key for the value if it exists, otherwise `undefined`
17
+ */
18
+ export function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
19
+
20
+ export function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key?: unknown): unknown {
21
+ const getKey = key === true;
22
+
23
+ if (!(map instanceof Map)) {
24
+ return getKey ? undefined : false;
25
+ }
26
+
27
+ if (!getKey) {
28
+ return inSet(new Set(map.values()), value);
29
+ }
30
+
31
+ for (const [key, item] of map) {
32
+ if (equal(item, value)) {
33
+ return key;
34
+ }
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Does the value exist in a set?
40
+ * @param set Set to check in
41
+ * @param value Value to check for
42
+ * @returns `true` if the value exists, otherwise `false`
43
+ */
44
+ export function inSet<Value>(set: Set<Value>, value: Value): boolean {
45
+ if (!(set instanceof Set)) {
46
+ return false;
47
+ }
48
+
49
+ if (set.has(value)) {
50
+ return true;
51
+ }
52
+
53
+ for (const item of set) {
54
+ if (equal(item, value)) {
55
+ return true;
56
+ }
57
+ }
58
+
59
+ return false;
60
+ }