@ls-stack/utils 3.14.0 → 3.16.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/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";
@@ -25,8 +25,10 @@ __export(typingFnUtils_exports, {
25
25
  isObjKey: () => isObjKey,
26
26
  isSubTypeOf: () => isSubTypeOf,
27
27
  narrowStringToUnion: () => narrowStringToUnion,
28
+ typeOnRightExtendsLeftType: () => typeOnRightExtendsLeftType,
28
29
  typedObjectEntries: () => typedObjectEntries,
29
- typedObjectKeys: () => typedObjectKeys
30
+ typedObjectKeys: () => typedObjectKeys,
31
+ unionsAreTheSame: () => unionsAreTheSame
30
32
  });
31
33
  module.exports = __toCommonJS(typingFnUtils_exports);
32
34
  function asNonPartial(obj) {
@@ -47,12 +49,15 @@ function narrowStringToUnion(key, union) {
47
49
  }
48
50
  return void 0;
49
51
  }
50
- function isSubTypeOf() {
52
+ function typeOnRightExtendsLeftType() {
51
53
  return void 0;
52
54
  }
55
+ var isSubTypeOf = typeOnRightExtendsLeftType;
53
56
  function isObjKey(key, obj) {
54
57
  return typeof key === "string" && key in obj;
55
58
  }
59
+ function unionsAreTheSame(_diff) {
60
+ }
56
61
  // Annotate the CommonJS export names for ESM import in node:
57
62
  0 && (module.exports = {
58
63
  asNonPartial,
@@ -60,6 +65,8 @@ function isObjKey(key, obj) {
60
65
  isObjKey,
61
66
  isSubTypeOf,
62
67
  narrowStringToUnion,
68
+ typeOnRightExtendsLeftType,
63
69
  typedObjectEntries,
64
- typedObjectKeys
70
+ typedObjectKeys,
71
+ unionsAreTheSame
65
72
  });
@@ -18,10 +18,33 @@ declare function narrowStringToUnion<const T extends string>(key: string | undef
18
18
  * @template SubType - The type that should extend BaseType
19
19
  * @returns {unknown} Returns undefined, only used for type checking
20
20
  */
21
- declare function isSubTypeOf<BaseType, SubType extends BaseType>(): unknown;
21
+ declare function typeOnRightExtendsLeftType<BaseType, SubType extends BaseType>(): unknown;
22
+ /** @deprecated use typeOnRightExtendsLeftType instead */
23
+ declare const isSubTypeOf: typeof typeOnRightExtendsLeftType;
22
24
  /**
23
25
  * Type helper to narrow a string to a key of an object.
24
26
  */
25
27
  declare function isObjKey<T extends Record<string, unknown>>(key: unknown, obj: T): key is keyof T;
28
+ type UnionDiff<T, U> = [
29
+ T
30
+ ] extends [U] ? [
31
+ U
32
+ ] extends [T] ? null : {
33
+ onRightHasExtraErr: Exclude<U, T>;
34
+ } : [U] extends [T] ? {
35
+ onRightHasMissingErr: Exclude<T, U>;
36
+ } : {
37
+ onRightHasExtraErr: Exclude<U, T>;
38
+ onRightHasMissingErr: Exclude<T, U>;
39
+ };
40
+ /**
41
+ * Type helper to compare two union types and determine their relationship.
42
+ *
43
+ * @template T - The first union type (left side)
44
+ * @template U - The second union type (right side)
45
+ * @param _diff - null if unions are identical, or an object describing the errors
46
+ * @returns void - This function is only used for type checking
47
+ */
48
+ declare function unionsAreTheSame<T, U>(_diff: UnionDiff<T, U>): void;
26
49
 
27
- export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typedObjectEntries, typedObjectKeys };
50
+ export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typeOnRightExtendsLeftType, typedObjectEntries, typedObjectKeys, unionsAreTheSame };
@@ -18,10 +18,33 @@ declare function narrowStringToUnion<const T extends string>(key: string | undef
18
18
  * @template SubType - The type that should extend BaseType
19
19
  * @returns {unknown} Returns undefined, only used for type checking
20
20
  */
21
- declare function isSubTypeOf<BaseType, SubType extends BaseType>(): unknown;
21
+ declare function typeOnRightExtendsLeftType<BaseType, SubType extends BaseType>(): unknown;
22
+ /** @deprecated use typeOnRightExtendsLeftType instead */
23
+ declare const isSubTypeOf: typeof typeOnRightExtendsLeftType;
22
24
  /**
23
25
  * Type helper to narrow a string to a key of an object.
24
26
  */
25
27
  declare function isObjKey<T extends Record<string, unknown>>(key: unknown, obj: T): key is keyof T;
28
+ type UnionDiff<T, U> = [
29
+ T
30
+ ] extends [U] ? [
31
+ U
32
+ ] extends [T] ? null : {
33
+ onRightHasExtraErr: Exclude<U, T>;
34
+ } : [U] extends [T] ? {
35
+ onRightHasMissingErr: Exclude<T, U>;
36
+ } : {
37
+ onRightHasExtraErr: Exclude<U, T>;
38
+ onRightHasMissingErr: Exclude<T, U>;
39
+ };
40
+ /**
41
+ * Type helper to compare two union types and determine their relationship.
42
+ *
43
+ * @template T - The first union type (left side)
44
+ * @template U - The second union type (right side)
45
+ * @param _diff - null if unions are identical, or an object describing the errors
46
+ * @returns void - This function is only used for type checking
47
+ */
48
+ declare function unionsAreTheSame<T, U>(_diff: UnionDiff<T, U>): void;
26
49
 
27
- export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typedObjectEntries, typedObjectKeys };
50
+ export { asNonPartial, asType, isObjKey, isSubTypeOf, narrowStringToUnion, typeOnRightExtendsLeftType, typedObjectEntries, typedObjectKeys, unionsAreTheSame };
@@ -17,18 +17,23 @@ function narrowStringToUnion(key, union) {
17
17
  }
18
18
  return void 0;
19
19
  }
20
- function isSubTypeOf() {
20
+ function typeOnRightExtendsLeftType() {
21
21
  return void 0;
22
22
  }
23
+ var isSubTypeOf = typeOnRightExtendsLeftType;
23
24
  function isObjKey(key, obj) {
24
25
  return typeof key === "string" && key in obj;
25
26
  }
27
+ function unionsAreTheSame(_diff) {
28
+ }
26
29
  export {
27
30
  asNonPartial,
28
31
  asType,
29
32
  isObjKey,
30
33
  isSubTypeOf,
31
34
  narrowStringToUnion,
35
+ typeOnRightExtendsLeftType,
32
36
  typedObjectEntries,
33
- typedObjectKeys
37
+ typedObjectKeys,
38
+ unionsAreTheSame
34
39
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Typescript utils",
4
- "version": "3.14.0",
4
+ "version": "3.16.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "lib"