@esposter/shared 1.0.30

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.
@@ -0,0 +1,23 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export declare enum Operation {
4
+ Push = "Push",
5
+ Read = "Read",
6
+ Create = "Create",
7
+ Update = "Update",
8
+ Delete = "Delete"
9
+ }
10
+ export declare class InvalidOperationError extends Error {
11
+ constructor(operation: Operation, name: string, message: string);
12
+ }
13
+ export declare class NotFoundError<T extends string = string> extends Error {
14
+ constructor(name: T, id: string);
15
+ }
16
+ export declare class NotInitializedError<T extends string = string> extends Error {
17
+ constructor(name: T);
18
+ }
19
+ export declare const parseXmlString: (xmlString: string) => Promise<any>;
20
+ export declare const parseXmlValue: (value: string) => string | number | boolean;
21
+ export declare const exhaustiveGuard: (value: never) => never;
22
+
23
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ import parseDataUrl from 'data-urls';
2
+ import { parseStringPromise } from 'xml2js';
3
+
4
+ class InvalidOperationError extends Error {
5
+ constructor(operation, name, message) {
6
+ super(`Invalid operation: ${operation}, name: ${name}, ${message}`);
7
+ this.name = "InvalidOperationError";
8
+ }
9
+ }
10
+
11
+ class NotFoundError extends Error {
12
+ constructor(name, id) {
13
+ super(`${name} is not found for id: ${id}`);
14
+ this.name = "NotFoundError";
15
+ }
16
+ }
17
+
18
+ class NotInitializedError extends Error {
19
+ constructor(name) {
20
+ super(`${name} is not initialized`);
21
+ this.name = "NotInitializedError";
22
+ }
23
+ }
24
+
25
+ var Operation;
26
+ (function (Operation) {
27
+ Operation["Push"] = "Push";
28
+ Operation["Read"] = "Read";
29
+ Operation["Create"] = "Create";
30
+ Operation["Update"] = "Update";
31
+ Operation["Delete"] = "Delete";
32
+ })(Operation || (Operation = {}));
33
+
34
+ const parseXmlValue = (value) => {
35
+ if (value === "true")
36
+ return true;
37
+ if (value === "false")
38
+ return false;
39
+ if (/^[+-]?\d+(\.\d+)?$/g.test(value)) {
40
+ const parsedValue = parseFloat(value);
41
+ return isNaN(parsedValue) ? value : parsedValue;
42
+ }
43
+ return value;
44
+ };
45
+
46
+ const parseXmlString = async (xmlString) => {
47
+ const xml = parseDataUrl(xmlString) ?? xmlString;
48
+ return parseStringPromise(xml, {
49
+ explicitChildren: true,
50
+ preserveChildrenOrder: true,
51
+ attrValueProcessors: [(value) => parseXmlValue(value)],
52
+ });
53
+ };
54
+
55
+ const exhaustiveGuard = (value) => {
56
+ throw new InvalidOperationError(Operation.Read, exhaustiveGuard.name, JSON.stringify(value));
57
+ };
58
+
59
+ export { InvalidOperationError, NotFoundError, NotInitializedError, Operation, exhaustiveGuard, parseXmlString, parseXmlValue };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@esposter/shared",
3
+ "version": "1.0.30",
4
+ "description": "Shared code",
5
+ "type": "module",
6
+ "homepage": "https://github.com/Esposter/Esposter#readme",
7
+ "license": "Apache-2.0",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Esposter/Esposter.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/Esposter/Esposter/issues"
22
+ },
23
+ "scripts": {
24
+ "build": "rollup --config rollup.config.ts --configPlugin typescript && pnpm run types:gen",
25
+ "lint": "eslint --config ../../eslint.light.config.js .",
26
+ "lint:fix": "eslint --config ../../eslint.light.config.js --fix .",
27
+ "typecheck": "tsc --noEmit",
28
+ "types:gen": "dts-bundle-generator -o dist/index.d.ts src/index.ts"
29
+ },
30
+ "devDependencies": {
31
+ "@rollup/plugin-typescript": "^11.1.6",
32
+ "@types/data-urls": "^3.0.4",
33
+ "@types/xml2js": "^0.4.14",
34
+ "dts-bundle-generator": "^9.5.1",
35
+ "eslint": "^9.2.0",
36
+ "rollup": "^4.17.2",
37
+ "typescript": "^5.4.5"
38
+ },
39
+ "dependencies": {
40
+ "data-urls": "^5.0.0",
41
+ "xml2js": "^0.6.2"
42
+ },
43
+ "gitHead": "000547393d835453249a06f46fc9e652eea3119e"
44
+ }