node-confmanager 1.9.0 → 1.11.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2024, Sébastien Vidal
1
+ Copyright (c) 2026, Sébastien Vidal
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any
4
4
  purpose with or without fee is hereby granted, provided that the above
package/README.md CHANGED
@@ -1,64 +1,69 @@
1
- # node-confmanager
2
- A configuration manager
3
-
4
- [![Build status](https://api.travis-ci.org/Psychopoulet/node-confmanager.svg?branch=master)](https://travis-ci.org/Psychopoulet/node-confmanager)
5
- [![Coverage status](https://coveralls.io/repos/github/Psychopoulet/node-confmanager/badge.svg?branch=master)](https://coveralls.io/github/Psychopoulet/node-confmanager)
6
- [![Dependency status](https://david-dm.org/Psychopoulet/node-confmanager/status.svg)](https://david-dm.org/Psychopoulet/node-confmanager)
7
- [![Dev dependency status](https://david-dm.org/Psychopoulet/node-confmanager/dev-status.svg)](https://david-dm.org/Psychopoulet/node-confmanager?type=dev)
8
- [![Issues](https://img.shields.io/github/issues/Psychopoulet/node-confmanager.svg)](https://github.com/Psychopoulet/node-confmanager/issues)
9
- [![Pull requests](https://img.shields.io/github/issues-pr/Psychopoulet/node-confmanager.svg)](https://github.com/Psychopoulet/node-confmanager/pulls)
10
-
11
- ## Installation
12
-
13
- ```bash
14
- $ npm install node-confmanager
15
- ```
16
-
17
- ## Features
18
-
19
- * All the features of the [node-containerpattern](https://www.npmjs.com/package/node-containerpattern) package
20
- * clone data in "get" action to avoid unwanted changes
21
- * Saving the data in a JSON file
22
- * Load the data from this JSON file and/or commandline
23
- * access to the data with shortcuts in commandline
24
-
25
- ## Doc
26
-
27
- ### Inheritance
28
-
29
- [check the official 'node-containerpattern' object documentation](https://github.com/Psychopoulet/node-containerpattern)
30
-
31
- ### Content
32
-
33
- [check the TypeScript definition file](https://github.com/Psychopoulet/node-confmanager/blob/master/lib/index.d.ts)
34
-
35
- ## Examples
36
-
37
- [check the TypeScript compilation tests](https://github.com/Psychopoulet/node-confmanager/blob/master/test/typescript/compilation.ts)
38
-
39
- ### Run
40
-
41
- ```bash
42
- # if "debug" skeleton is setted & defined as a boolean
43
- node mysoft.js -d # if "debug" shortcut is setted
44
- node mysoft.js --debug
45
- node mysoft.js --debug "true"
46
- node mysoft.js --debug "yes"
47
- node mysoft.js --debug "y"
48
- ```
49
-
50
- ```bash
51
- # if "arr" skeleton is defined as a array
52
- node mysoft.js --arr test1 test2
53
- node mysoft.js --arr "[ \"test1\", \"test2\" ]"
54
- ```
55
-
56
- ## Tests
57
-
58
- ```bash
59
- $ npm run-script tests
60
- ```
61
-
62
- ## License
63
-
64
- [ISC](LICENSE)
1
+ # node-confmanager
2
+ A configuration manager
3
+
4
+ [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_node-confmanager&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
5
+ [![Issues](https://img.shields.io/github/issues/Psychopoulet/node-confmanager.svg)](https://github.com/Psychopoulet/node-confmanager/issues)
6
+ [![Pull requests](https://img.shields.io/github/issues-pr/Psychopoulet/node-confmanager.svg)](https://github.com/Psychopoulet/node-confmanager/pulls)
7
+
8
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_node-confmanager&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
9
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_node-confmanager&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
10
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_node-confmanager&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
11
+ [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_node-confmanager&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
12
+ [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_node-confmanager&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_node-confmanager)
13
+
14
+ [![Known Vulnerabilities](https://snyk.io/test/github/Psychopoulet/node-confmanager/badge.svg)](https://snyk.io/test/github/Psychopoulet/node-confmanager)
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ $ npm install node-confmanager
20
+ ```
21
+
22
+ ## Features
23
+
24
+ * All the features of the [node-containerpattern](https://www.npmjs.com/package/node-containerpattern) package
25
+ * clone data in "get" action to avoid unwanted changes
26
+ * Saving the data in a JSON file
27
+ * Load the data from this JSON file and/or commandline
28
+ * access to the data with shortcuts in commandline
29
+
30
+ ## Doc
31
+
32
+ ### Inheritance
33
+
34
+ [check the official 'node-containerpattern' object documentation](https://github.com/Psychopoulet/node-containerpattern)
35
+
36
+ ### Content
37
+
38
+ [check the TypeScript definition file](https://github.com/Psychopoulet/node-confmanager/blob/master/lib/index.d.ts)
39
+
40
+ ## Examples
41
+
42
+ [check the TypeScript compilation tests](https://github.com/Psychopoulet/node-confmanager/blob/master/test/typescript/compilation.ts)
43
+
44
+ ### Run
45
+
46
+ ```bash
47
+ # if "debug" skeleton is setted & defined as a boolean
48
+ node mysoft.js -d # if "debug" shortcut is setted
49
+ node mysoft.js --debug
50
+ node mysoft.js --debug "true"
51
+ node mysoft.js --debug "yes"
52
+ node mysoft.js --debug "y"
53
+ ```
54
+
55
+ ```bash
56
+ # if "arr" skeleton is defined as a array
57
+ node mysoft.js --arr test1 test2
58
+ node mysoft.js --arr "[ \"test1\", \"test2\" ]"
59
+ ```
60
+
61
+ ## Tests
62
+
63
+ ```bash
64
+ $ npm run-script tests
65
+ ```
66
+
67
+ ## License
68
+
69
+ [ISC](LICENSE)
@@ -1,4 +1,4 @@
1
- import NodeContainerPattern = require("node-containerpattern");
1
+ import NodeContainerPattern from "node-containerpattern";
2
2
  export default class ConfManager extends NodeContainerPattern {
3
3
  filePath: string;
4
4
  spaces: boolean;
@@ -9,7 +9,7 @@ export default class ConfManager extends NodeContainerPattern {
9
9
  clearShortcuts(): this;
10
10
  deleteFile(): Promise<void>;
11
11
  fileExists(): Promise<boolean>;
12
- get(key: string): any;
12
+ get(key: string): unknown;
13
13
  load(loadConsole?: boolean): Promise<void>;
14
14
  save(): Promise<void>;
15
15
  shortcut(_key: string, _shortkey: string): this;
@@ -8,20 +8,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  const node_path_1 = require("node:path");
9
9
  const promises_1 = require("node:fs/promises");
10
10
  // externals
11
- const NodeContainerPattern = require("node-containerpattern");
11
+ const node_containerpattern_1 = __importDefault(require("node-containerpattern"));
12
12
  // locals
13
13
  const checkShortcut_1 = __importDefault(require("./utils/checkShortcut"));
14
14
  const clone_1 = __importDefault(require("./utils/clone"));
15
15
  const isFile_1 = __importDefault(require("./utils/isFile"));
16
16
  // module
17
- class ConfManager extends NodeContainerPattern {
17
+ class ConfManager extends node_containerpattern_1.default {
18
+ // attributes
19
+ // public
20
+ filePath;
21
+ spaces;
22
+ shortcuts;
18
23
  // constructor
19
24
  constructor(filePath, spaces = false, recursionSeparator = ".") {
20
25
  if ("undefined" !== typeof filePath && "string" !== typeof filePath) {
21
26
  throw new TypeError("\"filePath\" parameter is not a string");
22
27
  }
23
- else if ("undefined" !== typeof filePath && "" === filePath.trim()) {
24
- throw new Error("\"filePath\" parameter is empty");
28
+ else if ("string" === typeof filePath && "" === filePath.trim()) {
29
+ throw new RangeError("\"filePath\" parameter is empty");
25
30
  }
26
31
  else if ("undefined" !== typeof spaces && "boolean" !== typeof spaces) {
27
32
  throw new TypeError("The \"spaces\" parameter is not a boolean");
@@ -29,8 +34,8 @@ class ConfManager extends NodeContainerPattern {
29
34
  else if ("undefined" !== typeof recursionSeparator && "string" !== typeof recursionSeparator) {
30
35
  throw new TypeError("The \"recursionSeparator\" parameter is not a string");
31
36
  }
32
- else if ("undefined" !== typeof recursionSeparator && "" === recursionSeparator.trim()) {
33
- throw new Error("\"recursionSeparator\" parameter is empty");
37
+ else if ("string" === typeof recursionSeparator && "" === recursionSeparator.trim()) {
38
+ throw new RangeError("\"recursionSeparator\" parameter is empty");
34
39
  }
35
40
  else {
36
41
  super(recursionSeparator);
@@ -51,7 +56,7 @@ class ConfManager extends NodeContainerPattern {
51
56
  if (argument && (!isShortcut || this.shortcuts[argument])) {
52
57
  const key = isShortcut ? this.shortcuts[argument] : argument;
53
58
  // boolean
54
- if (this.skeletons[key] && "boolean" === this.skeletons[key]) {
59
+ if ("string" === typeof this.skeletons[key] && "boolean" === this.skeletons[key]) {
55
60
  this.set(key, true);
56
61
  }
57
62
  // check args
@@ -70,7 +75,7 @@ class ConfManager extends NodeContainerPattern {
70
75
  if (nextArgs.length) {
71
76
  const endArrayArgs = nextArgs.findIndex((a) => {
72
77
  return a.startsWith("--")
73
- || (a.startsWith("-") && !!this.shortcuts[a.slice(1)]);
78
+ || (a.startsWith("-") && Boolean(this.shortcuts[a.slice(1)]));
74
79
  });
75
80
  const values = 0 < endArrayArgs ? nextArgs.slice(0, endArrayArgs) : nextArgs;
76
81
  if (1 === values.length && values[0].startsWith("[") && values[0].endsWith("]")) {
@@ -118,21 +123,18 @@ class ConfManager extends NodeContainerPattern {
118
123
  this.clearData();
119
124
  return this.fileExists().then((exists) => {
120
125
  if (!exists) {
121
- if (loadConsole) {
122
- this._loadFromConsole();
123
- }
126
+ return Promise.resolve();
124
127
  }
125
- else {
126
- return (0, promises_1.readFile)(this.filePath, "utf-8").then((content) => {
127
- return JSON.parse(content);
128
- }).then((data) => {
129
- for (const key in data) {
130
- this.set(key, data[key]);
131
- }
132
- if (loadConsole) {
133
- this._loadFromConsole();
134
- }
135
- });
128
+ return (0, promises_1.readFile)(this.filePath, "utf-8").then((content) => {
129
+ return JSON.parse(content);
130
+ }).then((data) => {
131
+ for (const key in data) {
132
+ this.set(key, data[key]);
133
+ }
134
+ });
135
+ }).then(() => {
136
+ if (loadConsole) {
137
+ this._loadFromConsole();
136
138
  }
137
139
  });
138
140
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  // module
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = checkShortcut;
4
5
  function checkShortcut(key, shortkey) {
5
6
  if ("undefined" === typeof key) {
6
7
  throw new ReferenceError("Missing \"key\" parameter");
@@ -27,4 +28,3 @@ function checkShortcut(key, shortkey) {
27
28
  };
28
29
  }
29
30
  }
30
- exports.default = checkShortcut;
@@ -1 +1 @@
1
- export default function clone(from: any): any;
1
+ export default function clone(from: unknown): unknown;
@@ -1,20 +1,19 @@
1
1
  "use strict";
2
2
  // module
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = clone;
4
5
  function clone(from) {
5
- if (from && "object" === typeof from) {
6
+ if ("object" === typeof from && null !== from) {
6
7
  if (Object === from.constructor) {
7
- return Object.assign({}, from);
8
+ return { ...from };
8
9
  }
9
10
  else if (Array.isArray(from)) {
10
11
  return [...from];
11
12
  }
12
13
  else {
13
- return new from.constructor(from);
14
+ const FromConstructor = from.constructor;
15
+ return new FromConstructor(from);
14
16
  }
15
17
  }
16
- else {
17
- return from;
18
- }
18
+ return from;
19
19
  }
20
- exports.default = clone;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  // deps
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = isFile;
4
5
  // natives
5
6
  const node_fs_1 = require("node:fs");
6
7
  // module
@@ -22,4 +23,3 @@ function isFile(file) {
22
23
  }
23
24
  });
24
25
  }
25
- exports.default = isFile;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
 
3
3
  "name": "node-confmanager",
4
- "version": "1.9.0",
5
- "description": "A configuration manager",
4
+ "version": "1.11.0",
5
+ "description": "A configuration manager.",
6
6
 
7
7
  "type": "commonjs",
8
8
  "typings": "./lib/cjs/main.d.cts",
@@ -19,49 +19,54 @@
19
19
 
20
20
  "scripts": {
21
21
 
22
- "prepare": "npx husky install",
22
+ "prepare": "npx husky || true",
23
23
 
24
- "clean": "npx rimraf lib",
25
- "build": "npm run-script clean && npx tsc --project \"./tsconfig.json\"",
24
+ "lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
25
+ "lint-tests": "npx eslint --config .eslintrc-tests.js --ext .js,.cjs,.mjs ./test/**/*",
26
+ "lint": "npm run lint-back && npm run lint-tests",
26
27
 
27
- "lint": "npx eslint --config .eslintrc-src.js --ext .cts,.ts ./src/**/* && npx eslint --config .eslintrc-tests.js ./test/**/*.js",
28
- "check-requires": "npx used-deps-analyzer \"./package.json\" \"./src\" --no-dev --overkill \"fs-extra\" \"node-promfs\"",
29
- "check-updates": "npx check-version-modules",
30
- "unit-tests": "npm run build && npx nyc --reporter=html --reporter=text mocha",
28
+ "clean-back": "npx rimraf ./lib/cjs",
29
+ "clean": "npm run clean-back",
31
30
 
32
- "tests": "npm run-script lint && npm run check-requires && npm run-script check-updates && npm run-script unit-tests"
31
+ "build-back": "npm run clean-back && npx tsc --project ./tsconfig.json",
32
+ "build": "npm run build-back",
33
+
34
+ "check-requires": "npx used-deps-analyzer ./package.json ./lib/src --no-dev",
35
+ "check-updates": "npx check-version-modules --no-fail-at-major --fail-at-minor --fail-at-patch",
36
+ "unit-tests": "npx mocha",
37
+ "unit-tests-local": "npx nyc --reporter=html --reporter=text mocha",
38
+
39
+ "tests": "npm run lint && npm run check-requires && npm run check-updates && npm run build && npm run unit-tests-local"
33
40
 
34
41
  },
35
42
 
36
43
  "files": [
37
- "/bin",
38
- "/lib",
39
- "/public"
44
+ "lib/cjs"
40
45
  ],
41
46
  "engines": {
42
- "node": ">=16.0.0"
47
+ "node": ">=22.22.0"
43
48
  },
44
49
 
45
50
  "dependencies": {
46
- "node-containerpattern": "1.8.0"
51
+ "node-containerpattern": "1.10.0"
47
52
  },
48
53
  "devDependencies": {
49
- "@types/node": "20.11.0",
50
- "check-version-modules": "2.0.0",
54
+ "@types/node": "25.6.0",
55
+ "check-version-modules": "2.3.0",
51
56
  "colors": "1.4.0",
52
57
  "eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
53
- "husky": "8.0.3",
54
- "mocha": "10.2.0",
55
- "nyc": "15.1.0",
56
- "rimraf": "5.0.5",
57
- "typescript": "5.3.3",
58
- "used-deps-analyzer": "0.1.8"
58
+ "husky": "9.1.7",
59
+ "mocha": "11.7.5",
60
+ "nyc": "18.0.0",
61
+ "rimraf": "6.1.3",
62
+ "typescript": "5.9.3",
63
+ "used-deps-analyzer": "0.3.0"
59
64
  },
60
- "optionalDependencies": {},
61
65
 
62
66
  "husky": {
63
67
  "hooks": {
64
- "pre-push": "npm run-script tests"
68
+ "pre-commit": "npm run lint",
69
+ "pre-push": "npm run build && npm run unit-tests-local"
65
70
  }
66
71
  },
67
72
  "keywords": [