@valkyriestudios/utils 8.1.0 → 8.2.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 +7 -0
- package/deep/get.js +1 -1
- package/deep/set.js +1 -1
- package/package.json +3 -3
- package/src/deep/get.mjs +5 -1
- package/src/deep/set.mjs +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ 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.2.0] - 2023-11-29
|
|
9
|
+
### Improved
|
|
10
|
+
- Dev Dep: Upgrade @babel/core to 7.23.5
|
|
11
|
+
- Dev Dep: Upgrade @babel/preset-env to 7.23.5
|
|
12
|
+
- deep/get: Allow handling of deep keys containing multiple array denominators
|
|
13
|
+
- deep/set: Allow handling of deep keys containing multiple array denominators
|
|
14
|
+
|
|
8
15
|
## [8.1.0] - 2023-11-29
|
|
9
16
|
### Improved
|
|
10
17
|
- 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(
|
|
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;
|
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(
|
|
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.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "A collection of single-function utilities for common tasks",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"homepage": "https://github.com/ValkyrieStudios/utils#readme",
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@babel/cli": "^7.23.4",
|
|
39
|
-
"@babel/core": "^7.23.
|
|
40
|
-
"@babel/preset-env": "^7.23.
|
|
39
|
+
"@babel/core": "^7.23.5",
|
|
40
|
+
"@babel/preset-env": "^7.23.5",
|
|
41
41
|
"@babel/register": "^7.22.15",
|
|
42
42
|
"babel-plugin-transform-minify-booleans": "^6.9.4",
|
|
43
43
|
"babel-plugin-transform-remove-console": "^6.9.4",
|
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
|
|
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;
|
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
|
|
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++) {
|