@chubbyts/chubbyts-decode-encode 1.1.0 → 1.1.2
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/LICENSE +1 -1
- package/README.md +5 -5
- package/dist/decoder/index.d.ts +2 -2
- package/dist/decoder/json-type-decoder.js +12 -14
- package/dist/decoder/jsonx-type-decoder.js +13 -15
- package/dist/decoder/url-encoded-type-decoder.js +4 -10
- package/dist/decoder/yaml-type-decoder.js +12 -14
- package/dist/encoder/index.d.ts +2 -2
- package/dist/encoder/json-type-encoder.js +2 -4
- package/dist/encoder/jsonx-type-encoder.js +18 -20
- package/dist/encoder/url-encoded-type-encoder.js +2 -6
- package/dist/encoder/yaml-type-encoder.js +2 -4
- package/dist/index.d.ts +1 -1
- package/dist/jsonx-datatypes.d.ts +8 -8
- package/package.json +14 -14
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -25,16 +25,16 @@ A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.
|
|
|
25
25
|
|
|
26
26
|
* node: 14
|
|
27
27
|
* [@chubbyts/chubbyts-throwable-to-error][2]: ^1.0.0
|
|
28
|
-
* [fast-xml-parser][3]: ^4.
|
|
29
|
-
* [qs][4]: ^6.
|
|
30
|
-
* [yaml][5]: ^2.
|
|
28
|
+
* [fast-xml-parser][3]: ^4.1.3
|
|
29
|
+
* [qs][4]: ^6.11.1
|
|
30
|
+
* [yaml][5]: ^2.2.1
|
|
31
31
|
|
|
32
32
|
## Installation
|
|
33
33
|
|
|
34
34
|
Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-decode-encode][1].
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
|
-
npm i @chubbyts/chubbyts-decode-encode@^1.1.
|
|
37
|
+
npm i @chubbyts/chubbyts-decode-encode@^1.1.2
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Usage
|
|
@@ -175,7 +175,7 @@ const contentType = yamlTypeEncoder.contentType;
|
|
|
175
175
|
|
|
176
176
|
## Copyright
|
|
177
177
|
|
|
178
|
-
Dominik Zogg
|
|
178
|
+
2023 Dominik Zogg
|
|
179
179
|
|
|
180
180
|
[1]: https://www.npmjs.com/package/@chubbyts/chubbyts-decode-encode
|
|
181
181
|
[2]: https://www.npmjs.com/package/@chubbyts/chubbyts-throwable-to-error
|
package/dist/decoder/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Data } from '..';
|
|
2
2
|
export declare class DecodeError extends Error {
|
|
3
3
|
}
|
|
4
|
-
export
|
|
4
|
+
export type TypeDecoder = {
|
|
5
5
|
decode: (encodedData: string) => Data;
|
|
6
6
|
contentType: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type Decoder = {
|
|
9
9
|
decode: (encodedData: string, contentType: string, context?: Record<string, unknown>) => Data;
|
|
10
10
|
contentTypes: Array<string>;
|
|
11
11
|
};
|
|
@@ -4,21 +4,19 @@ exports.createJsonTypeDecoder = void 0;
|
|
|
4
4
|
const throwable_to_error_1 = require("@chubbyts/chubbyts-throwable-to-error/dist/throwable-to-error");
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const createJsonTypeDecoder = () => {
|
|
7
|
-
const decode = (encodedData) => {
|
|
8
|
-
try {
|
|
9
|
-
return JSON.parse(encodedData);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
13
|
-
const decodeError = new _1.DecodeError(error.message);
|
|
14
|
-
decodeError.stack = error.stack;
|
|
15
|
-
throw decodeError;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const contentType = 'application/json';
|
|
19
7
|
return {
|
|
20
|
-
decode
|
|
21
|
-
|
|
8
|
+
decode: (encodedData) => {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(encodedData);
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
14
|
+
const decodeError = new _1.DecodeError(error.message);
|
|
15
|
+
decodeError.stack = error.stack;
|
|
16
|
+
throw decodeError;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
contentType: 'application/json',
|
|
22
20
|
};
|
|
23
21
|
};
|
|
24
22
|
exports.createJsonTypeDecoder = createJsonTypeDecoder;
|
|
@@ -78,22 +78,20 @@ const convertObjectNode = (node) => {
|
|
|
78
78
|
return Object.fromEntries(node['json:object'].map(convertNodeWithName));
|
|
79
79
|
};
|
|
80
80
|
const createJsonxTypeDecoder = () => {
|
|
81
|
-
const decode = (encodedData) => {
|
|
82
|
-
try {
|
|
83
|
-
const parser = new fast_xml_parser_1.XMLParser({ preserveOrder: true, ignoreAttributes: false, htmlEntities: false });
|
|
84
|
-
return convertNode(parser.parse(encodedData)[1]);
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
88
|
-
const decodeError = new _1.DecodeError(error.message);
|
|
89
|
-
decodeError.stack = error.stack;
|
|
90
|
-
throw decodeError;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const contentType = 'application/jsonx+xml';
|
|
94
81
|
return {
|
|
95
|
-
decode
|
|
96
|
-
|
|
82
|
+
decode: (encodedData) => {
|
|
83
|
+
try {
|
|
84
|
+
const parser = new fast_xml_parser_1.XMLParser({ preserveOrder: true, ignoreAttributes: false, htmlEntities: false });
|
|
85
|
+
return convertNode(parser.parse(encodedData)[1]);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
89
|
+
const decodeError = new _1.DecodeError(error.message);
|
|
90
|
+
decodeError.stack = error.stack;
|
|
91
|
+
throw decodeError;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
contentType: 'application/jsonx+xml',
|
|
97
95
|
};
|
|
98
96
|
};
|
|
99
97
|
exports.createJsonxTypeDecoder = createJsonxTypeDecoder;
|
|
@@ -29,14 +29,8 @@ const decodeValue = (value) => {
|
|
|
29
29
|
}
|
|
30
30
|
return value;
|
|
31
31
|
};
|
|
32
|
-
const createUrlEncodedTypeDecoder = () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const contentType = 'application/x-www-form-urlencoded';
|
|
37
|
-
return {
|
|
38
|
-
decode,
|
|
39
|
-
contentType,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
32
|
+
const createUrlEncodedTypeDecoder = () => ({
|
|
33
|
+
decode: (encodedData) => decodeValue((0, qs_1.parse)(encodedData, { depth: 100 })),
|
|
34
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
35
|
+
});
|
|
42
36
|
exports.createUrlEncodedTypeDecoder = createUrlEncodedTypeDecoder;
|
|
@@ -5,21 +5,19 @@ const _1 = require(".");
|
|
|
5
5
|
const yaml_1 = require("yaml");
|
|
6
6
|
const throwable_to_error_1 = require("@chubbyts/chubbyts-throwable-to-error/dist/throwable-to-error");
|
|
7
7
|
const createYamlTypeDecoder = () => {
|
|
8
|
-
const decode = (encodedData) => {
|
|
9
|
-
try {
|
|
10
|
-
return (0, yaml_1.parse)(encodedData);
|
|
11
|
-
}
|
|
12
|
-
catch (e) {
|
|
13
|
-
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
14
|
-
const decodeError = new _1.DecodeError(error.message);
|
|
15
|
-
decodeError.stack = error.stack;
|
|
16
|
-
throw decodeError;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const contentType = 'application/x-yaml';
|
|
20
8
|
return {
|
|
21
|
-
decode
|
|
22
|
-
|
|
9
|
+
decode: (encodedData) => {
|
|
10
|
+
try {
|
|
11
|
+
return (0, yaml_1.parse)(encodedData);
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
15
|
+
const decodeError = new _1.DecodeError(error.message);
|
|
16
|
+
decodeError.stack = error.stack;
|
|
17
|
+
throw decodeError;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
contentType: 'application/x-yaml',
|
|
23
21
|
};
|
|
24
22
|
};
|
|
25
23
|
exports.createYamlTypeDecoder = createYamlTypeDecoder;
|
package/dist/encoder/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Data } from '..';
|
|
2
2
|
export declare class EncodeError extends Error {
|
|
3
3
|
}
|
|
4
|
-
export
|
|
4
|
+
export type TypeEncoder = {
|
|
5
5
|
encode: (data: Data) => string;
|
|
6
6
|
contentType: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type Encoder = {
|
|
9
9
|
encode: (data: Data, contentType: string, context?: Record<string, unknown>) => string;
|
|
10
10
|
contentTypes: Array<string>;
|
|
11
11
|
};
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createJsonTypeEncoder = void 0;
|
|
4
4
|
const createJsonTypeEncoder = (prettyPrint = false) => {
|
|
5
|
-
const encode = (data) => JSON.stringify(data, undefined, prettyPrint ? 4 : undefined);
|
|
6
|
-
const contentType = 'application/json';
|
|
7
5
|
return {
|
|
8
|
-
encode,
|
|
9
|
-
contentType,
|
|
6
|
+
encode: (data) => JSON.stringify(data, undefined, prettyPrint ? 4 : undefined),
|
|
7
|
+
contentType: 'application/json',
|
|
10
8
|
};
|
|
11
9
|
};
|
|
12
10
|
exports.createJsonTypeEncoder = createJsonTypeEncoder;
|
|
@@ -155,27 +155,25 @@ const createJsonxTypeEncoder = (prettyPrint = false) => {
|
|
|
155
155
|
processEntities: false,
|
|
156
156
|
format: prettyPrint,
|
|
157
157
|
});
|
|
158
|
-
const encode = (data) => {
|
|
159
|
-
try {
|
|
160
|
-
return builder.build([
|
|
161
|
-
createXmlNode(),
|
|
162
|
-
{
|
|
163
|
-
...createNode(data),
|
|
164
|
-
...createJsonxAttributes(),
|
|
165
|
-
},
|
|
166
|
-
]);
|
|
167
|
-
}
|
|
168
|
-
catch (e) {
|
|
169
|
-
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
170
|
-
const decodeError = new _1.EncodeError(error.message);
|
|
171
|
-
decodeError.stack = error.stack;
|
|
172
|
-
throw decodeError;
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
const contentType = 'application/jsonx+xml';
|
|
176
158
|
return {
|
|
177
|
-
encode
|
|
178
|
-
|
|
159
|
+
encode: (data) => {
|
|
160
|
+
try {
|
|
161
|
+
return builder.build([
|
|
162
|
+
createXmlNode(),
|
|
163
|
+
{
|
|
164
|
+
...createNode(data),
|
|
165
|
+
...createJsonxAttributes(),
|
|
166
|
+
},
|
|
167
|
+
]);
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
const error = (0, throwable_to_error_1.throwableToError)(e);
|
|
171
|
+
const decodeError = new _1.EncodeError(error.message);
|
|
172
|
+
decodeError.stack = error.stack;
|
|
173
|
+
throw decodeError;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
contentType: 'application/jsonx+xml',
|
|
179
177
|
};
|
|
180
178
|
};
|
|
181
179
|
exports.createJsonxTypeEncoder = createJsonxTypeEncoder;
|
|
@@ -22,13 +22,9 @@ const encodeValue = (value) => {
|
|
|
22
22
|
return value;
|
|
23
23
|
};
|
|
24
24
|
const createUrlEncodedTypeEncoder = () => {
|
|
25
|
-
const encode = (data) => {
|
|
26
|
-
return (0, qs_1.stringify)(encodeValue(data), { encodeValuesOnly: true });
|
|
27
|
-
};
|
|
28
|
-
const contentType = 'application/x-www-form-urlencoded';
|
|
29
25
|
return {
|
|
30
|
-
encode,
|
|
31
|
-
contentType,
|
|
26
|
+
encode: (data) => (0, qs_1.stringify)(encodeValue(data), { encodeValuesOnly: true }),
|
|
27
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
32
28
|
};
|
|
33
29
|
};
|
|
34
30
|
exports.createUrlEncodedTypeEncoder = createUrlEncodedTypeEncoder;
|
|
@@ -3,11 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createYamlTypeEncoder = void 0;
|
|
4
4
|
const yaml_1 = require("yaml");
|
|
5
5
|
const createYamlTypeEncoder = () => {
|
|
6
|
-
const encode = (data) => (0, yaml_1.stringify)(data, { indent: 4 });
|
|
7
|
-
const contentType = 'application/x-yaml';
|
|
8
6
|
return {
|
|
9
|
-
encode,
|
|
10
|
-
contentType,
|
|
7
|
+
encode: (data) => (0, yaml_1.stringify)(data, { indent: 4 }),
|
|
8
|
+
contentType: 'application/x-yaml',
|
|
11
9
|
};
|
|
12
10
|
};
|
|
13
11
|
exports.createYamlTypeEncoder = createYamlTypeEncoder;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,33 +4,33 @@ export declare const DATATYPE_BOOLEAN = "json:boolean";
|
|
|
4
4
|
export declare const DATATYPE_STRING = "json:string";
|
|
5
5
|
export declare const DATATYPE_NUMBER = "json:number";
|
|
6
6
|
export declare const DATATYPE_NULL = "json:null";
|
|
7
|
-
export
|
|
7
|
+
export type WithName = {
|
|
8
8
|
':@': {
|
|
9
9
|
'@_name': string;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type JsonxNullNode = {
|
|
13
13
|
[DATATYPE_NULL]: Array<never>;
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type JsonxBooleanNode = {
|
|
16
16
|
[DATATYPE_BOOLEAN]: Array<{
|
|
17
17
|
'#text': boolean;
|
|
18
18
|
}>;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type JsonxNumberNode = {
|
|
21
21
|
[DATATYPE_NUMBER]: Array<{
|
|
22
22
|
'#text': number;
|
|
23
23
|
}>;
|
|
24
24
|
};
|
|
25
|
-
export
|
|
25
|
+
export type JsonxStringNode = {
|
|
26
26
|
[DATATYPE_STRING]: Array<{
|
|
27
27
|
'#text': string;
|
|
28
28
|
}>;
|
|
29
29
|
};
|
|
30
|
-
export
|
|
30
|
+
export type JsonxArrayNode = {
|
|
31
31
|
[DATATYPE_ARRAY]: Array<JsonxNullNode | JsonxBooleanNode | JsonxNumberNode | JsonxStringNode | JsonxArrayNode | JsonxObjectNode>;
|
|
32
32
|
};
|
|
33
|
-
export
|
|
33
|
+
export type JsonxObjectNode = {
|
|
34
34
|
[DATATYPE_OBJECT]: Array<JsonxNullNode | JsonxBooleanNode | JsonxNumberNode | JsonxStringNode | JsonxArrayNode | JsonxObjectNode>;
|
|
35
35
|
};
|
|
36
|
-
export
|
|
36
|
+
export type JsonxNode = JsonxNullNode | JsonxBooleanNode | JsonxNumberNode | JsonxStringNode | JsonxArrayNode | JsonxObjectNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chubbyts/chubbyts-decode-encode",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chubbyts",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"cs": "prettier --check src tests",
|
|
21
21
|
"test": "jest",
|
|
22
22
|
"infection": "stryker run",
|
|
23
|
-
"build": "tsc",
|
|
24
|
-
"prepare": "
|
|
23
|
+
"build": "rm -Rf dist && tsc",
|
|
24
|
+
"prepare": "npm run build"
|
|
25
25
|
},
|
|
26
26
|
"jest": {
|
|
27
27
|
"preset": "ts-jest",
|
|
@@ -49,20 +49,20 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@chubbyts/chubbyts-throwable-to-error": "^1.0.0",
|
|
52
|
-
"fast-xml-parser": "^4.
|
|
53
|
-
"qs": "^6.
|
|
54
|
-
"yaml": "^2.
|
|
52
|
+
"fast-xml-parser": "^4.1.3",
|
|
53
|
+
"qs": "^6.11.1",
|
|
54
|
+
"yaml": "^2.2.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@stryker-mutator/core": "^6.
|
|
58
|
-
"@stryker-mutator/jest-runner": "^6.
|
|
59
|
-
"@types/jest": "^
|
|
60
|
-
"@types/node": "^
|
|
57
|
+
"@stryker-mutator/core": "^6.4.1",
|
|
58
|
+
"@stryker-mutator/jest-runner": "^6.4.1",
|
|
59
|
+
"@types/jest": "^29.5.0",
|
|
60
|
+
"@types/node": "^18.15.3",
|
|
61
61
|
"@types/qs": "^6.9.7",
|
|
62
|
-
"jest": "^
|
|
63
|
-
"prettier": "^2.
|
|
64
|
-
"ts-jest": "^
|
|
65
|
-
"typescript": "^4.
|
|
62
|
+
"jest": "^29.5.0",
|
|
63
|
+
"prettier": "^2.8.4",
|
|
64
|
+
"ts-jest": "^29.0.5",
|
|
65
|
+
"typescript": "^4.9.5"
|
|
66
66
|
},
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|