@esposter/shared 1.8.2 → 1.9.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/dist/index.d.ts CHANGED
@@ -1,2 +1,29 @@
1
+ declare const parseXmlString: (xmlString: string) => Promise<any>;
1
2
 
2
- export { }
3
+ declare const parseXmlValue: (value: string) => string | number | boolean;
4
+
5
+ declare enum Operation {
6
+ Push = "Push",
7
+ Read = "Read",
8
+ Create = "Create",
9
+ Update = "Update",
10
+ Delete = "Delete"
11
+ }
12
+
13
+ declare class InvalidOperationError extends Error {
14
+ constructor(operation: Operation, name: string, message: string);
15
+ }
16
+
17
+ declare class NotFoundError<T extends string = string> extends Error {
18
+ constructor(name: T, id: string);
19
+ }
20
+
21
+ declare class NotInitializedError<T extends string = string> extends Error {
22
+ constructor(name: T);
23
+ }
24
+
25
+ declare const capitalize: (string: string) => string;
26
+
27
+ declare const exhaustiveGuard: (value: never) => never;
28
+
29
+ export { InvalidOperationError, NotFoundError, NotInitializedError, Operation, capitalize, exhaustiveGuard, parseXmlString, parseXmlValue };
package/dist/index.js CHANGED
@@ -1 +1,61 @@
1
+ import parseDataUrl from 'data-urls';
2
+ import { parseStringPromise } from 'xml2js';
1
3
 
4
+ const parseXmlValue = (value) => {
5
+ if (value === "true")
6
+ return true;
7
+ if (value === "false")
8
+ return false;
9
+ if (/^[+-]?\d+(\.\d+)?$/g.test(value)) {
10
+ const parsedValue = parseFloat(value);
11
+ return isNaN(parsedValue) ? value : parsedValue;
12
+ }
13
+ return value;
14
+ };
15
+
16
+ const parseXmlString = async (xmlString) => {
17
+ const xml = parseDataUrl(xmlString) ?? xmlString;
18
+ return parseStringPromise(xml, {
19
+ explicitChildren: true,
20
+ preserveChildrenOrder: true,
21
+ attrValueProcessors: [(value) => parseXmlValue(value)],
22
+ });
23
+ };
24
+
25
+ class InvalidOperationError extends Error {
26
+ constructor(operation, name, message) {
27
+ super(`Invalid operation: ${operation}, name: ${name}, ${message}`);
28
+ this.name = "InvalidOperationError";
29
+ }
30
+ }
31
+
32
+ class NotFoundError extends Error {
33
+ constructor(name, id) {
34
+ super(`${name} is not found for id: ${id}`);
35
+ this.name = "NotFoundError";
36
+ }
37
+ }
38
+
39
+ class NotInitializedError extends Error {
40
+ constructor(name) {
41
+ super(`${name} is not initialized`);
42
+ this.name = "NotInitializedError";
43
+ }
44
+ }
45
+
46
+ var Operation;
47
+ (function (Operation) {
48
+ Operation["Push"] = "Push";
49
+ Operation["Read"] = "Read";
50
+ Operation["Create"] = "Create";
51
+ Operation["Update"] = "Update";
52
+ Operation["Delete"] = "Delete";
53
+ })(Operation || (Operation = {}));
54
+
55
+ const capitalize = (string) => `${string.charAt(0).toUpperCase()}${string.substring(1)}`;
56
+
57
+ const exhaustiveGuard = (value) => {
58
+ throw new InvalidOperationError(Operation.Read, exhaustiveGuard.name, JSON.stringify(value));
59
+ };
60
+
61
+ export { InvalidOperationError, NotFoundError, NotInitializedError, Operation, capitalize, exhaustiveGuard, parseXmlString, parseXmlValue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@esposter/shared",
3
- "version": "1.8.2",
3
+ "version": "1.9.0",
4
4
  "description": "Shareable typescript code",
5
5
  "type": "module",
6
6
  "homepage": "https://github.com/Esposter/Esposter#readme",
@@ -25,11 +25,11 @@
25
25
  "export:gen": "ctix build --config ../configuration/.ctirc"
26
26
  },
27
27
  "devDependencies": {
28
- "@esposter/configuration": "1.8.2",
28
+ "@esposter/configuration": "1.9.0",
29
29
  "@types/xml2js": "^0.4.14"
30
30
  },
31
31
  "dependencies": {
32
32
  "xml2js": "^0.6.2"
33
33
  },
34
- "gitHead": "1309cedda61626596ffec34619259fa275b9add0"
34
+ "gitHead": "59b5a81397421bd4d521b861791efe33fdf9b544"
35
35
  }