@abapify/asjson-parser 0.0.5 → 0.1.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/README.md +5 -5
- package/index.cjs.js +9 -9
- package/index.esm.js +8 -8
- package/package.json +1 -1
- package/src/lib/asjson.d.ts +2 -2
package/README.md
CHANGED
|
@@ -87,15 +87,15 @@ console.log(parse(json));
|
|
|
87
87
|
- as a transformer
|
|
88
88
|
|
|
89
89
|
```ts
|
|
90
|
-
import {
|
|
90
|
+
import { transform } from '@abapify/asjson-parser';
|
|
91
91
|
const object = JSON.parse(json);
|
|
92
|
-
console.log(
|
|
92
|
+
console.log(transform(object));
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
- as a proxy
|
|
95
|
+
- as a proxy (returns a proxied object)
|
|
96
96
|
|
|
97
97
|
```ts
|
|
98
|
-
import {
|
|
98
|
+
import { proxy } from '@abapify/asjson-parser';
|
|
99
99
|
const object = JSON.parse(json);
|
|
100
|
-
console.log(
|
|
100
|
+
console.log(proxy(object));
|
|
101
101
|
```
|
package/index.cjs.js
CHANGED
|
@@ -22,33 +22,33 @@ const AbapJsonProxyHandler = {
|
|
|
22
22
|
}
|
|
23
23
|
let value = Reflect.get(target, prop, receiver);
|
|
24
24
|
const heap = Reflect.get(target, HEAP, receiver);
|
|
25
|
-
if (typeof value ===
|
|
25
|
+
if (typeof value === 'object' && value !== null && REF in value && /^#.*$/.test(value[REF])) {
|
|
26
26
|
const refKey = value[REF].substring(1); // Remove leading "#"
|
|
27
27
|
value = Reflect.get(heap, refKey);
|
|
28
28
|
}
|
|
29
|
-
if (typeof value ===
|
|
29
|
+
if (typeof value === 'object' && value !== null && VAL in value) {
|
|
30
30
|
value = value[VAL];
|
|
31
31
|
}
|
|
32
|
-
if (typeof value ===
|
|
33
|
-
value =
|
|
32
|
+
if (typeof value === 'object' && value !== null) {
|
|
33
|
+
value = proxy(Object.assign(value, {
|
|
34
34
|
[HEAP]: heap
|
|
35
35
|
}));
|
|
36
36
|
}
|
|
37
37
|
return value;
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
function
|
|
40
|
+
function proxy(target) {
|
|
41
41
|
return new Proxy(target, AbapJsonProxyHandler);
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function transform(target) {
|
|
44
44
|
const proxy = new Proxy(target, AbapJsonProxyHandler);
|
|
45
45
|
return Object.fromEntries(Object.entries(proxy));
|
|
46
46
|
}
|
|
47
47
|
function parse(asjson) {
|
|
48
|
-
return
|
|
48
|
+
return transform(JSON.parse(asjson));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
exports.AbapJsonProxyHandler = AbapJsonProxyHandler;
|
|
52
|
-
exports.fromAbapJson = fromAbapJson;
|
|
53
|
-
exports.fromAbapJsonProxy = fromAbapJsonProxy;
|
|
54
52
|
exports.parse = parse;
|
|
53
|
+
exports.proxy = proxy;
|
|
54
|
+
exports.transform = transform;
|
package/index.esm.js
CHANGED
|
@@ -20,30 +20,30 @@ const AbapJsonProxyHandler = {
|
|
|
20
20
|
}
|
|
21
21
|
let value = Reflect.get(target, prop, receiver);
|
|
22
22
|
const heap = Reflect.get(target, HEAP, receiver);
|
|
23
|
-
if (typeof value ===
|
|
23
|
+
if (typeof value === 'object' && value !== null && REF in value && /^#.*$/.test(value[REF])) {
|
|
24
24
|
const refKey = value[REF].substring(1); // Remove leading "#"
|
|
25
25
|
value = Reflect.get(heap, refKey);
|
|
26
26
|
}
|
|
27
|
-
if (typeof value ===
|
|
27
|
+
if (typeof value === 'object' && value !== null && VAL in value) {
|
|
28
28
|
value = value[VAL];
|
|
29
29
|
}
|
|
30
|
-
if (typeof value ===
|
|
31
|
-
value =
|
|
30
|
+
if (typeof value === 'object' && value !== null) {
|
|
31
|
+
value = proxy(Object.assign(value, {
|
|
32
32
|
[HEAP]: heap
|
|
33
33
|
}));
|
|
34
34
|
}
|
|
35
35
|
return value;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
function
|
|
38
|
+
function proxy(target) {
|
|
39
39
|
return new Proxy(target, AbapJsonProxyHandler);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function transform(target) {
|
|
42
42
|
const proxy = new Proxy(target, AbapJsonProxyHandler);
|
|
43
43
|
return Object.fromEntries(Object.entries(proxy));
|
|
44
44
|
}
|
|
45
45
|
function parse(asjson) {
|
|
46
|
-
return
|
|
46
|
+
return transform(JSON.parse(asjson));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export { AbapJsonProxyHandler,
|
|
49
|
+
export { AbapJsonProxyHandler, parse, proxy, transform };
|
package/package.json
CHANGED
package/src/lib/asjson.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const AbapJsonProxyHandler: ProxyHandler<object>;
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
2
|
+
export declare function proxy(target: object): object;
|
|
3
|
+
export declare function transform(target: object): object;
|
|
4
4
|
export declare function parse(asjson: string): object;
|