@chubbyts/chubbyts-decode-encode 2.3.0 → 2.4.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/README.md
CHANGED
|
@@ -25,16 +25,17 @@ A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.
|
|
|
25
25
|
|
|
26
26
|
* node: 22
|
|
27
27
|
* [@chubbyts/chubbyts-throwable-to-error][2]: ^2.2.0
|
|
28
|
-
* [fast-xml-
|
|
29
|
-
* [
|
|
30
|
-
* [
|
|
28
|
+
* [fast-xml-builder][3]: ^1.3.0
|
|
29
|
+
* [fast-xml-parser][4]: ^5.7.3
|
|
30
|
+
* [qs][5]: ^6.15.1
|
|
31
|
+
* [yaml][6]: ^2.8.4
|
|
31
32
|
|
|
32
33
|
## Installation
|
|
33
34
|
|
|
34
35
|
Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-decode-encode][1].
|
|
35
36
|
|
|
36
37
|
```ts
|
|
37
|
-
npm i @chubbyts/chubbyts-decode-encode@^2.
|
|
38
|
+
npm i @chubbyts/chubbyts-decode-encode@^2.4.0
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
## Usage
|
|
@@ -179,6 +180,7 @@ const contentType = yamlTypeEncoder.contentType;
|
|
|
179
180
|
|
|
180
181
|
[1]: https://www.npmjs.com/package/@chubbyts/chubbyts-decode-encode
|
|
181
182
|
[2]: https://www.npmjs.com/package/@chubbyts/chubbyts-throwable-to-error
|
|
182
|
-
[3]: https://www.npmjs.com/package/fast-xml-
|
|
183
|
-
[4]: https://www.npmjs.com/package/
|
|
184
|
-
[5]: https://www.npmjs.com/package/
|
|
183
|
+
[3]: https://www.npmjs.com/package/fast-xml-builder
|
|
184
|
+
[4]: https://www.npmjs.com/package/fast-xml-parser
|
|
185
|
+
[5]: https://www.npmjs.com/package/qs
|
|
186
|
+
[6]: https://www.npmjs.com/package/yaml
|
package/dist/decoder/decoder.js
CHANGED
|
@@ -2,7 +2,7 @@ import { XMLParser } from 'fast-xml-parser';
|
|
|
2
2
|
import { throwableToError } from '@chubbyts/chubbyts-throwable-to-error/dist/throwable-to-error';
|
|
3
3
|
import { DATATYPE_ARRAY, DATATYPE_BOOLEAN, DATATYPE_NULL, DATATYPE_NUMBER, DATATYPE_OBJECT, DATATYPE_STRING, } from '../jsonx-datatypes.js';
|
|
4
4
|
import { DecodeError } from './decoder.js';
|
|
5
|
-
const decodeHtmlEntities = (string) => string.replace(
|
|
5
|
+
const decodeHtmlEntities = (string) => string.replace(/&#(\d+);/gm, (_, code) => String.fromCodePoint(Number(code)));
|
|
6
6
|
const getNodeName = (node) => {
|
|
7
7
|
return node[':@']?.['@_name'];
|
|
8
8
|
};
|
|
@@ -16,7 +16,7 @@ const decodeValue = (value) => {
|
|
|
16
16
|
if (value === 'false') {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
-
const float = parseFloat(value); // handles integers as well
|
|
19
|
+
const float = Number.parseFloat(value); // handles integers as well
|
|
20
20
|
if (float.toString() === value) {
|
|
21
21
|
return float;
|
|
22
22
|
}
|
package/dist/encoder/encoder.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Builder from 'fast-xml-builder';
|
|
2
2
|
import { throwableToError } from '@chubbyts/chubbyts-throwable-to-error/dist/throwable-to-error';
|
|
3
3
|
import { isArray, isBoolean, isNumber, isObject, isString, isNull } from '../data.js';
|
|
4
4
|
import { DATATYPE_ARRAY, DATATYPE_BOOLEAN, DATATYPE_NULL, DATATYPE_NUMBER, DATATYPE_OBJECT, DATATYPE_STRING, } from '../jsonx-datatypes.js';
|
|
5
5
|
import { EncodeError } from './encoder.js';
|
|
6
|
-
const encodeHtmlEntities = (string) => string.replace(/[\u00A0-\u9999<>&]/g, (i) => '&#' + i.
|
|
6
|
+
const encodeHtmlEntities = (string) => string.replace(/[\u00A0-\u9999<>&]/g, (i) => '&#' + i.codePointAt(0) + ';');
|
|
7
7
|
const createXmlNode = () => {
|
|
8
8
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'#text': '',
|
|
12
|
-
},
|
|
13
|
-
],
|
|
9
|
+
// Stryker disable next-line ArrayDeclaration: the XMLBuilder ignores the children of the xml processing instruction node
|
|
10
|
+
'?xml': [],
|
|
14
11
|
':@': {
|
|
15
12
|
'@_version': '1.0',
|
|
16
13
|
'@_encoding': 'UTF-8',
|
|
@@ -146,7 +143,7 @@ const createObjectNode = (value, key = undefined) => {
|
|
|
146
143
|
};
|
|
147
144
|
};
|
|
148
145
|
export const createJsonxTypeEncoder = (prettyPrint = false) => {
|
|
149
|
-
const builder = new
|
|
146
|
+
const builder = new Builder({
|
|
150
147
|
preserveOrder: true,
|
|
151
148
|
ignoreAttributes: false,
|
|
152
149
|
processEntities: false,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chubbyts/chubbyts-decode-encode",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"description": "A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"chubbyts",
|
|
@@ -52,21 +52,23 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@chubbyts/chubbyts-throwable-to-error": "^2.2.0",
|
|
55
|
+
"fast-xml-builder": "^1.3.0",
|
|
55
56
|
"fast-xml-parser": "^5.7.3",
|
|
56
57
|
"qs": "^6.15.1",
|
|
57
58
|
"yaml": "^2.8.4"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@chubbyts/chubbyts-
|
|
61
|
-
"@chubbyts/chubbyts-
|
|
61
|
+
"@chubbyts/chubbyts-function-mock": "^2.3.0",
|
|
62
|
+
"@chubbyts/chubbyts-oxlint": "^1.0.0",
|
|
62
63
|
"@stryker-mutator/core": "^9.6.1",
|
|
63
64
|
"@stryker-mutator/vitest-runner": "^9.6.1",
|
|
64
|
-
"@types/node": "^
|
|
65
|
+
"@types/node": "^26.1.1",
|
|
65
66
|
"@types/qs": "^6.15.1",
|
|
66
|
-
"@vitest/coverage-v8": "^4.1.
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
67
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
68
|
+
"oxlint": "^1.75.0",
|
|
69
|
+
"prettier": "^3.9.6",
|
|
70
|
+
"typescript": "^7.0.2",
|
|
71
|
+
"vitest": "^4.1.10"
|
|
70
72
|
},
|
|
71
73
|
"publishConfig": {
|
|
72
74
|
"access": "public"
|
|
@@ -76,8 +78,8 @@
|
|
|
76
78
|
"cs-fix": "prettier --write src tests",
|
|
77
79
|
"cs": "prettier --check src tests",
|
|
78
80
|
"infection": "stryker run",
|
|
79
|
-
"lint-fix": "
|
|
80
|
-
"lint": "
|
|
81
|
+
"lint-fix": "oxlint --fix src tests vitest.config.ts",
|
|
82
|
+
"lint": "oxlint src tests vitest.config.ts",
|
|
81
83
|
"test": "vitest"
|
|
82
84
|
}
|
|
83
85
|
}
|