@valkyriestudios/utils 11.5.0 → 11.7.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/deep/freeze.d.ts CHANGED
@@ -3,6 +3,9 @@ type deepInput = {
3
3
  } | {
4
4
  [key: string]: any;
5
5
  }[] | any[];
6
+ type Frozen<T> = {
7
+ readonly [K in keyof T]: Frozen<T[K]>;
8
+ };
6
9
  /**
7
10
  * Recursively freezes all properties of an object
8
11
  *
@@ -10,5 +13,5 @@ type deepInput = {
10
13
  *
11
14
  * @returns Deeply frozen object
12
15
  */
13
- export default function deepFreeze(obj: deepInput): Readonly<deepInput>;
16
+ export default function deepFreeze<T extends deepInput>(obj: T): Frozen<T>;
14
17
  export {};
package/deep/seal.d.ts CHANGED
@@ -3,6 +3,9 @@ type deepInput = {
3
3
  } | {
4
4
  [key: string]: any;
5
5
  }[] | any[];
6
+ type Sealed<T> = {
7
+ [K in keyof T]: Sealed<T[K]>;
8
+ };
6
9
  /**
7
10
  * Recursively seals all properties of an object
8
11
  *
@@ -10,5 +13,5 @@ type deepInput = {
10
13
  *
11
14
  * @returns Deeply sealed object
12
15
  */
13
- export default function deepSeal(obj: deepInput): deepInput;
16
+ export default function deepSeal<T extends deepInput>(obj: T): Sealed<T>;
14
17
  export {};
package/index.d.ts CHANGED
@@ -261,7 +261,10 @@ declare module "deep/freeze" {
261
261
  } | {
262
262
  [key: string]: any;
263
263
  }[] | any[];
264
- export default function deepFreeze(obj: deepInput): Readonly<deepInput>;
264
+ type Frozen<T> = {
265
+ readonly [K in keyof T]: Frozen<T[K]>;
266
+ };
267
+ export default function deepFreeze<T extends deepInput>(obj: T): Frozen<T>;
265
268
  }
266
269
  declare module "deep/get" {
267
270
  export default function deepGet(obj: {
@@ -276,7 +279,10 @@ declare module "deep/seal" {
276
279
  } | {
277
280
  [key: string]: any;
278
281
  }[] | any[];
279
- export default function deepSeal(obj: deepInput): deepInput;
282
+ type Sealed<T> = {
283
+ [K in keyof T]: Sealed<T[K]>;
284
+ };
285
+ export default function deepSeal<T extends deepInput>(obj: T): Sealed<T>;
280
286
  }
281
287
  declare module "deep/set" {
282
288
  export default function deepSet(obj: {
package/object/merge.js CHANGED
@@ -1,20 +1,14 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PROTO_OBJ = '[object Object]';
3
4
  function merge(target, source = {}) {
4
- if (Object.prototype.toString.call(target) !== '[object Object]' ||
5
- Object.prototype.toString.call(source) !== '[object Object]')
5
+ if (Object.prototype.toString.call(target) !== PROTO_OBJ ||
6
+ Object.prototype.toString.call(source) !== PROTO_OBJ)
6
7
  throw new TypeError('Please pass a target and object to merge');
7
8
  const acc = {};
8
9
  for (const key in target) {
9
- if (!Object.prototype.hasOwnProperty.call(target, key))
10
- continue;
11
- if (typeof target[key] === 'object' &&
12
- target[key] !== null &&
13
- !Array.isArray(target[key]) &&
14
- Object.prototype.hasOwnProperty.call(source, key) &&
15
- typeof source[key] === 'object' &&
16
- source[key] !== null &&
17
- !Array.isArray(source[key])) {
10
+ if (Object.prototype.toString.call(target[key]) === PROTO_OBJ &&
11
+ Object.prototype.toString.call(source[key]) === PROTO_OBJ) {
18
12
  acc[key] = merge(target[key], source[key]);
19
13
  }
20
14
  else {
package/object/pick.js CHANGED
@@ -8,25 +8,22 @@ function pick(obj, keys) {
8
8
  keys.length === 0)
9
9
  throw new TypeError('Please pass an object to pick from and a keys array');
10
10
  const map = {};
11
- let key_deep = false;
12
11
  let val;
12
+ let sanitized;
13
13
  for (const key of keys) {
14
14
  if (typeof key !== 'string')
15
15
  continue;
16
- const sanitized = key.trim();
16
+ sanitized = key.trim();
17
17
  if (sanitized.length === 0)
18
18
  continue;
19
- key_deep = /(\.|\[)/g.test(sanitized);
20
- val = key_deep
21
- ? (0, get_1.default)(obj, sanitized)
22
- : obj[sanitized];
23
- if (val === undefined)
24
- continue;
25
- if (key_deep) {
19
+ if (/(\.|\[)/g.test(sanitized)) {
20
+ val = (0, get_1.default)(obj, sanitized);
21
+ if (val === undefined)
22
+ continue;
26
23
  (0, set_1.default)(map, sanitized, val);
27
24
  }
28
- else {
29
- map[sanitized] = val;
25
+ else if (obj[sanitized] !== undefined) {
26
+ map[sanitized] = obj[sanitized];
30
27
  }
31
28
  }
32
29
  return map;
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@valkyriestudios/utils", "version": "11.5.0", "description": "A collection of single-function utilities for common tasks", "author": { "name": "Peter Vermeulen", "email": "contact@valkyriestudios.be", "url": "www.valkyriestudios.be" }, "keywords": [ "utility", "library", "javascript", "js", "node", "bun" ], "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/ValkyrieStudios/utils.git" }, "bugs": { "url": "https://github.com/ValkyrieStudios/utils/issues" }, "homepage": "https://github.com/ValkyrieStudios/utils#readme", "types": "index.d.ts" }
1
+ { "name": "@valkyriestudios/utils", "version": "11.7.0", "description": "A collection of single-function utilities for common tasks", "author": { "name": "Peter Vermeulen", "email": "contact@valkyriestudios.be", "url": "www.valkyriestudios.be" }, "keywords": [ "utility", "library", "javascript", "js", "node", "bun" ], "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/ValkyrieStudios/utils.git" }, "bugs": { "url": "https://github.com/ValkyrieStudios/utils/issues" }, "homepage": "https://github.com/ValkyrieStudios/utils#readme", "types": "index.d.ts" }