init
This commit is contained in:
parent
2c697b0de9
commit
d43f5e71db
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"deno.enable": true
|
||||||
|
}
|
10
deno.json
Normal file
10
deno.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "@bearmetal/store",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "A simple store for storing data in a JSON file.",
|
||||||
|
"files": [
|
||||||
|
"mod.ts",
|
||||||
|
"store.ts"
|
||||||
|
],
|
||||||
|
"exports": "./mod.ts"
|
||||||
|
}
|
32
store.ts
Normal file
32
store.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
export class BearMetalStore {
|
||||||
|
private store: Record<string, string | number | boolean> = {};
|
||||||
|
private storePath: string;
|
||||||
|
|
||||||
|
constructor(storePath?: string) {
|
||||||
|
this.storePath = storePath || Deno.env.get("BEAR_METAL_STORE_PATH") ||
|
||||||
|
"./BearMetal/store.json";
|
||||||
|
this.readIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public get(key: string): string | number | boolean {
|
||||||
|
return this.store[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
public set(key: string, value: string | number | boolean): void {
|
||||||
|
this.store[key] = value;
|
||||||
|
this.writeOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
public delete(key: string): void {
|
||||||
|
delete this.store[key];
|
||||||
|
this.writeOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
private readIn() {
|
||||||
|
this.store = JSON.parse(Deno.readTextFileSync(this.storePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
private writeOut() {
|
||||||
|
Deno.writeTextFileSync(this.storePath, JSON.stringify(this.store));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user