node-confmanager 1.4.4 → 1.4.7

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/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- declare module "node-confmanager" {
1
+ /// <reference types="node" />
2
2
 
3
- type tType = "array" | "boolean" | "color" | "email" | "float" | "ipv4" | "ipv6" | "integer" | "object" | "string" | "url";
3
+ declare module "node-confmanager" {
4
4
 
5
5
  import Container = require("node-containerpattern");
6
6
 
@@ -14,32 +14,15 @@ declare module "node-confmanager" {
14
14
 
15
15
  protected _loadFromConsole(): Promise<void>;
16
16
 
17
- public shortcut(key: string, shortkey: string): ConfManager;
18
- public clearShortcuts(): ConfManager;
19
- public clear(): ConfManager;
17
+ public shortcut(key: string, shortkey: string): this;
18
+ public clearShortcuts(): this;
19
+ public clear(): this;
20
20
  public deleteFile(): Promise<void>;
21
21
  public get(key: string): any;
22
22
  public fileExists(): Promise<boolean>;
23
23
  public load(): Promise<void>;
24
24
  public save(): Promise<void>;
25
25
 
26
- // rewrite to force proper return
27
- public clear(): ConfManager;
28
- public clearData(): ConfManager;
29
- public clearDocumentations(): ConfManager;
30
- public clearLimits(): ConfManager;
31
- public clearMinsMaxs(): ConfManager;
32
- public clearRegexs(): ConfManager;
33
- public clearSkeletons(): ConfManager;
34
- public delete(key: string): ConfManager;
35
- public document(key: string, value: string): ConfManager;
36
- public limit(key: string, limit: Array<any>): ConfManager;
37
- public min(key: string, min: number): ConfManager;
38
- public max(key: string, max: number): ConfManager;
39
- public regex(key: string, regex: RegExp): ConfManager;
40
- public set(key: string, value: any): ConfManager;
41
- public skeleton(key: string, value: tType): ConfManager;
42
-
43
26
  }
44
27
 
45
28
  export = ConfManager;
package/lib/main.js CHANGED
@@ -6,7 +6,7 @@
6
6
  const { dirname, join } = require("path");
7
7
 
8
8
  // externals
9
- const { isFileProm, mkdirpProm, readJSONFileProm, unlinkProm, writeJSONFileProm } = require("node-promfs");
9
+ const { pathExists, mkdirp, readJson, unlink, writeJson } = require("fs-extra");
10
10
  const Container = require("node-containerpattern");
11
11
 
12
12
  // locals
@@ -107,11 +107,15 @@ module.exports = class ConfManager extends Container {
107
107
  }
108
108
 
109
109
  deleteFile () {
110
- return !this.filePath ? Promise.resolve() : unlinkProm(this.filePath);
110
+
111
+ return !this.filePath ? Promise.resolve() : pathExists(this.filePath).then((exists) => {
112
+ return exists ? unlink(this.filePath) : Promise.resolve();
113
+ });
114
+
111
115
  }
112
116
 
113
117
  fileExists () {
114
- return !this.filePath ? Promise.resolve(false) : isFileProm(this.filePath);
118
+ return !this.filePath ? Promise.resolve(false) : pathExists(this.filePath);
115
119
  }
116
120
 
117
121
  load () {
@@ -120,7 +124,7 @@ module.exports = class ConfManager extends Container {
120
124
 
121
125
  return this.fileExists().then((exists) => {
122
126
 
123
- return !exists ? this._loadFromConsole() : readJSONFileProm(this.filePath, "utf8").then((data) => {
127
+ return !exists ? this._loadFromConsole() : readJson(this.filePath, "utf8").then((data) => {
124
128
 
125
129
  for (const key in data) {
126
130
  this.set(key, data[key]);
@@ -136,21 +140,19 @@ module.exports = class ConfManager extends Container {
136
140
 
137
141
  save () {
138
142
 
139
- return !this.filePath ? Promise.resolve() : mkdirpProm(dirname(this.filePath)).then(() => {
143
+ return !this.filePath ? Promise.resolve() : mkdirp(dirname(this.filePath)).then(() => {
140
144
 
141
145
  const objects = {};
142
146
  this.forEach((value, key) => {
143
147
  objects[key] = value;
144
148
  });
145
149
 
146
- return this.spaces ?
147
- writeJSONFileProm(this.filePath, objects, {
148
- "encoding": "utf8",
149
- "space": 2
150
- }) :
151
- writeJSONFileProm(this.filePath, objects, {
152
- "encoding": "utf8"
153
- });
150
+ return this.spaces ? writeJson(this.filePath, objects, {
151
+ "encoding": "utf8",
152
+ "space": 2
153
+ }) : writeJson(this.filePath, objects, {
154
+ "encoding": "utf8"
155
+ });
154
156
 
155
157
  });
156
158
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-confmanager",
3
- "version": "1.4.4",
3
+ "version": "1.4.7",
4
4
  "description": "A configuration manager",
5
5
  "main": "lib/main.js",
6
6
  "typings": "lib/index.d.ts",
@@ -45,14 +45,14 @@
45
45
  "url": "https://github.com/Psychopoulet/node-confmanager/issues"
46
46
  },
47
47
  "dependencies": {
48
- "node-containerpattern": "1.4.2",
49
- "node-promfs": "3.7.0"
48
+ "node-containerpattern": "1.4.5",
49
+ "fs-extra": "10.1.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@types/node": "17.0.34",
52
+ "@types/node": "17.0.35",
53
53
  "check-version-modules": "1.3.5",
54
54
  "coveralls": "3.1.1",
55
- "eslint": "8.15.0",
55
+ "eslint": "8.16.0",
56
56
  "husky": "8.0.1",
57
57
  "mocha": "10.0.0",
58
58
  "nyc": "15.1.0",