@ls-stack/utils 3.15.0 → 3.17.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.
@@ -2,13 +2,10 @@
2
2
  function objectTypedEntries(obj) {
3
3
  return Object.entries(obj);
4
4
  }
5
- function pick(obj, keys, rename) {
5
+ function pick(obj, keys) {
6
6
  const result = {};
7
- if (!obj) {
8
- return result;
9
- }
10
7
  for (const key of keys) {
11
- result[rename?.[key] || key] = obj[key];
8
+ result[key] = obj[key];
12
9
  }
13
10
  return result;
14
11
  }
package/lib/hash.cjs ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hash.ts
21
+ var hash_exports = {};
22
+ __export(hash_exports, {
23
+ murmur2: () => murmur2
24
+ });
25
+ module.exports = __toCommonJS(hash_exports);
26
+ function murmur2(str) {
27
+ let h = 0;
28
+ let k, i = 0, len = str.length;
29
+ for (; len >= 4; ++i, len -= 4) {
30
+ k = str.charCodeAt(i) & 255 | (str.charCodeAt(++i) & 255) << 8 | (str.charCodeAt(++i) & 255) << 16 | (str.charCodeAt(++i) & 255) << 24;
31
+ k = /* Math.imul(k, m): */
32
+ (k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16);
33
+ k ^= /* k >>> r: */
34
+ k >>> 24;
35
+ h = /* Math.imul(k, m): */
36
+ (k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16) ^ /* Math.imul(h, m): */
37
+ (h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
38
+ }
39
+ switch (len) {
40
+ case 3:
41
+ h ^= (str.charCodeAt(i + 2) & 255) << 16;
42
+ case 2:
43
+ h ^= (str.charCodeAt(i + 1) & 255) << 8;
44
+ case 1:
45
+ h ^= str.charCodeAt(i) & 255;
46
+ h = /* Math.imul(h, m): */
47
+ (h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
48
+ }
49
+ h ^= h >>> 13;
50
+ h = /* Math.imul(h, m): */
51
+ (h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
52
+ return ((h ^ h >>> 15) >>> 0).toString(36);
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ murmur2
57
+ });
package/lib/hash.d.cts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param str - The string to hash.
3
+ * @returns The hash of the string.
4
+ */
5
+ declare function murmur2(str: string): string;
6
+
7
+ export { murmur2 };
package/lib/hash.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param str - The string to hash.
3
+ * @returns The hash of the string.
4
+ */
5
+ declare function murmur2(str: string): string;
6
+
7
+ export { murmur2 };
package/lib/hash.js ADDED
@@ -0,0 +1,32 @@
1
+ // src/hash.ts
2
+ function murmur2(str) {
3
+ let h = 0;
4
+ let k, i = 0, len = str.length;
5
+ for (; len >= 4; ++i, len -= 4) {
6
+ k = str.charCodeAt(i) & 255 | (str.charCodeAt(++i) & 255) << 8 | (str.charCodeAt(++i) & 255) << 16 | (str.charCodeAt(++i) & 255) << 24;
7
+ k = /* Math.imul(k, m): */
8
+ (k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16);
9
+ k ^= /* k >>> r: */
10
+ k >>> 24;
11
+ h = /* Math.imul(k, m): */
12
+ (k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16) ^ /* Math.imul(h, m): */
13
+ (h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
14
+ }
15
+ switch (len) {
16
+ case 3:
17
+ h ^= (str.charCodeAt(i + 2) & 255) << 16;
18
+ case 2:
19
+ h ^= (str.charCodeAt(i + 1) & 255) << 8;
20
+ case 1:
21
+ h ^= str.charCodeAt(i) & 255;
22
+ h = /* Math.imul(h, m): */
23
+ (h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
24
+ }
25
+ h ^= h >>> 13;
26
+ h = /* Math.imul(h, m): */
27
+ (h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
28
+ return ((h ^ h >>> 15) >>> 0).toString(36);
29
+ }
30
+ export {
31
+ murmur2
32
+ };
package/lib/objUtils.cjs CHANGED
@@ -32,13 +32,10 @@ module.exports = __toCommonJS(objUtils_exports);
32
32
  function objectTypedEntries(obj) {
33
33
  return Object.entries(obj);
34
34
  }
35
- function pick(obj, keys, rename) {
35
+ function pick(obj, keys) {
36
36
  const result = {};
37
- if (!obj) {
38
- return result;
39
- }
40
37
  for (const key of keys) {
41
- result[rename?.[key] || key] = obj[key];
38
+ result[key] = obj[key];
42
39
  }
43
40
  return result;
44
41
  }
@@ -1,6 +1,6 @@
1
1
  /** @deprecated use typedObjectEntries from @ls-stack/utils/typingFnUtils instead */
2
2
  declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
3
- declare function pick<T, K extends keyof T>(obj: T | undefined, keys: K[], rename?: Partial<Record<K, string>>): Record<string, unknown>;
3
+ declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
4
4
  declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
5
5
  declare function mapObjectToObject<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
6
6
  declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
package/lib/objUtils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** @deprecated use typedObjectEntries from @ls-stack/utils/typingFnUtils instead */
2
2
  declare function objectTypedEntries<T extends Record<string, unknown>>(obj: T): [Extract<keyof T, string>, T[keyof T]][];
3
- declare function pick<T, K extends keyof T>(obj: T | undefined, keys: K[], rename?: Partial<Record<K, string>>): Record<string, unknown>;
3
+ declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
4
4
  declare function mapArrayToObject<T, K extends string, O>(array: T[], mapper: (item: T, index: number) => [K, O]): Record<K, O>;
5
5
  declare function mapObjectToObject<I extends Record<string | number | symbol, unknown>, K extends string | number | symbol, O>(obj: I, mapper: (key: keyof I, value: I[keyof I]) => [K, O]): Record<K, O>;
6
6
  declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
package/lib/objUtils.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  omit,
7
7
  pick,
8
8
  rejectObjUndefinedValues
9
- } from "./chunk-MWND73GM.js";
9
+ } from "./chunk-GHAQOUA6.js";
10
10
  export {
11
11
  looseGetObjectProperty,
12
12
  mapArrayToObject,
package/lib/testUtils.cjs CHANGED
@@ -125,13 +125,10 @@ function clampMin(value, min) {
125
125
  }
126
126
 
127
127
  // src/objUtils.ts
128
- function pick(obj, keys, rename) {
128
+ function pick(obj, keys) {
129
129
  const result = {};
130
- if (!obj) {
131
- return result;
132
- }
133
130
  for (const key of keys) {
134
- result[rename?.[key] || key] = obj[key];
131
+ result[key] = obj[key];
135
132
  }
136
133
  return result;
137
134
  }
package/lib/testUtils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  omit,
3
3
  pick
4
- } from "./chunk-MWND73GM.js";
4
+ } from "./chunk-GHAQOUA6.js";
5
5
  import {
6
6
  deepEqual
7
7
  } from "./chunk-JQFUKJU5.js";
@@ -30,19 +30,19 @@ type UnionDiff<T, U> = [
30
30
  ] extends [U] ? [
31
31
  U
32
32
  ] extends [T] ? null : {
33
- onRightHasExtra: Exclude<U, T>;
33
+ onRightHasExtraErr: Exclude<U, T>;
34
34
  } : [U] extends [T] ? {
35
- onRightHasMissing: Exclude<T, U>;
35
+ onRightHasMissingErr: Exclude<T, U>;
36
36
  } : {
37
- onRightHasExtra: Exclude<U, T>;
38
- onRightHasMissing: Exclude<T, U>;
37
+ onRightHasExtraErr: Exclude<U, T>;
38
+ onRightHasMissingErr: Exclude<T, U>;
39
39
  };
40
40
  /**
41
41
  * Type helper to compare two union types and determine their relationship.
42
42
  *
43
43
  * @template T - The first union type (left side)
44
44
  * @template U - The second union type (right side)
45
- * @param _diff - null if unions are identical, or an object describing the difference
45
+ * @param _diff - null if unions are identical, or an object describing the errors
46
46
  * @returns void - This function is only used for type checking
47
47
  */
48
48
  declare function unionsAreTheSame<T, U>(_diff: UnionDiff<T, U>): void;
@@ -30,19 +30,19 @@ type UnionDiff<T, U> = [
30
30
  ] extends [U] ? [
31
31
  U
32
32
  ] extends [T] ? null : {
33
- onRightHasExtra: Exclude<U, T>;
33
+ onRightHasExtraErr: Exclude<U, T>;
34
34
  } : [U] extends [T] ? {
35
- onRightHasMissing: Exclude<T, U>;
35
+ onRightHasMissingErr: Exclude<T, U>;
36
36
  } : {
37
- onRightHasExtra: Exclude<U, T>;
38
- onRightHasMissing: Exclude<T, U>;
37
+ onRightHasExtraErr: Exclude<U, T>;
38
+ onRightHasMissingErr: Exclude<T, U>;
39
39
  };
40
40
  /**
41
41
  * Type helper to compare two union types and determine their relationship.
42
42
  *
43
43
  * @template T - The first union type (left side)
44
44
  * @template U - The second union type (right side)
45
- * @param _diff - null if unions are identical, or an object describing the difference
45
+ * @param _diff - null if unions are identical, or an object describing the errors
46
46
  * @returns void - This function is only used for type checking
47
47
  */
48
48
  declare function unionsAreTheSame<T, U>(_diff: UnionDiff<T, U>): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Typescript utils",
4
- "version": "3.15.0",
4
+ "version": "3.17.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "lib"
@@ -82,6 +82,10 @@
82
82
  "import": "./lib/getValueStableKey.js",
83
83
  "require": "./lib/getValueStableKey.cjs"
84
84
  },
85
+ "./hash": {
86
+ "import": "./lib/hash.js",
87
+ "require": "./lib/hash.cjs"
88
+ },
85
89
  "./interpolate": {
86
90
  "import": "./lib/interpolate.js",
87
91
  "require": "./lib/interpolate.cjs"