@chubbyts/chubbyts-decode-encode 1.1.1 → 1.1.3

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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022 Dominik Zogg
1
+ Copyright (c) 2023 Dominik Zogg
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
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.0.10
29
- * [qs][4]: ^6.11.0
30
- * [yaml][5]: ^2.1.1
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.1
37
+ npm i @chubbyts/chubbyts-decode-encode@^1.1.3
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 2022
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
@@ -1,11 +1,11 @@
1
1
  import { Data } from '..';
2
2
  export declare class DecodeError extends Error {
3
3
  }
4
- export declare type TypeDecoder = {
4
+ export type TypeDecoder = {
5
5
  decode: (encodedData: string) => Data;
6
6
  contentType: string;
7
7
  };
8
- export declare type Decoder = {
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
- contentType,
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
- contentType,
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;
@@ -30,13 +30,9 @@ const decodeValue = (value) => {
30
30
  return value;
31
31
  };
32
32
  const createUrlEncodedTypeDecoder = () => {
33
- const decode = (encodedData) => {
34
- return decodeValue((0, qs_1.parse)(encodedData, { depth: 100 }));
35
- };
36
- const contentType = 'application/x-www-form-urlencoded';
37
33
  return {
38
- decode,
39
- contentType,
34
+ decode: (encodedData) => decodeValue((0, qs_1.parse)(encodedData, { depth: 100 })),
35
+ contentType: 'application/x-www-form-urlencoded',
40
36
  };
41
37
  };
42
38
  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
- contentType,
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;
@@ -1,11 +1,11 @@
1
1
  import { Data } from '..';
2
2
  export declare class EncodeError extends Error {
3
3
  }
4
- export declare type TypeEncoder = {
4
+ export type TypeEncoder = {
5
5
  encode: (data: Data) => string;
6
6
  contentType: string;
7
7
  };
8
- export declare type Encoder = {
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
- contentType,
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
@@ -1,4 +1,4 @@
1
- export declare type Data = {
1
+ export type Data = {
2
2
  [key: string]: Data;
3
3
  } | Array<Data> | string | number | boolean | null;
4
4
  export declare const isNull: (value: unknown) => value is null;
@@ -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 declare type WithName = {
7
+ export type WithName = {
8
8
  ':@': {
9
9
  '@_name': string;
10
10
  };
11
11
  };
12
- export declare type JsonxNullNode = {
12
+ export type JsonxNullNode = {
13
13
  [DATATYPE_NULL]: Array<never>;
14
14
  };
15
- export declare type JsonxBooleanNode = {
15
+ export type JsonxBooleanNode = {
16
16
  [DATATYPE_BOOLEAN]: Array<{
17
17
  '#text': boolean;
18
18
  }>;
19
19
  };
20
- export declare type JsonxNumberNode = {
20
+ export type JsonxNumberNode = {
21
21
  [DATATYPE_NUMBER]: Array<{
22
22
  '#text': number;
23
23
  }>;
24
24
  };
25
- export declare type JsonxStringNode = {
25
+ export type JsonxStringNode = {
26
26
  [DATATYPE_STRING]: Array<{
27
27
  '#text': string;
28
28
  }>;
29
29
  };
30
- export declare type JsonxArrayNode = {
30
+ export type JsonxArrayNode = {
31
31
  [DATATYPE_ARRAY]: Array<JsonxNullNode | JsonxBooleanNode | JsonxNumberNode | JsonxStringNode | JsonxArrayNode | JsonxObjectNode>;
32
32
  };
33
- export declare type JsonxObjectNode = {
33
+ export type JsonxObjectNode = {
34
34
  [DATATYPE_OBJECT]: Array<JsonxNullNode | JsonxBooleanNode | JsonxNumberNode | JsonxStringNode | JsonxArrayNode | JsonxObjectNode>;
35
35
  };
36
- export declare type JsonxNode = JsonxNullNode | JsonxBooleanNode | JsonxNumberNode | JsonxStringNode | JsonxArrayNode | JsonxObjectNode;
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.1",
3
+ "version": "1.1.3",
4
4
  "description": "A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.",
5
5
  "keywords": [
6
6
  "chubbyts",
@@ -49,20 +49,20 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@chubbyts/chubbyts-throwable-to-error": "^1.0.0",
52
- "fast-xml-parser": "^4.0.10",
53
- "qs": "^6.11.0",
54
- "yaml": "^2.1.1"
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.2.2",
58
- "@stryker-mutator/jest-runner": "^6.2.2",
59
- "@types/jest": "^29.0.3",
60
- "@types/node": "^14.18.29",
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": "^29.0.3",
63
- "prettier": "^2.7.1",
64
- "ts-jest": "^29.0.1",
65
- "typescript": "^4.8.3"
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"