*Update dist
This commit is contained in:
parent
7c631f3af5
commit
647dc9a2ec
|
@ -5,80 +5,69 @@
|
||||||
*/
|
*/
|
||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
export interface Options {
|
export interface Options {
|
||||||
suffix?: string;
|
suffix?: string;
|
||||||
fallback?: string;
|
fallback?: string;
|
||||||
alias?: object;
|
alias?: object;
|
||||||
}
|
}
|
||||||
export interface LoadOptions {
|
export interface LoadOptions {
|
||||||
hash?: string | boolean;
|
hash?: string | boolean;
|
||||||
query?: string | boolean;
|
query?: string | boolean;
|
||||||
env?: object | boolean;
|
env?: object | boolean;
|
||||||
argv?: string[] | boolean;
|
argv?: string[] | boolean;
|
||||||
config?: string | boolean;
|
config?: string | boolean;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Config Parser
|
* Config Parser
|
||||||
*/
|
*/
|
||||||
export default class Config {
|
export default class Config {
|
||||||
private module;
|
private module;
|
||||||
private prefix;
|
private prefix;
|
||||||
private suffix?;
|
private suffix?;
|
||||||
private fallback?;
|
private fallback?;
|
||||||
private options;
|
private options;
|
||||||
private alias;
|
private alias;
|
||||||
private data;
|
private data;
|
||||||
private env;
|
private env;
|
||||||
private args;
|
private args;
|
||||||
private argv;
|
private argv;
|
||||||
private pass;
|
private pass;
|
||||||
private query;
|
private query;
|
||||||
private hash;
|
private hash;
|
||||||
constructor(module: string, options?: Options);
|
constructor(module: string, options?: Options);
|
||||||
private init;
|
private init;
|
||||||
inject(options: object): void;
|
inject(options: object): void;
|
||||||
load(options: LoadOptions): void;
|
load(options: LoadOptions): void;
|
||||||
open(file: string): void;
|
open(file: string): void;
|
||||||
openDir(dir: string): void;
|
openDir(dir: string): void;
|
||||||
openJson(file: string): void;
|
openJson(file: string): void;
|
||||||
saveConfigJson(file: string, data: object): void;
|
saveConfigJson(file: string, data: object): void;
|
||||||
filter(name: string): Config;
|
filter(name: string): 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
|
str(key: string, fallback?: any): any;
|
||||||
):
|
int(key: any, fallback?: any): any;
|
||||||
| "string"
|
uint(key: any, fallback?: any): any;
|
||||||
| "number"
|
float(key: any, fallback?: any): any;
|
||||||
| "bigint"
|
ufloat(key: any, fallback?: any): any;
|
||||||
| "boolean"
|
fixed(key: any, exp: any, fallback?: any): any;
|
||||||
| "symbol"
|
ufixed(key: any, exp: any, fallback?: any): any;
|
||||||
| "undefined"
|
bool(key: any, fallback?: any): any;
|
||||||
| "object"
|
buf(key: string, fallback?: any, enc?: BufferEncoding): any;
|
||||||
| "function"
|
array(key: string, fallback?: any): any;
|
||||||
| "null";
|
obj(key: string, fallback?: any): any;
|
||||||
str(key: string, fallback?: any): any;
|
func(key: string, fallback?: any): any;
|
||||||
int(key: any, fallback?: any): any;
|
path(key: string, fallback?: any): any;
|
||||||
uint(key: any, fallback?: any): any;
|
mb(key: string, fallback?: any): any;
|
||||||
float(key: any, fallback?: any): any;
|
getSuffix(): any;
|
||||||
ufloat(key: any, fallback?: any): any;
|
getPrefix(): string;
|
||||||
fixed(key: any, exp: any, fallback?: any): any;
|
getFile(file: string): any;
|
||||||
ufixed(key: any, exp: any, fallback?: any): any;
|
location(file: string): string;
|
||||||
bool(key: any, fallback?: any): any;
|
parseConfig(text: string): void;
|
||||||
buf(key: string, fallback?: any, enc?: BufferEncoding): any;
|
parseArg(argv?: string[]): void;
|
||||||
array(key: string, fallback?: any): any;
|
parseEnv(env?: object): void;
|
||||||
obj(key: string, fallback?: any): any;
|
parseQuery(query: string): void | {};
|
||||||
func(key: string, fallback?: any): any;
|
parseHash(hash: string): void | {};
|
||||||
path(key: string, fallback?: any): any;
|
parseForm(query: string, ch: string, map: object): void;
|
||||||
mb(key: string, fallback?: any): any;
|
|
||||||
getSuffix(): any;
|
|
||||||
getPrefix(): string;
|
|
||||||
getFile(file: string): any;
|
|
||||||
location(file: string): string;
|
|
||||||
parseConfig(text: string): void;
|
|
||||||
parseArg(argv?: string[]): void;
|
|
||||||
parseEnv(env?: object): void;
|
|
||||||
parseQuery(query: string): void | {};
|
|
||||||
parseHash(hash: string): void | {};
|
|
||||||
parseForm(query: string, ch: string, map: object): void;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue