complete-common 2.16.1 → 2.18.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.
@@ -4,6 +4,14 @@
4
4
  * @module
5
5
  */
6
6
  import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
7
+ import type { WidenLiteral } from "../types/WidenLiteral.js";
8
+ /**
9
+ * Safely gets a value from a widened object.
10
+ *
11
+ * This is useful when normal indexing produces a type error from an object that uses an `as const`
12
+ * assertion.
13
+ */
14
+ export declare function getWidenedObjectValue<T extends Record<string, unknown>>(object: T, key: WidenLiteral<keyof T>): T[keyof T] | undefined;
7
15
  /**
8
16
  * Helper function to get the values in an object that match an arbitrary condition. Similar to the
9
17
  * `Array.filter` method, but works for objects.
@@ -4,6 +4,14 @@
4
4
  * @module
5
5
  */
6
6
  import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
7
+ import type { WidenLiteral } from "../types/WidenLiteral.js";
8
+ /**
9
+ * Safely gets a value from a widened object.
10
+ *
11
+ * This is useful when normal indexing produces a type error from an object that uses an `as const`
12
+ * assertion.
13
+ */
14
+ export declare function getWidenedObjectValue<T extends Record<string, unknown>>(object: T, key: WidenLiteral<keyof T>): T[keyof T] | undefined;
7
15
  /**
8
16
  * Helper function to get the values in an object that match an arbitrary condition. Similar to the
9
17
  * `Array.filter` method, but works for objects.
@@ -4,6 +4,14 @@
4
4
  * @module
5
5
  */
6
6
  import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
7
+ import type { WidenLiteral } from "../types/WidenLiteral.js";
8
+ /**
9
+ * Safely gets a value from a widened object.
10
+ *
11
+ * This is useful when normal indexing produces a type error from an object that uses an `as const`
12
+ * assertion.
13
+ */
14
+ export declare function getWidenedObjectValue<T extends Record<string, unknown>>(object: T, key: WidenLiteral<keyof T>): T[keyof T] | undefined;
7
15
  /**
8
16
  * Helper function to get the values in an object that match an arbitrary condition. Similar to the
9
17
  * `Array.filter` method, but works for objects.
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/functions/object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAChE,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAC5B,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAC/B,SAAS,CAAC,EAAE,CAad;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC,EAChE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAChC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAOtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,EAC/D,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQzC"}
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/functions/object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EA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C,CAAC,EAAE,CAAC,CAAC,CAQzC"}
package/dist/index.cjs CHANGED
@@ -307,6 +307,10 @@ function clamp(num, min, max) {
307
307
  return Math.max(min, Math.min(num, max));
308
308
  }
309
309
 
310
+ function getWidenedObjectValue(object, key) {
311
+ const widenedObject = object;
312
+ return widenedObject[key];
313
+ }
310
314
  function objectFilter(object, predicate) {
311
315
  const array = [];
312
316
  for (const key in object) {
@@ -672,6 +676,7 @@ exports.getNumConsecutiveDiacritics = getNumConsecutiveDiacritics;
672
676
  exports.getRandomArrayElement = getRandomArrayElement;
673
677
  exports.getRandomArrayIndex = getRandomArrayIndex;
674
678
  exports.getRandomInt = getRandomInt;
679
+ exports.getWidenedObjectValue = getWidenedObjectValue;
675
680
  exports.hasDiacritic = hasDiacritic;
676
681
  exports.hasEmoji = hasEmoji;
677
682
  exports.hasWhitespace = hasWhitespace;
package/dist/index.mjs CHANGED
@@ -305,6 +305,10 @@ function clamp(num, min, max) {
305
305
  return Math.max(min, Math.min(num, max));
306
306
  }
307
307
 
308
+ function getWidenedObjectValue(object, key) {
309
+ const widenedObject = object;
310
+ return widenedObject[key];
311
+ }
308
312
  function objectFilter(object, predicate) {
309
313
  const array = [];
310
314
  for (const key in object) {
@@ -626,4 +630,4 @@ function* tupleKeys(tuple) {
626
630
 
627
631
  const ReadonlyMap = Map;
628
632
 
629
- export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectMap, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
633
+ export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getRandomArrayElement, getRandomArrayIndex, getRandomInt, getWidenedObjectValue, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayString, isEnumValue, isFirstLetterCapitalized, isKebabCase, isKeyOf, isLowerCase, isObject, isSemanticVersion, isUpperCase, kebabCaseToCamelCase, kebabCaseToPascalCase, mapAsync, mapFilter, mapFind, newArray, noop, normalizeString, objectFilter, objectKeysToSet, objectMap, objectToMap, objectToReverseMap, objectValuesToSet, parseFloatSafe, parseIntSafe, parseSemanticVersion, removeLinesBetweenMarkers, removeLinesMatching, removeNonPrintableCharacters, removeWhitespace, repeat, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "complete-common",
3
- "version": "2.16.1",
3
+ "version": "2.18.0",
4
4
  "description": "Helper functions for TypeScript projects.",
5
5
  "homepage": "https://complete-ts.github.io/",
6
6
  "bugs": {
@@ -5,6 +5,21 @@
5
5
  */
6
6
 
7
7
  import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
8
+ import type { WidenLiteral } from "../types/WidenLiteral.js";
9
+
10
+ /**
11
+ * Safely gets a value from a widened object.
12
+ *
13
+ * This is useful when normal indexing produces a type error from an object that uses an `as const`
14
+ * assertion.
15
+ */
16
+ export function getWidenedObjectValue<T extends Record<string, unknown>>(
17
+ object: T,
18
+ key: WidenLiteral<keyof T>,
19
+ ): T[keyof T] | undefined {
20
+ const widenedObject = object as Record<PropertyKey, T[keyof T]>;
21
+ return widenedObject[key as PropertyKey];
22
+ }
8
23
 
9
24
  /**
10
25
  * Helper function to get the values in an object that match an arbitrary condition. Similar to the