namirasoft-core
Advanced tools
Comparing version 1.4.4 to 1.4.5
import { IStorage } from "./IStorage"; | ||
export declare class IStorageJsonFile extends IStorage { | ||
private data; | ||
private base_path; | ||
@@ -8,2 +9,4 @@ constructor(base_path: string); | ||
}; | ||
private load; | ||
private save; | ||
get(name: string, defaultValue: string): any; | ||
@@ -10,0 +13,0 @@ set(name: string, value: string): void; |
@@ -14,19 +14,28 @@ "use strict"; | ||
} | ||
load() { | ||
try { | ||
let content = fs_1.default.readFileSync(this.base_path, { encoding: "utf8" }); | ||
this.data = JSON.parse(content); | ||
} | ||
catch (error) { | ||
this.data = {}; | ||
} | ||
} | ||
save() { | ||
fs_1.default.writeFileSync(this.base_path, JSON.stringify(this.data)); | ||
} | ||
get(name, defaultValue) { | ||
var _a; | ||
let content = fs_1.default.readFileSync(this.base_path, { encoding: "utf8" }); | ||
let data = JSON.parse(content); | ||
return (_a = data[name]) !== null && _a !== void 0 ? _a : defaultValue; | ||
this.load(); | ||
return (_a = this.data[name]) !== null && _a !== void 0 ? _a : defaultValue; | ||
} | ||
set(name, value) { | ||
let content = fs_1.default.readFileSync(this.base_path, { encoding: "utf8" }); | ||
let data = JSON.parse(content); | ||
data[name] = value; | ||
fs_1.default.writeFileSync(this.base_path, JSON.stringify(data)); | ||
this.load(); | ||
this.data[name] = value; | ||
this.save(); | ||
} | ||
del(name) { | ||
let content = fs_1.default.readFileSync(this.base_path, { encoding: "utf8" }); | ||
let data = JSON.parse(content); | ||
delete data[name]; | ||
fs_1.default.writeFileSync(this.base_path, JSON.stringify(data)); | ||
this.load(); | ||
delete this.data[name]; | ||
this.save(); | ||
} | ||
@@ -33,0 +42,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
"private": false, | ||
"version": "1.4.4", | ||
"version": "1.4.5", | ||
"author": "Amir Abolhasani", | ||
@@ -14,0 +14,0 @@ "license": "MIT", |
@@ -0,0 +0,0 @@ export type BaseDatabaseRow<ID> = |
@@ -0,0 +0,0 @@ export class BaseMetaColumn |
@@ -0,0 +0,0 @@ import { BaseMetaColumn } from "./BaseMetaColumn"; |
@@ -0,0 +0,0 @@ import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; |
@@ -0,0 +0,0 @@ import { IStorage } from "./IStorage"; |
@@ -0,0 +0,0 @@ export class ConsoleOperation |
@@ -0,0 +0,0 @@ import { ErrorOperation } from "./ErrorOperation"; |
@@ -0,0 +0,0 @@ import { Country } from "./Country"; |
@@ -0,0 +0,0 @@ export class Country |
@@ -0,0 +0,0 @@ import { Country } from "./Country"; |
@@ -0,0 +0,0 @@ import { Buffer } from 'buffer'; |
@@ -0,0 +0,0 @@ import * as crypto from 'node:crypto'; |
@@ -0,0 +0,0 @@ import { ConvertService } from "./ConvertService"; |
@@ -0,0 +0,0 @@ import { HTTPError } from "./HTTPError"; |
@@ -0,0 +0,0 @@ let fs: any; |
@@ -0,0 +0,0 @@ import { BaseMetaColumn } from "./BaseMetaColumn"; |
@@ -0,0 +0,0 @@ export enum FilterItemColumnType |
@@ -0,0 +0,0 @@ import { ErrorOperation } from "./ErrorOperation"; |
@@ -0,0 +0,0 @@ export class GeoOperation |
@@ -0,0 +0,0 @@ import * as crypto from 'node:crypto'; |
@@ -0,0 +0,0 @@ export class HTTPError extends Error |
@@ -0,0 +0,0 @@ export enum HTTPMethod |
@@ -0,0 +0,0 @@ export * from "./BaseDatabaseRow"; |
@@ -0,0 +0,0 @@ export abstract class IStorage |
@@ -0,0 +0,0 @@ import { EncodingOperation } from "./EncodingOperation"; |
@@ -6,2 +6,3 @@ import fs from "fs"; | ||
{ | ||
private data: any; | ||
private base_path: string; | ||
@@ -14,22 +15,34 @@ constructor(base_path: string) | ||
static data: { [name: string]: string } = {}; | ||
private load(): void | ||
{ | ||
try | ||
{ | ||
let content = fs.readFileSync(this.base_path, { encoding: "utf8" }); | ||
this.data = JSON.parse(content); | ||
} catch (error) | ||
{ | ||
this.data = {}; | ||
} | ||
} | ||
private save(): void | ||
{ | ||
fs.writeFileSync(this.base_path, JSON.stringify(this.data)); | ||
} | ||
override get(name: string, defaultValue: string) | ||
{ | ||
let content = fs.readFileSync(this.base_path, { encoding: "utf8" }); | ||
let data = JSON.parse(content); | ||
return data[name] ?? defaultValue; | ||
this.load(); | ||
return this.data[name] ?? defaultValue; | ||
} | ||
override set(name: string, value: string) | ||
{ | ||
let content = fs.readFileSync(this.base_path, { encoding: "utf8" }); | ||
let data = JSON.parse(content); | ||
data[name] = value; | ||
fs.writeFileSync(this.base_path, JSON.stringify(data)); | ||
this.load(); | ||
this.data[name] = value; | ||
this.save(); | ||
} | ||
override del(name: string) | ||
{ | ||
let content = fs.readFileSync(this.base_path, { encoding: "utf8" }); | ||
let data = JSON.parse(content); | ||
delete data[name]; | ||
fs.writeFileSync(this.base_path, JSON.stringify(data)); | ||
this.load(); | ||
delete this.data[name]; | ||
this.save(); | ||
} | ||
} |
@@ -0,0 +0,0 @@ import { IStorage } from "./IStorage.js"; |
@@ -0,0 +0,0 @@ import { IStorage } from "./IStorage"; |
@@ -0,0 +0,0 @@ export class NamingConvention |
@@ -0,0 +0,0 @@ import { ConvertService } from "./ConvertService"; |
@@ -0,0 +0,0 @@ let fs: any; |
@@ -0,0 +0,0 @@ import * as Phone from 'phone'; |
@@ -0,0 +0,0 @@ export class PriceOperation |
@@ -0,0 +0,0 @@ export class RegexTemplate |
@@ -0,0 +0,0 @@ export class SearchOperation |
@@ -0,0 +0,0 @@ export class StringOperation |
@@ -0,0 +0,0 @@ import moment from "moment"; |
@@ -0,0 +0,0 @@ import { ParsedNameValue } from "./ParsedNameValue"; |
@@ -0,0 +0,0 @@ export class VersionOperation |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
394612
5057