@luxass/utils 2.3.0 → 2.4.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/{guards-C19fJmlu.d.ts → guards-x9QZDUSt.d.ts} +1 -2
- package/dist/guards.d.ts +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -5
- package/dist/{number-C2E_sOOy.d.ts → number-DzUC7V5F.d.ts} +1 -2
- package/dist/number.d.ts +1 -1
- package/dist/object-BT3S70pM.d.ts +84 -0
- package/dist/object-CyGLe77G.js +75 -0
- package/dist/object.d.ts +2 -0
- package/dist/object.js +3 -0
- package/dist/{string-CBWIJiC0.d.ts → string-BjsgnDeW.d.ts} +1 -1
- package/dist/string.d.ts +1 -1
- package/dist/{types-QETho94V.d.ts → types-DCrM3M9i.d.ts} +0 -1
- package/dist/types.d.ts +1 -1
- package/package.json +4 -3
|
@@ -55,6 +55,5 @@ declare function isNotUndefined<T>(v: T): v is Exclude<T, undefined>;
|
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
57
|
declare function isTruthy<T>(v: T): v is NonNullable<T>;
|
|
58
|
-
|
|
59
58
|
//#endregion
|
|
60
|
-
export { isNotNull
|
|
59
|
+
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
package/dist/guards.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { isNotNull
|
|
1
|
+
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-x9QZDUSt.js";
|
|
2
2
|
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { isNotNull
|
|
2
|
-
import { clamp
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-x9QZDUSt.js";
|
|
2
|
+
import { clamp } from "./number-DzUC7V5F.js";
|
|
3
|
+
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-BT3S70pM.js";
|
|
4
|
+
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-BjsgnDeW.js";
|
|
5
|
+
import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-DCrM3M9i.js";
|
|
5
6
|
import pRetry from "p-retry";
|
|
6
7
|
|
|
7
8
|
//#region src/common.d.ts
|
|
@@ -19,6 +20,5 @@ declare class InvariantError extends Error {
|
|
|
19
20
|
* @throws {InvariantError} Throws when the predicate is falsy
|
|
20
21
|
*/
|
|
21
22
|
declare function invariant(predicate: unknown, message: string, ...positionals: unknown[]): asserts predicate;
|
|
22
|
-
|
|
23
23
|
//#endregion
|
|
24
|
-
export { ElementOf, InferArguments, InvariantError, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, capitalize, clamp, dedent, dedentRaw, formatStr, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
24
|
+
export { ElementOf, InferArguments, InvariantError, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, capitalize, clamp, dedent, dedentRaw, formatStr, getChangedKeys, getOwnProperty, hasOwnProperty, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, omit, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-O1HGJraI.js";
|
|
2
2
|
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-pQApOGKP.js";
|
|
3
3
|
import { clamp } from "./number-BS9T5WGO.js";
|
|
4
|
+
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-CyGLe77G.js";
|
|
4
5
|
|
|
5
6
|
//#region rolldown:runtime
|
|
6
7
|
var __create = Object.create;
|
|
@@ -82,10 +83,10 @@ var require_retry_operation = __commonJS({ "node_modules/.pnpm/retry@0.13.1/node
|
|
|
82
83
|
RetryOperation$1.prototype.retry = function(err) {
|
|
83
84
|
if (this._timeout) clearTimeout(this._timeout);
|
|
84
85
|
if (!err) return false;
|
|
85
|
-
var currentTime = new Date().getTime();
|
|
86
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
86
87
|
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
87
88
|
this._errors.push(err);
|
|
88
|
-
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
89
|
+
this._errors.unshift(/* @__PURE__ */ new Error("RetryOperation timeout occurred"));
|
|
89
90
|
return false;
|
|
90
91
|
}
|
|
91
92
|
this._errors.push(err);
|
|
@@ -118,7 +119,7 @@ var require_retry_operation = __commonJS({ "node_modules/.pnpm/retry@0.13.1/node
|
|
|
118
119
|
if (this._operationTimeoutCb) this._timeout = setTimeout(function() {
|
|
119
120
|
self._operationTimeoutCb();
|
|
120
121
|
}, self._operationTimeout);
|
|
121
|
-
this._operationStart = new Date().getTime();
|
|
122
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
122
123
|
this._fn(this._attempts);
|
|
123
124
|
};
|
|
124
125
|
RetryOperation$1.prototype.try = function(fn) {
|
|
@@ -278,7 +279,7 @@ async function pRetry(input, options) {
|
|
|
278
279
|
options.onFailedAttempt ??= () => {};
|
|
279
280
|
options.shouldRetry ??= () => true;
|
|
280
281
|
options.retries ??= 10;
|
|
281
|
-
const operation = import_retry.
|
|
282
|
+
const operation = import_retry.operation(options);
|
|
282
283
|
const abortHandler = () => {
|
|
283
284
|
operation.stop();
|
|
284
285
|
reject(options.signal?.reason);
|
|
@@ -316,4 +317,4 @@ async function pRetry(input, options) {
|
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
//#endregion
|
|
319
|
-
export { InvariantError, capitalize, clamp, dedent, dedentRaw, formatStr, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
320
|
+
export { InvariantError, capitalize, clamp, dedent, dedentRaw, formatStr, getChangedKeys, getOwnProperty, hasOwnProperty, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, omit, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
package/dist/number.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { clamp
|
|
1
|
+
import { clamp } from "./number-DzUC7V5F.js";
|
|
2
2
|
export { clamp };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//#region src/object.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if an object has a specific property as its own property (not inherited).
|
|
4
|
+
*
|
|
5
|
+
* @param {object} obj - The object to check
|
|
6
|
+
* @param {string} key - The property key to check for
|
|
7
|
+
* @returns {boolean} `true` if the object has the property as its own property, `false` otherwise
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { hasOwnProperty } from '@luxass/utils/object';
|
|
12
|
+
*
|
|
13
|
+
* const obj = { name: 'John' };
|
|
14
|
+
* hasOwnProperty(obj, 'name'); // true
|
|
15
|
+
* hasOwnProperty(obj, 'toString'); // false (inherited)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function hasOwnProperty(obj: object, key: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Safely gets an own property value from an object, returning undefined if the property doesn't exist.
|
|
21
|
+
*
|
|
22
|
+
* This function provides type-safe property access with multiple overloads:
|
|
23
|
+
* - For objects with known key-value types, returns the value type or undefined
|
|
24
|
+
* - For generic objects, returns the property value type or undefined
|
|
25
|
+
* - Fallback returns unknown type
|
|
26
|
+
*
|
|
27
|
+
* @param {object} obj - The object to get the property from
|
|
28
|
+
* @param {string} key - The property key to retrieve
|
|
29
|
+
* @returns {unknown} The property value if it exists as an own property, undefined otherwise
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { getOwnProperty } from '@luxass/utils/object';
|
|
34
|
+
*
|
|
35
|
+
* const obj = { name: 'John', age: 30 };
|
|
36
|
+
* getOwnProperty(obj, 'name'); // 'John'
|
|
37
|
+
* getOwnProperty(obj, 'missing'); // undefined
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function getOwnProperty<K extends string, V>(obj: Partial<Record<K, V>>, key: K): V | undefined;
|
|
41
|
+
declare function getOwnProperty<O extends object>(obj: O, key: string): O[keyof O] | undefined;
|
|
42
|
+
declare function getOwnProperty(obj: object, key: string): unknown;
|
|
43
|
+
/**
|
|
44
|
+
* Compares two objects and returns an array of keys where the values differ.
|
|
45
|
+
*
|
|
46
|
+
* Uses Object.is() for comparison, which handles special cases like NaN and -0/+0 correctly.
|
|
47
|
+
* Only checks keys that exist in the first object.
|
|
48
|
+
*
|
|
49
|
+
* @template T - The type of objects being compared
|
|
50
|
+
* @param {T} obj1 - The first object to compare
|
|
51
|
+
* @param {T} obj2 - The second object to compare
|
|
52
|
+
* @returns {(keyof T)[]} An array of keys where the values differ between the two objects
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { getChangedKeys } from '@luxass/utils/object';
|
|
57
|
+
*
|
|
58
|
+
* const obj1 = { name: 'John', age: 30, city: 'NYC' };
|
|
59
|
+
* const obj2 = { name: 'John', age: 31, city: 'NYC' };
|
|
60
|
+
* getChangedKeys(obj1, obj2); // ['age']
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function getChangedKeys<T extends object>(obj1: T, obj2: T): (keyof T)[];
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new object with specified keys omitted from the original object.
|
|
66
|
+
*
|
|
67
|
+
* This function creates a shallow copy of the input object and removes the specified keys.
|
|
68
|
+
* The original object is not modified.
|
|
69
|
+
*
|
|
70
|
+
* @param {Record<string, unknown>} obj - The source object to omit keys from
|
|
71
|
+
* @param {ReadonlyArray<string>} keys - An array of key names to omit from the object
|
|
72
|
+
* @returns {Record<string, unknown>} A new object with the specified keys removed
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { omit } from '@luxass/utils/object';
|
|
77
|
+
*
|
|
78
|
+
* const obj = { name: 'John', age: 30, city: 'NYC', country: 'USA' };
|
|
79
|
+
* omit(obj, ['age', 'country']); // { name: 'John', city: 'NYC' }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function omit(obj: Record<string, unknown>, keys: ReadonlyArray<string>): Record<string, unknown>;
|
|
83
|
+
//#endregion
|
|
84
|
+
export { getChangedKeys, getOwnProperty, hasOwnProperty, omit };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/object.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if an object has a specific property as its own property (not inherited).
|
|
4
|
+
*
|
|
5
|
+
* @param {object} obj - The object to check
|
|
6
|
+
* @param {string} key - The property key to check for
|
|
7
|
+
* @returns {boolean} `true` if the object has the property as its own property, `false` otherwise
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { hasOwnProperty } from '@luxass/utils/object';
|
|
12
|
+
*
|
|
13
|
+
* const obj = { name: 'John' };
|
|
14
|
+
* hasOwnProperty(obj, 'name'); // true
|
|
15
|
+
* hasOwnProperty(obj, 'toString'); // false (inherited)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function hasOwnProperty(obj, key) {
|
|
19
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
20
|
+
}
|
|
21
|
+
function getOwnProperty(obj, key) {
|
|
22
|
+
if (!hasOwnProperty(obj, key)) return void 0;
|
|
23
|
+
return obj[key];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Compares two objects and returns an array of keys where the values differ.
|
|
27
|
+
*
|
|
28
|
+
* Uses Object.is() for comparison, which handles special cases like NaN and -0/+0 correctly.
|
|
29
|
+
* Only checks keys that exist in the first object.
|
|
30
|
+
*
|
|
31
|
+
* @template T - The type of objects being compared
|
|
32
|
+
* @param {T} obj1 - The first object to compare
|
|
33
|
+
* @param {T} obj2 - The second object to compare
|
|
34
|
+
* @returns {(keyof T)[]} An array of keys where the values differ between the two objects
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { getChangedKeys } from '@luxass/utils/object';
|
|
39
|
+
*
|
|
40
|
+
* const obj1 = { name: 'John', age: 30, city: 'NYC' };
|
|
41
|
+
* const obj2 = { name: 'John', age: 31, city: 'NYC' };
|
|
42
|
+
* getChangedKeys(obj1, obj2); // ['age']
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function getChangedKeys(obj1, obj2) {
|
|
46
|
+
const result = [];
|
|
47
|
+
for (const key in obj1) if (!Object.is(obj1[key], obj2[key])) result.push(key);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new object with specified keys omitted from the original object.
|
|
52
|
+
*
|
|
53
|
+
* This function creates a shallow copy of the input object and removes the specified keys.
|
|
54
|
+
* The original object is not modified.
|
|
55
|
+
*
|
|
56
|
+
* @param {Record<string, unknown>} obj - The source object to omit keys from
|
|
57
|
+
* @param {ReadonlyArray<string>} keys - An array of key names to omit from the object
|
|
58
|
+
* @returns {Record<string, unknown>} A new object with the specified keys removed
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { omit } from '@luxass/utils/object';
|
|
63
|
+
*
|
|
64
|
+
* const obj = { name: 'John', age: 30, city: 'NYC', country: 'USA' };
|
|
65
|
+
* omit(obj, ['age', 'country']); // { name: 'John', city: 'NYC' }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
function omit(obj, keys) {
|
|
69
|
+
const result = { ...obj };
|
|
70
|
+
for (const key of keys) delete result[key];
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { getChangedKeys, getOwnProperty, hasOwnProperty, omit };
|
package/dist/object.d.ts
ADDED
package/dist/object.js
ADDED
|
@@ -129,4 +129,4 @@ declare function sanitizeIdentifier(str: string): string;
|
|
|
129
129
|
*/
|
|
130
130
|
declare function formatStr(message: string, ...positionals: unknown[]): string;
|
|
131
131
|
//#endregion
|
|
132
|
-
export { capitalize
|
|
132
|
+
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
package/dist/string.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { capitalize
|
|
1
|
+
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-BjsgnDeW.js";
|
|
2
2
|
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
@@ -82,6 +82,5 @@ type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
84
|
type RemoveIndexSignature<T> = { [K in keyof T as {} extends Record<K, 1> ? never : K]: T[K] };
|
|
85
|
-
|
|
86
85
|
//#endregion
|
|
87
86
|
export { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-
|
|
1
|
+
import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-DCrM3M9i.js";
|
|
2
2
|
export { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A collection of utilities for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"exports": {
|
|
25
25
|
".": "./dist/index.js",
|
|
26
|
-
"./string": "./dist/string.js",
|
|
27
26
|
"./guards": "./dist/guards.js",
|
|
28
27
|
"./number": "./dist/number.js",
|
|
28
|
+
"./object": "./dist/object.js",
|
|
29
|
+
"./string": "./dist/string.js",
|
|
29
30
|
"./types": "./dist/types.js",
|
|
30
31
|
"./package.json": "./package.json"
|
|
31
32
|
},
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"eslint": "^9.27.0",
|
|
49
50
|
"eslint-plugin-format": "^1.0.1",
|
|
50
51
|
"publint": "^0.3.12",
|
|
51
|
-
"tsdown": "^0.
|
|
52
|
+
"tsdown": "^0.12.9",
|
|
52
53
|
"typescript": "^5.8.3",
|
|
53
54
|
"vitest": "^3.1.4",
|
|
54
55
|
"vitest-package-exports": "^0.1.1"
|