complete-common 2.31.0 → 2.32.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/functions/object.d.cts +16 -0
- package/dist/functions/object.d.mts +16 -0
- package/dist/functions/object.d.ts +16 -0
- package/dist/functions/object.d.ts.map +1 -1
- package/dist/functions/time.d.cts +2 -1
- package/dist/functions/time.d.mts +2 -1
- package/dist/functions/time.d.ts +2 -1
- package/dist/functions/time.d.ts.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.mjs +7 -1
- package/package.json +2 -2
- package/src/functions/object.ts +28 -0
- package/src/functions/time.ts +2 -1
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
8
|
+
/**
|
|
9
|
+
* Helper function to get the keys and values of an object with their literal key types preserved.
|
|
10
|
+
*
|
|
11
|
+
* This is a typed wrapper around `Object.entries`. The type assertion is necessary because
|
|
12
|
+
* TypeScript defines the keys from `Object.entries` as being `string[]`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getObjectEntries<const T extends object>(object: T): ReadonlyArray<{
|
|
15
|
+
[K in keyof T]: [K, T[K]];
|
|
16
|
+
}[keyof T]>;
|
|
17
|
+
/**
|
|
18
|
+
* Helper function to get keys of an object with their literal key types preserved.
|
|
19
|
+
*
|
|
20
|
+
* This is a typed wrapper around `Object.keys`. The type assertion is necessary because TypeScript
|
|
21
|
+
* defines `Object.keys` as returning `string[]`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getObjectKeys<const T extends object>(object: T): ReadonlyArray<keyof T>;
|
|
8
24
|
/**
|
|
9
25
|
* Safely gets a value from a widened object.
|
|
10
26
|
*
|
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
8
|
+
/**
|
|
9
|
+
* Helper function to get the keys and values of an object with their literal key types preserved.
|
|
10
|
+
*
|
|
11
|
+
* This is a typed wrapper around `Object.entries`. The type assertion is necessary because
|
|
12
|
+
* TypeScript defines the keys from `Object.entries` as being `string[]`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getObjectEntries<const T extends object>(object: T): ReadonlyArray<{
|
|
15
|
+
[K in keyof T]: [K, T[K]];
|
|
16
|
+
}[keyof T]>;
|
|
17
|
+
/**
|
|
18
|
+
* Helper function to get keys of an object with their literal key types preserved.
|
|
19
|
+
*
|
|
20
|
+
* This is a typed wrapper around `Object.keys`. The type assertion is necessary because TypeScript
|
|
21
|
+
* defines `Object.keys` as returning `string[]`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getObjectKeys<const T extends object>(object: T): ReadonlyArray<keyof T>;
|
|
8
24
|
/**
|
|
9
25
|
* Safely gets a value from a widened object.
|
|
10
26
|
*
|
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
7
7
|
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
8
|
+
/**
|
|
9
|
+
* Helper function to get the keys and values of an object with their literal key types preserved.
|
|
10
|
+
*
|
|
11
|
+
* This is a typed wrapper around `Object.entries`. The type assertion is necessary because
|
|
12
|
+
* TypeScript defines the keys from `Object.entries` as being `string[]`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getObjectEntries<const T extends object>(object: T): ReadonlyArray<{
|
|
15
|
+
[K in keyof T]: [K, T[K]];
|
|
16
|
+
}[keyof T]>;
|
|
17
|
+
/**
|
|
18
|
+
* Helper function to get keys of an object with their literal key types preserved.
|
|
19
|
+
*
|
|
20
|
+
* This is a typed wrapper around `Object.keys`. The type assertion is necessary because TypeScript
|
|
21
|
+
* defines `Object.keys` as returning `string[]`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getObjectKeys<const T extends object>(object: T): ReadonlyArray<keyof T>;
|
|
8
24
|
/**
|
|
9
25
|
* Safely gets a value from a widened object.
|
|
10
26
|
*
|
|
@@ -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;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrE,MAAM,EAAE,CAAC,EACT,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,GACzB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAGxB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,EACnD,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,WAAW,EAAE,CAAC,EAAE,CAAC,EACnD,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,WAAW,EAAE,CAAC,EAClD,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQnB;AAED;;;;;GA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CAAC,EACnD,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,WAAW,EAAE,CAAC,EAAE,CAAC,EACnD,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,WAAW,EAAE,CAAC,EAClD,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACnB,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,WAAW,EACrB,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAQzC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,WAAW,EACxE,GAAG,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAChB,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAStB"}
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Helper function to get the number of elapsed seconds since a starting time.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* By default, this function will return a whole number (using `Math.floor` on the result), but this
|
|
10
|
+
* can be disabled with the "roundToInteger" parameter.
|
|
10
11
|
*
|
|
11
12
|
* For example:
|
|
12
13
|
*
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Helper function to get the number of elapsed seconds since a starting time.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* By default, this function will return a whole number (using `Math.floor` on the result), but this
|
|
10
|
+
* can be disabled with the "roundToInteger" parameter.
|
|
10
11
|
*
|
|
11
12
|
* For example:
|
|
12
13
|
*
|
package/dist/functions/time.d.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* Helper function to get the number of elapsed seconds since a starting time.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* By default, this function will return a whole number (using `Math.floor` on the result), but this
|
|
10
|
+
* can be disabled with the "roundToInteger" parameter.
|
|
10
11
|
*
|
|
11
12
|
* For example:
|
|
12
13
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/functions/time.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/functions/time.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,cAAc,UAAO,GACpB,MAAM,CAMR"}
|
package/dist/index.cjs
CHANGED
|
@@ -333,6 +333,12 @@ function clamp(num, min, max) {
|
|
|
333
333
|
return Math.max(min, Math.min(num, max));
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
function getObjectEntries(object) {
|
|
337
|
+
return Object.entries(object);
|
|
338
|
+
}
|
|
339
|
+
function getObjectKeys(object) {
|
|
340
|
+
return Object.keys(object);
|
|
341
|
+
}
|
|
336
342
|
function getWidenedObjectValue(object, key) {
|
|
337
343
|
const widenedObject = object;
|
|
338
344
|
return widenedObject[key];
|
|
@@ -726,6 +732,8 @@ exports.getEnumEntries = getEnumEntries;
|
|
|
726
732
|
exports.getEnumKeys = getEnumKeys;
|
|
727
733
|
exports.getEnumValues = getEnumValues;
|
|
728
734
|
exports.getNumConsecutiveDiacritics = getNumConsecutiveDiacritics;
|
|
735
|
+
exports.getObjectEntries = getObjectEntries;
|
|
736
|
+
exports.getObjectKeys = getObjectKeys;
|
|
729
737
|
exports.getRandomArrayElement = getRandomArrayElement;
|
|
730
738
|
exports.getRandomArrayIndex = getRandomArrayIndex;
|
|
731
739
|
exports.getRandomInt = getRandomInt;
|
package/dist/index.mjs
CHANGED
|
@@ -331,6 +331,12 @@ function clamp(num, min, max) {
|
|
|
331
331
|
return Math.max(min, Math.min(num, max));
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
+
function getObjectEntries(object) {
|
|
335
|
+
return Object.entries(object);
|
|
336
|
+
}
|
|
337
|
+
function getObjectKeys(object) {
|
|
338
|
+
return Object.keys(object);
|
|
339
|
+
}
|
|
334
340
|
function getWidenedObjectValue(object, key) {
|
|
335
341
|
const widenedObject = object;
|
|
336
342
|
return widenedObject[key];
|
|
@@ -680,4 +686,4 @@ function* tupleKeys(tuple) {
|
|
|
680
686
|
|
|
681
687
|
const ReadonlyMap = Map;
|
|
682
688
|
|
|
683
|
-
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayLength, assertArrayNonEmpty, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertPositiveInteger, 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, isArrayObject, 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, reverseObject, satisfiesSemanticVersion, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys, unique };
|
|
689
|
+
export { HOUR_IN_MILLISECONDS, MINUTE_IN_MILLISECONDS, ReadonlyMap, ReadonlySet, SECOND_IN_MILLISECONDS, addSetsToSet, arrayCopyTwoDimensional, arrayEquals, arrayRemove, arrayRemoveAllInPlace, arrayRemoveInPlace, assertArray, assertArrayBoolean, assertArrayLength, assertArrayNonEmpty, assertArrayNumber, assertArrayObject, assertArrayString, assertBoolean, assertDefined, assertEnumValue, assertInteger, assertIs, assertNotNull, assertNumber, assertObject, assertPositiveInteger, assertString, assertStringNotEmpty, capitalizeFirstLetter, clamp, combineSets, copySet, eRange, emptyArray, escapeHTMLCharacters, filterAsync, filterMap, filterMapAsync, getElapsedSeconds, getEnumEntries, getEnumKeys, getEnumValues, getNumConsecutiveDiacritics, getObjectEntries, getObjectKeys, getRandomArrayElement, getRandomArrayIndex, getRandomInt, getWidenedObjectValue, hasDiacritic, hasEmoji, hasWhitespace, iRange, includes, includesAny, interfaceSatisfiesEnum, isASCII, isArray, isArrayBoolean, isArrayNumber, isArrayObject, 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, reverseObject, satisfiesSemanticVersion, setAdd, setHas, sortCaseInsensitive, sumArray, titleCaseToKebabCase, todo, trimPrefix, trimSuffix, truncateString, tupleEntries, tupleKeys, unique };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "complete-common",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.32.0",
|
|
4
4
|
"description": "Helper functions for TypeScript projects.",
|
|
5
5
|
"homepage": "https://complete-ts.github.io/",
|
|
6
6
|
"bugs": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test": "bun test ./tests"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/node": "26.0
|
|
35
|
+
"@types/node": "26.1.0",
|
|
36
36
|
"complete-node": "18.0.0",
|
|
37
37
|
"typedoc": "0.28.19",
|
|
38
38
|
"typedoc-plugin-markdown": "4.12.0",
|
package/src/functions/object.ts
CHANGED
|
@@ -7,6 +7,34 @@
|
|
|
7
7
|
import type { ReadonlyRecord } from "../types/ReadonlyRecord.js";
|
|
8
8
|
import type { WidenLiteral } from "../types/WidenLiteral.js";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to get the keys and values of an object with their literal key types preserved.
|
|
12
|
+
*
|
|
13
|
+
* This is a typed wrapper around `Object.entries`. The type assertion is necessary because
|
|
14
|
+
* TypeScript defines the keys from `Object.entries` as being `string[]`.
|
|
15
|
+
*/
|
|
16
|
+
export function getObjectEntries<const T extends object>(
|
|
17
|
+
object: T,
|
|
18
|
+
): ReadonlyArray<{ [K in keyof T]: [K, T[K]] }[keyof T]> {
|
|
19
|
+
return Object.entries(object) as Array<
|
|
20
|
+
{
|
|
21
|
+
[K in keyof T]: [K, T[K]];
|
|
22
|
+
}[keyof T]
|
|
23
|
+
>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Helper function to get keys of an object with their literal key types preserved.
|
|
28
|
+
*
|
|
29
|
+
* This is a typed wrapper around `Object.keys`. The type assertion is necessary because TypeScript
|
|
30
|
+
* defines `Object.keys` as returning `string[]`.
|
|
31
|
+
*/
|
|
32
|
+
export function getObjectKeys<const T extends object>(
|
|
33
|
+
object: T,
|
|
34
|
+
): ReadonlyArray<keyof T> {
|
|
35
|
+
return Object.keys(object) as Array<keyof T>;
|
|
36
|
+
}
|
|
37
|
+
|
|
10
38
|
/**
|
|
11
39
|
* Safely gets a value from a widened object.
|
|
12
40
|
*
|
package/src/functions/time.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Helper function to get the number of elapsed seconds since a starting time.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* By default, this function will return a whole number (using `Math.floor` on the result), but this
|
|
11
|
+
* can be disabled with the "roundToInteger" parameter.
|
|
11
12
|
*
|
|
12
13
|
* For example:
|
|
13
14
|
*
|