Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Hammer 647dc9a2ec
*Update dist 2022-12-06 16:39:23 -05:00
Derrick Hammer 7c631f3af5
*Force create of config directory if it does not exist 2022-12-06 16:38:58 -05:00
3 changed files with 71 additions and 69 deletions

13
dist/index.d.ts vendored
View File

@ -45,18 +45,7 @@ export default class Config {
set(key: string, value: any): void; set(key: string, value: any): void;
has(key: string): boolean; has(key: string): boolean;
get(key: string, fallback?: any): any; get(key: string, fallback?: any): any;
typeOf( typeOf(key: string): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "null";
key: string
):
| "string"
| "number"
| "bigint"
| "boolean"
| "symbol"
| "undefined"
| "object"
| "function"
| "null";
str(key: string, fallback?: any): any; str(key: string, fallback?: any): any;
int(key: any, fallback?: any): any; int(key: any, fallback?: any): any;
uint(key: any, fallback?: any): any; uint(key: any, fallback?: any): any;

3
dist/index.js vendored
View File

@ -135,6 +135,9 @@ class Config {
(0, bsert_1.default)(typeof data === "object"); (0, bsert_1.default)(typeof data === "object");
(0, bsert_1.default)(!Array.isArray(data)); (0, bsert_1.default)(!Array.isArray(data));
const fullPath = path_1.default.join(this.str("configdir"), file); const fullPath = path_1.default.join(this.str("configdir"), file);
if (!fs_1.default.existsSync(fullPath)) {
fs_1.default.mkdirSync(fullPath, { recursive: true });
}
fs_1.default.writeFileSync(fullPath, JSON.stringify(data)); fs_1.default.writeFileSync(fullPath, JSON.stringify(data));
this.openJson(fullPath); this.openJson(fullPath);
} }

View File

@ -80,6 +80,7 @@ export default class Config {
} }
} }
} }
public inject(options: object) { public inject(options: object) {
for (const key of Object.keys(options)) { for (const key of Object.keys(options)) {
const value = options[key]; const value = options[key];
@ -174,6 +175,10 @@ export default class Config {
const fullPath = Path.join(this.str("configdir"), file); const fullPath = Path.join(this.str("configdir"), file);
if (!fs.existsSync(fullPath)) {
fs.mkdirSync(fullPath, { recursive: true });
}
fs.writeFileSync(fullPath, JSON.stringify(data)); fs.writeFileSync(fullPath, JSON.stringify(data));
this.openJson(fullPath); this.openJson(fullPath);
} }
@ -317,6 +322,7 @@ export default class Config {
return value; return value;
} }
int(key, fallback = null) { int(key, fallback = null) {
const value = this.get(key); const value = this.get(key);
@ -398,6 +404,7 @@ export default class Config {
return num; return num;
} }
ufloat(key, fallback = null) { ufloat(key, fallback = null) {
const value = this.float(key); const value = this.float(key);
if (value === null) { if (value === null) {
@ -424,6 +431,7 @@ export default class Config {
throw new Error(`${fmt(key)} must be a fixed number.`); throw new Error(`${fmt(key)} must be a fixed number.`);
} }
} }
ufixed(key, exp, fallback = null) { ufixed(key, exp, fallback = null) {
const value = this.fixed(key, exp); const value = this.fixed(key, exp);
@ -473,6 +481,7 @@ export default class Config {
throw new Error(`${fmt(key)} must be a boolean.`); throw new Error(`${fmt(key)} must be a boolean.`);
} }
buf(key: string, fallback = null, enc: BufferEncoding = "hex") { buf(key: string, fallback = null, enc: BufferEncoding = "hex") {
const value = this.get(key); const value = this.get(key);
@ -875,6 +884,7 @@ export default class Config {
return this.parseForm(query, "?", this.query); return this.parseForm(query, "?", this.query);
} }
public parseHash(hash: string) { public parseHash(hash: string) {
if (typeof hash !== "string") { if (typeof hash !== "string") {
if (!global.location) { if (!global.location) {