@chubbyts/chubbyts-decode-encode 2.3.0 → 2.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # chubbyts-decode-encode
2
2
 
3
- [![CI](https://github.com/chubbyts/chubbyts-decode-encode/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-decode-encode/actions?query=workflow%3ACI)
3
+ [![CI](https://github.com/chubbyts/chubbyts-decode-encode/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-decode-encode/actions/workflows/ci.yml)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/chubbyts/chubbyts-decode-encode/badge.svg?branch=master)](https://coveralls.io/github/chubbyts/chubbyts-decode-encode?branch=master)
5
5
  [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyts%2Fchubbyts-decode-encode%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyts/chubbyts-decode-encode/master)
6
6
  [![npm-version](https://img.shields.io/npm/v/@chubbyts/chubbyts-decode-encode.svg)](https://www.npmjs.com/package/@chubbyts/chubbyts-decode-encode)
@@ -24,17 +24,18 @@ A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.
24
24
  ## Requirements
25
25
 
26
26
  * node: 22
27
- * [@chubbyts/chubbyts-throwable-to-error][2]: ^2.2.0
28
- * [fast-xml-parser][3]: ^5.7.3
29
- * [qs][4]: ^6.15.1
30
- * [yaml][5]: ^2.8.4
27
+ * [@chubbyts/chubbyts-throwable-to-error][2]: ^2.3.0
28
+ * [fast-xml-builder][3]: ^1.3.0
29
+ * [fast-xml-parser][4]: ^5.10.1
30
+ * [qs][5]: ^6.15.3
31
+ * [yaml][6]: ^2.9.0
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.3.0
38
+ npm i @chubbyts/chubbyts-decode-encode@^2.4.1
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-parser
183
- [4]: https://www.npmjs.com/package/qs
184
- [5]: https://www.npmjs.com/package/yaml
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/data.js CHANGED
@@ -3,4 +3,12 @@ export const isBoolean = (value) => typeof value === 'boolean';
3
3
  export const isNumber = (value) => typeof value === 'number';
4
4
  export const isString = (value) => typeof value === 'string';
5
5
  export const isArray = (value) => Array.isArray(value);
6
- export const isObject = (value) => value !== null && typeof value === 'object' && value.constructor.name == 'Object';
6
+ export const isObject = (value) => {
7
+ if (value === null || typeof value !== 'object') {
8
+ return false;
9
+ }
10
+ // prototype based check: constructor based checks crash on null prototype objects (Object.create(null))
11
+ // and can be shadowed by an attacker controlled own "constructor" property (e.g. {"constructor": 1})
12
+ const prototype = Object.getPrototypeOf(value);
13
+ return prototype === Object.prototype || prototype === null;
14
+ };
@@ -1,6 +1,7 @@
1
1
  export class DecodeError extends Error {
2
2
  constructor(message, stack) {
3
3
  super(message);
4
+ // oxlint-disable-next-line functional/immutable-data
4
5
  this.stack = stack;
5
6
  }
6
7
  }
@@ -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(/&#\d+;/gm, (code) => String.fromCharCode(code.match(/\d+/)[0]));
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
  }
@@ -1,6 +1,7 @@
1
1
  export class EncodeError extends Error {
2
2
  constructor(message, stack) {
3
3
  super(message);
4
+ // oxlint-disable-next-line functional/immutable-data
4
5
  this.stack = stack;
5
6
  }
6
7
  }
@@ -1,16 +1,13 @@
1
- import { XMLBuilder } from 'fast-xml-parser';
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.charCodeAt(0) + ';');
6
+ const encodeHtmlEntities = (string) => string.replace(/[\u00A0-\u9999<>&]/g, (i) => '&#' + i.codePointAt(0) + ';');
7
7
  const createXmlNode = () => {
8
8
  return {
9
- '?xml': [
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 XMLBuilder({
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.3.0",
4
+ "version": "2.4.1",
5
5
  "description": "A simple decode/encode solution for json / jsonx / url-encoded / xml / yaml.",
6
6
  "keywords": [
7
7
  "chubbyts",
@@ -15,7 +15,10 @@
15
15
  ],
16
16
  "author": "Dominik Zogg",
17
17
  "license": "MIT",
18
- "repository": "chubbyts/chubbyts-decode-encode",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "chubbyts/chubbyts-decode-encode"
21
+ },
19
22
  "prettier": {
20
23
  "printWidth": 120,
21
24
  "tabWidth": 2,
@@ -51,22 +54,24 @@
51
54
  "node": ">=22"
52
55
  },
53
56
  "dependencies": {
54
- "@chubbyts/chubbyts-throwable-to-error": "^2.2.0",
55
- "fast-xml-parser": "^5.7.3",
56
- "qs": "^6.15.1",
57
- "yaml": "^2.8.4"
57
+ "@chubbyts/chubbyts-throwable-to-error": "^2.3.0",
58
+ "fast-xml-builder": "^1.3.0",
59
+ "fast-xml-parser": "^5.10.1",
60
+ "qs": "^6.15.3",
61
+ "yaml": "^2.9.0"
58
62
  },
59
63
  "devDependencies": {
60
- "@chubbyts/chubbyts-eslint": "^5.2.0",
61
- "@chubbyts/chubbyts-function-mock": "^2.1.1",
64
+ "@chubbyts/chubbyts-function-mock": "^2.3.0",
65
+ "@chubbyts/chubbyts-oxlint": "^1.0.0",
62
66
  "@stryker-mutator/core": "^9.6.1",
63
67
  "@stryker-mutator/vitest-runner": "^9.6.1",
64
- "@types/node": "^25.6.2",
68
+ "@types/node": "^26.1.2",
65
69
  "@types/qs": "^6.15.1",
66
- "@vitest/coverage-v8": "^4.1.5",
67
- "prettier": "^3.8.3",
68
- "typescript": "^6.0.3",
69
- "vitest": "^4.1.5"
70
+ "@vitest/coverage-v8": "^4.1.10",
71
+ "oxlint": "^1.76.0",
72
+ "prettier": "^3.9.6",
73
+ "typescript": "^7.0.2",
74
+ "vitest": "^4.1.10"
70
75
  },
71
76
  "publishConfig": {
72
77
  "access": "public"
@@ -76,8 +81,8 @@
76
81
  "cs-fix": "prettier --write src tests",
77
82
  "cs": "prettier --check src tests",
78
83
  "infection": "stryker run",
79
- "lint-fix": "eslint src tests eslint.config.js vitest.config.ts --fix",
80
- "lint": "eslint src tests",
84
+ "lint-fix": "oxlint --fix src tests vitest.config.ts",
85
+ "lint": "oxlint src tests vitest.config.ts",
81
86
  "test": "vitest"
82
87
  }
83
88
  }