@creejs/commons-lang 2.1.10 → 2.1.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creejs/commons-lang",
3
- "version": "2.1.10",
3
+ "version": "2.1.12",
4
4
  "description": "Commons Utils About Language, used inside creejs",
5
5
  "keywords": [
6
6
  "commons",
@@ -0,0 +1,39 @@
1
+ declare namespace _default {
2
+ export { first };
3
+ export { last };
4
+ export { equals };
5
+ export { equalsIgnoreOrder };
6
+ }
7
+ export default _default;
8
+ /**
9
+ * Gets the first element of an array
10
+ * @param {any[]} arr - The input array
11
+ * @param {any} [defaultValue] - The value to return if the array is empty or first element is undefined/null.
12
+ * @returns {any} The first element of the array, or the defaultValue if the array is empty or not an array.
13
+ * @throws {Error} if arr is not an array
14
+ */
15
+ export function first(arr: any[], defaultValue?: any): any;
16
+ /**
17
+ * Gets the last element of an array
18
+ * @param {any[]} arr - The input array
19
+ * @param {any} [defaultValue] - The value to return if the array is empty or last element is undefined/null
20
+ * @returns {any} The last element of the array or the defaultValue
21
+ * @throws {Error} if arr is not an array
22
+ */
23
+ export function last(arr: any[], defaultValue?: any): any;
24
+ /**
25
+ * Checks if two arrays are equal by order
26
+ * @param {any[]} arr1 - first array to compare
27
+ * @param {any[]} arr2 - Second array to compare
28
+ * @param {(a:any, b:any) => 0|1|-1} [compareFn]
29
+ * @returns {boolean} True if arrays have same elements (order-independent), false otherwise
30
+ */
31
+ export function equals(arr1: any[], arr2: any[], compareFn?: (a: any, b: any) => 0 | 1 | -1): boolean;
32
+ /**
33
+ * Checks if two arrays are equal ignoring element order
34
+ * @param {any[]} arr1 - first array to compare
35
+ * @param {any[]} arr2 - Second array to compare
36
+ * @param {(a:any, b:any) => 0|1|-1} [compareFn]
37
+ * @returns {boolean} True if arrays have same elements (order-independent), false otherwise
38
+ */
39
+ export function equalsIgnoreOrder(arr1: any[], arr2: any[], compareFn?: (a: any, b: any) => 0 | 1 | -1): boolean;
package/types/index.d.ts CHANGED
@@ -13,6 +13,8 @@ declare namespace _default {
13
13
  export { ReflectUtils };
14
14
  export { TypedArrayUtils };
15
15
  export { ArrayBufferUtils };
16
+ export { TimeUtils };
17
+ export { ArrayUtils };
16
18
  }
17
19
  export default _default;
18
20
  import LangUtils from './lang-utils.js';
@@ -26,4 +28,6 @@ import InstanceProxyUtils from './instance-proxy-utils.js';
26
28
  import ReflectUtils from './reflect-utils.js';
27
29
  import TypedArrayUtils from './typed-array-utils.js';
28
30
  import ArrayBufferUtils from './array-buffer-utils.js';
29
- export { LangUtils, StringUtils, TypeUtils, TypeAssert, ExecUtils, PromiseUtils, LangUtils as Lang, TypeUtils as Type, ExecUtils as Exec, ClassProxyUtils, InstanceProxyUtils, ReflectUtils, TypedArrayUtils, ArrayBufferUtils };
31
+ import TimeUtils from './time-utils.js';
32
+ import ArrayUtils from './array-utils.js';
33
+ export { LangUtils, StringUtils, TypeUtils, TypeAssert, ExecUtils, PromiseUtils, LangUtils as Lang, TypeUtils as Type, ExecUtils as Exec, ClassProxyUtils, InstanceProxyUtils, ReflectUtils, TypedArrayUtils, ArrayBufferUtils, TimeUtils, ArrayUtils };
@@ -0,0 +1,46 @@
1
+ declare namespace _default {
2
+ export { s2ns };
3
+ export { ms2ns };
4
+ export { timestamp64 };
5
+ export { lapseNano };
6
+ export { lapseMillis };
7
+ export { timeoutNano };
8
+ export { timeoutMillis };
9
+ }
10
+ export default _default;
11
+ export const s2ns: 1000000000;
12
+ export const ms2ns: 1000000;
13
+ /**
14
+ * Gets the current timestamp in nanoseconds (if running in Node.js) or milliseconds (in browser).
15
+ * Uses `process.hrtime.bigint()` for high-resolution timestamps in Node.js, falls back to `Date.now()` in browsers.
16
+ * @returns {bigint} Current timestamp as a BigInt
17
+ */
18
+ export function timestamp64(): bigint;
19
+ /**
20
+ * Calculates the time elapsed in nanoseconds between the given timestamp and now.
21
+ * @param {bigint} start - start timestamp64, in nanoseconds.
22
+ * @param {bigint} [end] - end timestamp64, in nanoseconds. If not provided, uses current timestamp64.
23
+ * @returns {bigint} The elapsed time in nanoseconds (current timestamp64 - ts64).
24
+ */
25
+ export function lapseNano(start: bigint, end?: bigint): bigint;
26
+ /**
27
+ * Calculates the time elapsed in milliseconds between the given timestamp and now.
28
+ * @param {bigint} start - start The timestamp in 64-bit format.
29
+ * @param {bigint} [end] - end timestamp64, in nanoseconds. If not provided, uses current timestamp64.
30
+ * @returns {bigint} The elapsed time in milliseconds.
31
+ */
32
+ export function lapseMillis(start: bigint, end?: bigint): bigint;
33
+ /**
34
+ * compare current timestamp64 against the given ts64, and check if the elapsed time exceeds the specified timeout.
35
+ * @param {bigint} nanoTimestamp64 - The timestamp to compare against (in nanoseconds).
36
+ * @param {bigint|number} nanoTimeout - The timeout threshold (in nanoseconds).
37
+ * @returns {boolean} True if elapsed time exceeds timeout, false otherwise.
38
+ */
39
+ export function timeoutNano(nanoTimestamp64: bigint, nanoTimeout: bigint | number): boolean;
40
+ /**
41
+ * compare current timestamp64 against the given ts64, and check if the elapsed time exceeds the specified timeout.
42
+ * @param {bigint} nanoTimestamp64 - The timestamp to compare against (in nanoseconds).
43
+ * @param {bigint|number} millisTimeout - The timeout threshold (in milliseconds).
44
+ * @returns {boolean} True if elapsed time exceeds timeout, false otherwise.
45
+ */
46
+ export function timeoutMillis(nanoTimestamp64: bigint, millisTimeout: bigint | number): boolean;