node-confmanager
Advanced tools
Comparing version 1.4.7 to 1.5.0
@@ -9,5 +9,5 @@ /// <reference types="node" /> | ||
public filePath: string; | ||
public spaces: boolean; | ||
public shortcuts: Array<string>; | ||
public filePath: string; // conf file | ||
public spaces: boolean; // formate file | ||
public shortcuts: Array<string>; // for container | ||
@@ -18,10 +18,10 @@ constructor(filePath?: string, spaces?: boolean, recursionSeparator?: string); | ||
public shortcut(key: string, shortkey: string): this; | ||
public clearShortcuts(): this; | ||
public clear(): this; | ||
public deleteFile(): Promise<void>; | ||
public get(key: string): any; | ||
public fileExists(): Promise<boolean>; | ||
public load(): Promise<void>; | ||
public save(): Promise<void>; | ||
// public clear(): void; // Container.clear & clearShortcuts | ||
public clearShortcuts(): this; // forget all the shortcuts | ||
public deleteFile(): Promise<void>; // delete the conf file | ||
public fileExists(): Promise<boolean>; // check if the conf file exists | ||
// public get(key: string): any; // Container.get with cloned data | ||
public load(): Promise<void>; // load data from conf file then commandline (commandline takeover) | ||
public save(): Promise<void>; // save data into conf file | ||
public shortcut(key: string, shortkey: string): this; // bind a shortcut for commandline | ||
@@ -28,0 +28,0 @@ } |
@@ -89,12 +89,11 @@ "use strict"; | ||
shortcut (_key, _shortkey) { | ||
// public | ||
const { key, shortkey } = checkShortcut(_key, _shortkey); | ||
this.shortcuts[shortkey] = key; | ||
return this; | ||
// Container.clear & clearShortcuts | ||
clear () { | ||
super.clear(); | ||
this.clearShortcuts(); | ||
} | ||
// forget all the shortcuts | ||
clearShortcuts () { | ||
@@ -105,7 +104,3 @@ this.shortcuts = []; | ||
clear () { | ||
super.clear(); | ||
return this.clearShortcuts(); | ||
} | ||
// delete the conf file | ||
deleteFile () { | ||
@@ -119,2 +114,3 @@ | ||
// check if the conf file exists | ||
fileExists () { | ||
@@ -124,2 +120,8 @@ return !this.filePath ? Promise.resolve(false) : pathExists(this.filePath); | ||
// Container.get with cloned data | ||
get (key) { | ||
return clone(super.get(key)); | ||
} | ||
// load data from conf file then commandline (commandline takeover) | ||
load () { | ||
@@ -145,2 +147,3 @@ | ||
// save data into conf file | ||
save () { | ||
@@ -166,6 +169,13 @@ | ||
get (key) { | ||
return clone(super.get(key)); | ||
// bind a shortcut for commandline | ||
shortcut (_key, _shortkey) { | ||
const { key, shortkey } = checkShortcut(_key, _shortkey); | ||
this.shortcuts[shortkey] = key; | ||
return this; | ||
} | ||
}; |
{ | ||
"name": "node-confmanager", | ||
"version": "1.4.7", | ||
"version": "1.5.0", | ||
"description": "A configuration manager", | ||
@@ -48,3 +48,3 @@ "main": "lib/main.js", | ||
"dependencies": { | ||
"node-containerpattern": "1.4.5", | ||
"node-containerpattern": "1.5.1", | ||
"fs-extra": "10.1.0" | ||
@@ -51,0 +51,0 @@ }, |
@@ -27,97 +27,14 @@ # node-confmanager | ||
see the [node-containerpattern](https://www.npmjs.com/package/node-containerpattern) documentation to see extended methods & attribues | ||
### Inheritance | ||
### node-confmanager | ||
[check the official 'node-containerpattern' object documentation](https://github.com/Psychopoulet/node-containerpattern) | ||
-- Attributes -- | ||
### Content | ||
* ``` filePath: string ``` conf file | ||
* ``` spaces: string ``` formate file | ||
* ``` shortcuts: string ``` for container | ||
[check the TypeScript definition file](https://github.com/Psychopoulet/node-confmanager/blob/master/lib/index.d.ts) | ||
-- Constructor -- | ||
* ``` constructor(confPath?: string, spaces?: boolean, recursionSeparator?: string) ``` | ||
-- Methods -- | ||
* ``` deleteFile() : return Promise instance ``` delete the conf file | ||
* ``` fileExists() : return Promise instance => then((exists) => {}) ``` check if the conf file exists | ||
* ``` clearShortcuts() : return this ``` forget all the shortcuts | ||
* ``` clear() : return this ``` node-containerpattern.clear & clearShortcuts | ||
* ``` load() : return Promise instance ``` load data from conf file then commandline (commandline takeover) | ||
* ``` save() : return Promise instance ``` save data into conf file | ||
* ``` shortcut(string key, string shortkey) : return this ``` bind a shortcut for commandline | ||
## Examples | ||
### Native | ||
[check the TypeScript compilation tests](https://github.com/Psychopoulet/node-confmanager/blob/master/test/typescript/compilation.ts) | ||
```javascript | ||
const ConfManager = require("node-confmanager"); | ||
const conf = new ConfManager(require("path").join(__dirname, "conf.json")); | ||
conf | ||
.skeleton("debug", "boolean") // add skeleton (based on [node-containerpattern](https://www.npmjs.com/package/node-containerpattern)) to check datatype | ||
.shortcut("debug", "d") // add shortcut to simply use comandline params, can add "-d true" to commandline to activate debug | ||
.shortcut("usr.login", "ul") | ||
.shortcut("usr.password", "up"); | ||
conf.fileExists().then((exists) => { | ||
return exists ? Promise.resolve() : Conf.set("usr", { login : "login", pwd : "pwd" }) | ||
.set("debug", false) | ||
.set("prod", "n") // = false | ||
.save(); | ||
}).then(() => { | ||
// can add "--usr.login login2" or "-ul login2" to commandline to force login change | ||
return conf.load(); | ||
}).then(() => { | ||
console.log(conf.get("debug")); | ||
console.log(conf.get("usr.login")); | ||
}).catch((err) => { | ||
console.log(err); | ||
}); | ||
``` | ||
### Typescript | ||
```typescript | ||
import ConfManager = require("node-confmanager"); | ||
import { join } from "path"; | ||
const Conf = new ConfManager(join(__dirname, "conf.json")); | ||
Conf | ||
.skeleton("debug", "boolean").shortcut("debug", "d") | ||
.shortcut("usr.login", "ul") | ||
.shortcut("usr.password", "up"); | ||
Conf.fileExists().then((exists: boolean) => { | ||
return exists ? Promise.resolve() : Conf.set("usr", { login : "login", pwd : "pwd" }) | ||
.set("debug", false) | ||
.set("prod", "n") // = false | ||
.save(); | ||
}).then(() => { | ||
return Conf.load(); | ||
}).then(() => { | ||
console.log(Conf.get("debug")); | ||
console.log(Conf.get("usr.login")); | ||
}).catch((err: Error) => { | ||
console.log(err); | ||
}); | ||
``` | ||
### Run | ||
@@ -124,0 +41,0 @@ |
181
10623
58
+ Addednode-containerpattern@1.5.1(transitive)
- Removednode-containerpattern@1.4.5(transitive)
Updatednode-containerpattern@1.5.1