@valkyriestudios/utils 8.1.0 → 8.3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic
6
6
  Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [8.3.0] - 2023-12-06
9
+ ### Added
10
+ - Dev Dep: babel-plugin-module-extension@0.1.3
11
+
12
+ ### Improved
13
+ - Dev Dep: Upgrade eslint to 8.55.0
14
+ - Rerun benchmark for v8 on intel i9
15
+
16
+ ### Fixed
17
+ - deep/get: Fix edge case issue where cursor is not an object or array when parts still exist afterwards
18
+
19
+ ## [8.2.0] - 2023-11-29
20
+ ### Improved
21
+ - Dev Dep: Upgrade @babel/core to 7.23.5
22
+ - Dev Dep: Upgrade @babel/preset-env to 7.23.5
23
+ - deep/get: Allow handling of deep keys containing multiple array denominators
24
+ - deep/set: Allow handling of deep keys containing multiple array denominators
25
+
8
26
  ## [8.1.0] - 2023-11-29
9
27
  ### Improved
10
28
  - Reverted module type change that caused breakage due to esm vs cjs compatibility
package/deep/get.js CHANGED
@@ -11,7 +11,7 @@ function deepGet(obj, path) {
11
11
  var get_parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : !1;
12
12
  if (Object.prototype.toString.call(obj) !== _is.PROTO_OBJ && !Array.isArray(obj)) throw new TypeError('Deepget is only supported for objects');
13
13
  if (!(0, _isNotEmpty["default"])(path)) throw new TypeError('No path was given');
14
- var parts = path.replace('[', '.').replace(']', '').split('.');
14
+ var parts = path.replace(/\[/g, '.').replace(/(\.){2,}/g, '.').replace(/(^\.|\.$|\])/g, '').split('.');
15
15
  if (parts.length === 0 || parts.length === 1 && get_parent) return obj;
16
16
  if (get_parent) parts.pop();
17
17
  var cursor = obj;
@@ -20,7 +20,7 @@ function deepGet(obj, path) {
20
20
  var ix = parseInt(parts.shift());
21
21
  if (!Number.isInteger(ix) || ix < 0 || ix > cursor.length - 1) return undefined;
22
22
  cursor = cursor[ix];
23
- } else {
23
+ } else if (Object.prototype.toString.call(cursor) === _is.PROTO_OBJ) {
24
24
  var key = parts.shift();
25
25
  if (!cursor.hasOwnProperty(key)) return undefined;
26
26
  cursor = cursor[key];
package/deep/set.js CHANGED
@@ -12,7 +12,7 @@ function deepSet(obj, path) {
12
12
  var define = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !1;
13
13
  if (Object.prototype.toString.call(obj) !== _is.PROTO_OBJ && !Array.isArray(obj)) throw new TypeError('Deepset is only supported for objects');
14
14
  if (!(0, _isNotEmpty["default"])(path)) throw new TypeError('No path was given');
15
- var parts = path.replace('[', '.').replace(']', '').split('.');
15
+ var parts = path.replace(/\[/g, '.').replace(/(\.){2,}/g, '.').replace(/(^\.|\.$|\])/g, '').split('.');
16
16
  for (var i = 0; i < parts.length - 1; i++) {
17
17
  if (parts[i] === '') continue;
18
18
  if (!obj[parts[i]]) obj[parts[i]] = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valkyriestudios/utils",
3
- "version": "8.1.0",
3
+ "version": "8.3.0",
4
4
  "description": "A collection of single-function utilities for common tasks",
5
5
  "main": "index.js",
6
6
  "author": {
@@ -23,7 +23,7 @@
23
23
  "lint": "npm run lint:src && npm run lint:test",
24
24
  "lint:src": "./node_modules/.bin/eslint --ext .js,.mjs ./src",
25
25
  "lint:test": "./node_modules/.bin/eslint --ext .js,.mjs ./test",
26
- "build": "npm run lint && npm run test:coverage && rm -rf ./dist && mkdir ./dist && npx babel src --out-dir ./dist && sh ./adjust_esm_to_cjs.sh && mv -f ./dist/* ./ && rm -rf ./dist",
26
+ "build": "npm run lint && npm run test:coverage && npx babel src --out-dir ./",
27
27
  "codecov": "codecov"
28
28
  },
29
29
  "repository": {
@@ -36,12 +36,13 @@
36
36
  "homepage": "https://github.com/ValkyrieStudios/utils#readme",
37
37
  "devDependencies": {
38
38
  "@babel/cli": "^7.23.4",
39
- "@babel/core": "^7.23.2",
40
- "@babel/preset-env": "^7.23.2",
39
+ "@babel/core": "^7.23.5",
40
+ "@babel/preset-env": "^7.23.5",
41
41
  "@babel/register": "^7.22.15",
42
+ "babel-plugin-module-extension": "^0.1.3",
42
43
  "babel-plugin-transform-minify-booleans": "^6.9.4",
43
44
  "babel-plugin-transform-remove-console": "^6.9.4",
44
45
  "c8": "^8.0.1",
45
- "eslint": "^8.52.0"
46
+ "eslint": "^8.55.0"
46
47
  }
47
48
  }
package/src/deep/get.mjs CHANGED
@@ -14,7 +14,11 @@ export default function deepGet (obj, path, get_parent = false) {
14
14
  if (!isNotEmptyString(path)) throw new TypeError('No path was given');
15
15
 
16
16
  // Cleanup paths : a.b[2].c --> ['a', 'b', '2', 'c'] (faster processing)
17
- const parts = path.replace('[', '.').replace(']', '').split('.');
17
+ const parts = path
18
+ .replace(/\[/g, '.')
19
+ .replace(/(\.){2,}/g, '.')
20
+ .replace(/(^\.|\.$|\])/g, '')
21
+ .split('.');
18
22
 
19
23
  // Return obj if no parts were passed or if only 1 part and get_parent is true
20
24
  if (parts.length === 0 || (parts.length === 1 && get_parent)) return obj;
@@ -28,7 +32,7 @@ export default function deepGet (obj, path, get_parent = false) {
28
32
  const ix = parseInt(parts.shift());
29
33
  if (!Number.isInteger(ix) || ix < 0 || ix > (cursor.length - 1)) return undefined;
30
34
  cursor = cursor[ix];
31
- } else {
35
+ } else if (Object.prototype.toString.call(cursor) === PROTO_OBJ) {
32
36
  const key = parts.shift();
33
37
  if (!cursor.hasOwnProperty(key)) return undefined;
34
38
  cursor = cursor[key];
package/src/deep/set.mjs CHANGED
@@ -14,7 +14,11 @@ export default function deepSet (obj, path, value = null, define = false) {
14
14
  if (!isNotEmptyString(path)) throw new TypeError('No path was given');
15
15
 
16
16
  // Cleanup paths : a.b[2].c --> ['a', 'b', '2', 'c'] (faster processing)
17
- const parts = path.replace('[', '.').replace(']', '').split('.');
17
+ const parts = path
18
+ .replace(/\[/g, '.')
19
+ .replace(/(\.){2,}/g, '.')
20
+ .replace(/(^\.|\.$|\])/g, '')
21
+ .split('.');
18
22
 
19
23
  // Build any unknown paths and set cursor
20
24
  for (let i = 0; i < parts.length - 1; i++) {