From 7c631f3af55415efaf564fd6e47c99250b0e44df Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 6 Dec 2022 16:38:58 -0500 Subject: [PATCH] *Force create of config directory if it does not exist --- src/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.ts b/src/index.ts index 2911279..92976a4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,6 +80,7 @@ export default class Config { } } } + public inject(options: object) { for (const key of Object.keys(options)) { const value = options[key]; @@ -174,6 +175,10 @@ export default class Config { const fullPath = Path.join(this.str("configdir"), file); + if (!fs.existsSync(fullPath)) { + fs.mkdirSync(fullPath, { recursive: true }); + } + fs.writeFileSync(fullPath, JSON.stringify(data)); this.openJson(fullPath); } @@ -317,6 +322,7 @@ export default class Config { return value; } + int(key, fallback = null) { const value = this.get(key); @@ -398,6 +404,7 @@ export default class Config { return num; } + ufloat(key, fallback = null) { const value = this.float(key); if (value === null) { @@ -424,6 +431,7 @@ export default class Config { throw new Error(`${fmt(key)} must be a fixed number.`); } } + ufixed(key, exp, fallback = null) { const value = this.fixed(key, exp); @@ -473,6 +481,7 @@ export default class Config { throw new Error(`${fmt(key)} must be a boolean.`); } + buf(key: string, fallback = null, enc: BufferEncoding = "hex") { const value = this.get(key); @@ -875,6 +884,7 @@ export default class Config { return this.parseForm(query, "?", this.query); } + public parseHash(hash: string) { if (typeof hash !== "string") { if (!global.location) {