tscommons-esm-config 0.0.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.
@@ -0,0 +1,31 @@
1
+ import { TPropertyObject } from 'tscommons-esm-core';
2
+ export declare class CommonsConfig {
3
+ private config;
4
+ static hasProperty(config: TPropertyObject, key: string): boolean;
5
+ static getObject(config: TPropertyObject, key: string, defaultValue?: TPropertyObject): TPropertyObject;
6
+ static getString(config: TPropertyObject, key: string, defaultValue?: string): string;
7
+ static getNumber(config: TPropertyObject, key: string, defaultValue?: number): number;
8
+ static getBoolean(config: TPropertyObject, key: string, defaultValue?: boolean): boolean;
9
+ static getDate(config: TPropertyObject, key: string, defaultValue?: Date): Date;
10
+ static setObject(config: TPropertyObject, key: string, data: TPropertyObject): void;
11
+ static setString(config: TPropertyObject, key: string, data: string): void;
12
+ static setNumber(config: TPropertyObject, key: string, data: number): void;
13
+ static setBoolean(config: TPropertyObject, key: string, data: boolean): void;
14
+ static setDate(config: TPropertyObject, key: string, data: Date): void;
15
+ constructor(config: TPropertyObject);
16
+ protected setRawObject(config: TPropertyObject): void;
17
+ protected getRawObject(): TPropertyObject;
18
+ cloneConfig(src: CommonsConfig): void;
19
+ hasProperty(key: string): boolean;
20
+ getObject(key: string, defaultValue?: TPropertyObject): TPropertyObject;
21
+ getObjectAsConfig(key: string, allowEmpty?: boolean): TPropertyObject;
22
+ getString(key: string, defaultValue?: string): string;
23
+ getNumber(key: string, defaultValue?: number): number;
24
+ getBoolean(key: string, defaultValue?: boolean): boolean;
25
+ getDate(key: string, defaultValue?: Date): Date;
26
+ setObject(key: string, data: TPropertyObject): void;
27
+ setString(key: string, data: string): void;
28
+ setNumber(key: string, data: number): void;
29
+ setBoolean(key: string, data: boolean): void;
30
+ setDate(key: string, data: Date): void;
31
+ }
@@ -0,0 +1,122 @@
1
+ import { commonsTypeHasProperty, commonsTypeHasPropertyObject, commonsTypeHasPropertyNumber, commonsTypeHasPropertyBoolean, commonsTypeHasPropertyString, commonsTypeHasPropertyDate } from 'tscommons-esm-core';
2
+ export class CommonsConfig {
3
+ config;
4
+ static hasProperty(config, key) {
5
+ return commonsTypeHasProperty(config, key);
6
+ }
7
+ static getObject(config, key, defaultValue) {
8
+ if (!CommonsConfig.hasProperty(config, key)) {
9
+ if (defaultValue !== undefined)
10
+ return defaultValue;
11
+ throw new Error(`No such key: ${key}`);
12
+ }
13
+ if (!commonsTypeHasPropertyObject(config, key))
14
+ throw new Error('Key value is not an object');
15
+ return config[key];
16
+ }
17
+ static getString(config, key, defaultValue) {
18
+ if (!CommonsConfig.hasProperty(config, key)) {
19
+ if (defaultValue !== undefined)
20
+ return defaultValue;
21
+ throw new Error(`No such key: ${key}`);
22
+ }
23
+ if (!commonsTypeHasPropertyString(config, key))
24
+ throw new Error('Key value is not a string');
25
+ return config[key];
26
+ }
27
+ static getNumber(config, key, defaultValue) {
28
+ if (!CommonsConfig.hasProperty(config, key)) {
29
+ if (defaultValue !== undefined)
30
+ return defaultValue;
31
+ throw new Error(`No such key: ${key}`);
32
+ }
33
+ if (!commonsTypeHasPropertyNumber(config, key))
34
+ throw new Error('Key value is not a number');
35
+ return config[key];
36
+ }
37
+ static getBoolean(config, key, defaultValue) {
38
+ if (!CommonsConfig.hasProperty(config, key)) {
39
+ if (defaultValue !== undefined)
40
+ return defaultValue;
41
+ throw new Error(`No such key: ${key}`);
42
+ }
43
+ if (!commonsTypeHasPropertyBoolean(config, key))
44
+ throw new Error('Key value is not a boolean');
45
+ return config[key] ? true : false;
46
+ }
47
+ static getDate(config, key, defaultValue) {
48
+ if (!CommonsConfig.hasProperty(config, key)) {
49
+ if (defaultValue !== undefined)
50
+ return defaultValue;
51
+ throw new Error(`No such key: ${key}`);
52
+ }
53
+ if (!commonsTypeHasPropertyDate(config, key))
54
+ throw new Error('Key value is not a Date');
55
+ return config[key];
56
+ }
57
+ static setObject(config, key, data) {
58
+ config[key] = data;
59
+ }
60
+ static setString(config, key, data) {
61
+ config[key] = data;
62
+ }
63
+ static setNumber(config, key, data) {
64
+ config[key] = data;
65
+ }
66
+ static setBoolean(config, key, data) {
67
+ config[key] = data;
68
+ }
69
+ static setDate(config, key, data) {
70
+ config[key] = data;
71
+ }
72
+ constructor(config) {
73
+ this.config = config;
74
+ }
75
+ setRawObject(config) {
76
+ this.config = config;
77
+ }
78
+ getRawObject() {
79
+ return this.config;
80
+ }
81
+ cloneConfig(src) {
82
+ this.setRawObject(src.getRawObject());
83
+ }
84
+ hasProperty(key) {
85
+ return CommonsConfig.hasProperty(this.config, key);
86
+ }
87
+ getObject(key, defaultValue) {
88
+ return CommonsConfig.getObject(this.config, key, defaultValue);
89
+ }
90
+ getObjectAsConfig(key, allowEmpty = false) {
91
+ const object = this.getObject(key, allowEmpty ? {} : undefined);
92
+ return new CommonsConfig(object);
93
+ }
94
+ getString(key, defaultValue) {
95
+ return CommonsConfig.getString(this.config, key, defaultValue);
96
+ }
97
+ getNumber(key, defaultValue) {
98
+ return CommonsConfig.getNumber(this.config, key, defaultValue);
99
+ }
100
+ getBoolean(key, defaultValue) {
101
+ return CommonsConfig.getBoolean(this.config, key, defaultValue);
102
+ }
103
+ getDate(key, defaultValue) {
104
+ return CommonsConfig.getDate(this.config, key, defaultValue);
105
+ }
106
+ setObject(key, data) {
107
+ return CommonsConfig.setObject(this.config, key, data);
108
+ }
109
+ setString(key, data) {
110
+ return CommonsConfig.setString(this.config, key, data);
111
+ }
112
+ setNumber(key, data) {
113
+ return CommonsConfig.setNumber(this.config, key, data);
114
+ }
115
+ setBoolean(key, data) {
116
+ return CommonsConfig.setBoolean(this.config, key, data);
117
+ }
118
+ setDate(key, data) {
119
+ return CommonsConfig.setDate(this.config, key, data);
120
+ }
121
+ }
122
+ //# sourceMappingURL=commons-config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commons-config.mjs","sourceRoot":"","sources":["../../src/classes/commons-config.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,4BAA4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,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;IAEM,OAAO,CAAC,GAAW,EAAE,IAAU;QACrC,OAAO,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;CACD"}
@@ -0,0 +1,2 @@
1
+ import { CommonsConfig } from './classes/commons-config.mjs';
2
+ export { CommonsConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { CommonsConfig } from './classes/commons-config.mjs';
2
+ export { CommonsConfig };
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EACN,aAAa,EACb,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "tscommons-esm-config",
3
+ "version": "0.0.2",
4
+ "description": "",
5
+ "scripts": {
6
+ "tsc": "./node_modules/typescript/bin/tsc",
7
+ "preprepare": "rm -rf ./dist; php ~/Dev/etim.php src/ && npm run tsc",
8
+ "publish-major": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version major && npm install && npm publish && git add . && git commit -m 'publish'",
9
+ "publish-minor": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version minor && npm install && npm publish && git add . && git commit -m 'publish'",
10
+ "publish-patch": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version patch && npm install && npm publish && git add . && git commit -m 'publish'"
11
+ },
12
+ "main": "dist/index.mjs",
13
+ "types": "dist/index.d.mjs",
14
+ "type": "module",
15
+ "author": "Pete Morris",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@stylistic/eslint-plugin-ts": "^2.10.1",
19
+ "eslint-plugin-import": "^2.31.0",
20
+ "eslint-plugin-prefer-arrow-functions": "^3.4.1",
21
+ "typescript": "^5.6.3",
22
+ "typescript-eslint": "^8.14.0"
23
+ },
24
+ "files": [
25
+ "dist/**/*"
26
+ ],
27
+ "dependencies": {
28
+ "tscommons-esm-core": "^0.0.2"
29
+ }
30
+ }