@abapify/asjson-parser 0.1.1 → 0.3.4
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 -1
- package/package.json +23 -7
- package/index.cjs.d.ts +0 -1
- package/index.cjs.js +0 -54
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -49
- package/src/index.d.ts +0 -1
- package/src/lib/asjson.d.ts +0 -4
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @abapify/asjson-parser
|
|
2
|
+
|
|
3
|
+
[](https://github.com/abapify/adt-cli/pkgs/npm/%40abapify%2Fasjson-parser)
|
|
4
|
+
|
|
5
|
+
ABAP asJSON (canonical JSON representation) parser.
|
|
2
6
|
|
|
3
7
|
[asJSON](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_asjson.htm) - Canonical JSON Representation
|
|
4
8
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abapify/asjson-parser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"types": "./dist/index.d.mts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.mjs",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"jsonc-eslint-parser": "^2.1.0"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
7
20
|
"repository": {
|
|
8
21
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/abapify/
|
|
22
|
+
"url": "git+https://github.com/abapify/adt-cli.git",
|
|
10
23
|
"directory": "packages/asjson-parser"
|
|
11
24
|
},
|
|
12
|
-
"
|
|
13
|
-
|
|
25
|
+
"homepage": "https://github.com/abapify/adt-cli/tree/main/packages/asjson-parser#readme",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/abapify/adt-cli/issues"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.cjs.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const HEAP = '%heap';
|
|
4
|
-
const REF = '%ref';
|
|
5
|
-
const VAL = '%val';
|
|
6
|
-
const AbapJsonProxyHandler = {
|
|
7
|
-
// Prevents '%heap' from showing up during iteration (e.g., Object.keys)
|
|
8
|
-
ownKeys (target) {
|
|
9
|
-
const ownKeys = Reflect.ownKeys(target);
|
|
10
|
-
// if (ownKeys.includes(VAL)) {
|
|
11
|
-
// const val = Reflect.get(target, VAL);
|
|
12
|
-
// return Reflect.ownKeys(val);
|
|
13
|
-
// }
|
|
14
|
-
return ownKeys.filter((key)=>![
|
|
15
|
-
HEAP
|
|
16
|
-
].includes(key.toString()));
|
|
17
|
-
},
|
|
18
|
-
get: (target, prop, receiver)=>{
|
|
19
|
-
// Use Reflect to access the property, but exclude '%heap'
|
|
20
|
-
if (prop === HEAP) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
let value = Reflect.get(target, prop, receiver);
|
|
24
|
-
const heap = Reflect.get(target, HEAP, receiver);
|
|
25
|
-
if (typeof value === 'object' && value !== null && REF in value && /^#.*$/.test(value[REF])) {
|
|
26
|
-
const refKey = value[REF].substring(1); // Remove leading "#"
|
|
27
|
-
value = Reflect.get(heap, refKey);
|
|
28
|
-
}
|
|
29
|
-
if (typeof value === 'object' && value !== null && VAL in value) {
|
|
30
|
-
value = value[VAL];
|
|
31
|
-
}
|
|
32
|
-
if (typeof value === 'object' && value !== null) {
|
|
33
|
-
value = proxy(Object.assign(value, {
|
|
34
|
-
[HEAP]: heap
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
function proxy(target) {
|
|
41
|
-
return new Proxy(target, AbapJsonProxyHandler);
|
|
42
|
-
}
|
|
43
|
-
function transform(target) {
|
|
44
|
-
const proxy = new Proxy(target, AbapJsonProxyHandler);
|
|
45
|
-
return Object.fromEntries(Object.entries(proxy));
|
|
46
|
-
}
|
|
47
|
-
function parse(asjson) {
|
|
48
|
-
return transform(JSON.parse(asjson));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
exports.AbapJsonProxyHandler = AbapJsonProxyHandler;
|
|
52
|
-
exports.parse = parse;
|
|
53
|
-
exports.proxy = proxy;
|
|
54
|
-
exports.transform = transform;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/index.esm.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const HEAP = '%heap';
|
|
2
|
-
const REF = '%ref';
|
|
3
|
-
const VAL = '%val';
|
|
4
|
-
const AbapJsonProxyHandler = {
|
|
5
|
-
// Prevents '%heap' from showing up during iteration (e.g., Object.keys)
|
|
6
|
-
ownKeys (target) {
|
|
7
|
-
const ownKeys = Reflect.ownKeys(target);
|
|
8
|
-
// if (ownKeys.includes(VAL)) {
|
|
9
|
-
// const val = Reflect.get(target, VAL);
|
|
10
|
-
// return Reflect.ownKeys(val);
|
|
11
|
-
// }
|
|
12
|
-
return ownKeys.filter((key)=>![
|
|
13
|
-
HEAP
|
|
14
|
-
].includes(key.toString()));
|
|
15
|
-
},
|
|
16
|
-
get: (target, prop, receiver)=>{
|
|
17
|
-
// Use Reflect to access the property, but exclude '%heap'
|
|
18
|
-
if (prop === HEAP) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
let value = Reflect.get(target, prop, receiver);
|
|
22
|
-
const heap = Reflect.get(target, HEAP, receiver);
|
|
23
|
-
if (typeof value === 'object' && value !== null && REF in value && /^#.*$/.test(value[REF])) {
|
|
24
|
-
const refKey = value[REF].substring(1); // Remove leading "#"
|
|
25
|
-
value = Reflect.get(heap, refKey);
|
|
26
|
-
}
|
|
27
|
-
if (typeof value === 'object' && value !== null && VAL in value) {
|
|
28
|
-
value = value[VAL];
|
|
29
|
-
}
|
|
30
|
-
if (typeof value === 'object' && value !== null) {
|
|
31
|
-
value = proxy(Object.assign(value, {
|
|
32
|
-
[HEAP]: heap
|
|
33
|
-
}));
|
|
34
|
-
}
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
function proxy(target) {
|
|
39
|
-
return new Proxy(target, AbapJsonProxyHandler);
|
|
40
|
-
}
|
|
41
|
-
function transform(target) {
|
|
42
|
-
const proxy = new Proxy(target, AbapJsonProxyHandler);
|
|
43
|
-
return Object.fromEntries(Object.entries(proxy));
|
|
44
|
-
}
|
|
45
|
-
function parse(asjson) {
|
|
46
|
-
return transform(JSON.parse(asjson));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { AbapJsonProxyHandler, parse, proxy, transform };
|
package/src/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './lib/asjson';
|
package/src/lib/asjson.d.ts
DELETED