@valkyriestudios/utils 11.5.0 → 11.6.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/object/merge.js CHANGED
@@ -1,20 +1,17 @@
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
10
  if (!Object.prototype.hasOwnProperty.call(target, key))
10
11
  continue;
11
- if (typeof target[key] === 'object' &&
12
- target[key] !== null &&
13
- !Array.isArray(target[key]) &&
12
+ if (Object.prototype.toString.call(target[key]) === PROTO_OBJ &&
14
13
  Object.prototype.hasOwnProperty.call(source, key) &&
15
- typeof source[key] === 'object' &&
16
- source[key] !== null &&
17
- !Array.isArray(source[key])) {
14
+ Object.prototype.toString.call(source[key]) === PROTO_OBJ) {
18
15
  acc[key] = merge(target[key], source[key]);
19
16
  }
20
17
  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.6.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" }