property-accessor 2.0.0 → 2.0.1
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,18 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
7
7
|
|
|
8
|
+
## [2.0.1] - 2025-05-01
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fixed changelog
|
|
13
|
+
- Refactored code
|
|
14
|
+
|
|
8
15
|
## [2.0.0] - 2025-05-01
|
|
9
16
|
|
|
10
17
|
### Added
|
|
18
|
+
|
|
11
19
|
- Re-implemented with TypeScript
|
|
12
20
|
- Added path validation
|
|
13
21
|
- Added tests
|
|
14
22
|
|
|
15
|
-
###
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
16
25
|
- Refactored code
|
|
17
26
|
|
|
18
27
|
## [1.0.0] - 2019-06-27
|
|
19
28
|
|
|
20
|
-
Basic package implementation with ES2015
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
Basic package implementation with ES2015
|
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Property Accessor
|
|
2
|
+
#### [Changelog](./CHANGELOG.md)
|
|
2
3
|
|
|
3
4
|
This utility provides methods to **evaluate and manipulate deeply nested properties** of objects using string-based paths like:
|
|
4
5
|
|
|
@@ -32,7 +33,7 @@ Retrieves a value from the object using a dot/bracket notation path.
|
|
|
32
33
|
|
|
33
34
|
### `PropertyAccessor.set(key: string, value: any, target: any): boolean`
|
|
34
35
|
|
|
35
|
-
Sets a value at the given path. Returns `true` on success, `false` otherwise.
|
|
36
|
+
Sets a value at the given path. Returns `true` on success, `false` otherwise.
|
|
36
37
|
**Automatically creates nested objects and arrays as needed**.
|
|
37
38
|
|
|
38
39
|
- **Parameters:**
|
|
@@ -50,8 +51,8 @@ const { PropertyAccessor } = require('property-accessor');
|
|
|
50
51
|
const target = {
|
|
51
52
|
users: [
|
|
52
53
|
{ firstName: 'John', surName: 'Doe', age: 25 },
|
|
53
|
-
{ firstName: 'Ann', surName: 'Doe', age: 23 }
|
|
54
|
-
]
|
|
54
|
+
{ firstName: 'Ann', surName: 'Doe', age: 23 },
|
|
55
|
+
],
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
console.log(PropertyAccessor.get('users[0].firstName', target));
|
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validatePath = void 0;
|
|
4
4
|
const _const_1 = require("../constants");
|
|
5
5
|
function validatePath(key) {
|
|
6
|
-
const normalizedKey = key
|
|
7
|
-
.replace(/\['([^']+)'\]/g, '[$1]')
|
|
8
|
-
.replace(/\["([^"]+)"\]/g, '[$1]');
|
|
6
|
+
const normalizedKey = key.replace(/\['([^']+)'\]/g, '[$1]').replace(/\["([^"]+)"\]/g, '[$1]');
|
|
9
7
|
return _const_1.VALID_PATH_REGEX.test(normalizedKey);
|
|
10
8
|
}
|
|
11
9
|
exports.validatePath = validatePath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-path.js","sourceRoot":"","sources":["../../src/helpers/validate-path.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAE1C,SAAgB,YAAY,CAAC,GAAW;IACtC,MAAM,aAAa,GAAG,GAAG
|
|
1
|
+
{"version":3,"file":"validate-path.js","sourceRoot":"","sources":["../../src/helpers/validate-path.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAE1C,SAAgB,YAAY,CAAC,GAAW;IACtC,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC9F,OAAO,yBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC9C,CAAC;AAHD,oCAGC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property-accessor.js","sourceRoot":"","sources":["../../src/library/property-accessor.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAExC,MAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"property-accessor.js","sourceRoot":"","sources":["../../src/library/property-accessor.ts"],"names":[],"mappings":";;;AAAA,uCAAwC;AAExC,MAAa,gBAAgB;IACjB,MAAM,CAAM;IAEtB,YAAY,MAAW;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACM,GAAG,CAAC,GAAW;QACpB,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAEM,GAAG,CAAC,GAAW,EAAE,KAAU;QAChC,OAAO,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,GAAQ;QAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO;QACT,CAAC;QACD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,GAAG,CAAC;QACb,CAAC;QACD,IAAI,CAAC,IAAA,uBAAY,EAAC,IAAI,CAAC,EAAE,CAAC;YACxB,OAAO;QACT,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;YAC1D,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;gBACtC,OAAO;YACT,CAAC;YACD,MAAM,KAAK,GAAa,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC7D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,C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CAAC,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE,CAAC;wBACpD,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC3D,CAAC;oBACD,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AApED,4CAoEC"}
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -7,15 +7,15 @@ const target = {
|
|
|
7
7
|
b: [
|
|
8
8
|
{
|
|
9
9
|
c: 'd',
|
|
10
|
-
e: 1
|
|
10
|
+
e: 1,
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
13
|
f: 'g',
|
|
14
|
-
h: 2
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
]
|
|
14
|
+
h: 2,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
assert.equal(PropertyAccessor.get('a[0]b[0].c', target), 'd');
|
|
@@ -26,7 +26,7 @@ assert.equal(PropertyAccessor.set('a[0]b[5].f', 3, target), true);
|
|
|
26
26
|
assert.equal(PropertyAccessor.set('a[1]b.c.d.f', 3, target), true);
|
|
27
27
|
assert.equal(PropertyAccessor.get('a[0]b.length', target), 6);
|
|
28
28
|
|
|
29
|
-
const propertyAccessor = new PropertyAccessor({ a: [
|
|
29
|
+
const propertyAccessor = new PropertyAccessor({ a: [{ b: 2 }] });
|
|
30
30
|
|
|
31
31
|
assert.equal(propertyAccessor.get('a[0].b'), 2);
|
|
32
32
|
assert.equal(propertyAccessor.set('a[0].c', 3), true);
|