namirasoft-core
Advanced tools
Comparing version 1.3.74 to 1.3.75
@@ -11,3 +11,3 @@ import { IStorage } from "./IStorage"; | ||
private set; | ||
del(): Promise<void>; | ||
del(): void; | ||
} |
@@ -24,3 +24,3 @@ "use strict"; | ||
let ans; | ||
let value = yield this.storage.get(this.name, ""); | ||
let value = this.storage.get(this.name, ""); | ||
if (value) { | ||
@@ -32,3 +32,3 @@ let cache = JSON.parse(value); | ||
ans = yield this.getFromSource(); | ||
yield this.set(ans); | ||
this.set(ans); | ||
return ans; | ||
@@ -38,20 +38,16 @@ }); | ||
set(data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let expires_at = new Date(); | ||
expires_at.setMinutes(expires_at.getMinutes() + this.duration_minutes); | ||
let value = JSON.stringify({ data, expires_at }); | ||
yield this.storage.set(this.name, value); | ||
let sleep = expires_at.getTime() - new Date().getTime(); | ||
if (sleep <= 0) | ||
sleep = 5 * 1000; | ||
setTimeout(() => { | ||
if (this.onExpired) | ||
this.onExpired(); | ||
}, sleep); | ||
}); | ||
let expires_at = new Date(); | ||
expires_at.setMinutes(expires_at.getMinutes() + this.duration_minutes); | ||
let value = JSON.stringify({ data, expires_at }); | ||
this.storage.set(this.name, value); | ||
let sleep = expires_at.getTime() - new Date().getTime(); | ||
if (sleep <= 0) | ||
sleep = 5 * 1000; | ||
setTimeout(() => { | ||
if (this.onExpired) | ||
this.onExpired(); | ||
}, sleep); | ||
} | ||
del() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.storage.del(this.name); | ||
}); | ||
this.storage.del(this.name); | ||
} | ||
@@ -58,0 +54,0 @@ } |
export declare abstract class IStorage { | ||
abstract get(name: string, defaultValue: string): Promise<string>; | ||
abstract set(name: string, value: string): Promise<void>; | ||
abstract del(name: string): Promise<void>; | ||
abstract get(name: string, defaultValue: string): string; | ||
abstract set(name: string, value: string): void; | ||
abstract del(name: string): void; | ||
} |
@@ -9,5 +9,5 @@ import { IStorage } from "./IStorage"; | ||
private getAll; | ||
get(name: string, defaultValue: string): Promise<string>; | ||
set(name: string, value: string): Promise<void>; | ||
del(name: string): Promise<void>; | ||
get(name: string, defaultValue: string): string; | ||
set(name: string, value: string): void; | ||
del(name: string): void; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -33,29 +24,23 @@ exports.IStorageCookie = void 0; | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
let all = this.getAll(); | ||
return (_a = EncodingOperation_1.EncodingOperation.Base64Decode(all[name])) !== null && _a !== void 0 ? _a : defaultValue; | ||
} | ||
catch (error) { | ||
return defaultValue; | ||
} | ||
}); | ||
try { | ||
let all = this.getAll(); | ||
return (_a = EncodingOperation_1.EncodingOperation.Base64Decode(all[name])) !== null && _a !== void 0 ? _a : defaultValue; | ||
} | ||
catch (error) { | ||
return defaultValue; | ||
} | ||
} | ||
set(name, value) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
let items = []; | ||
for (let key of Object.keys(this.fixed)) | ||
items.push(`${key}=${this.fixed[key]}`); | ||
items.push(`${name}=${EncodingOperation_1.EncodingOperation.Base64Encode(value)}`); | ||
document.cookie = items.join(";"); | ||
} | ||
catch (error) { | ||
} | ||
}); | ||
try { | ||
let items = []; | ||
for (let key of Object.keys(this.fixed)) | ||
items.push(`${key}=${this.fixed[key]}`); | ||
items.push(`${name}=${EncodingOperation_1.EncodingOperation.Base64Encode(value)}`); | ||
document.cookie = items.join(";"); | ||
} | ||
catch (error) { | ||
} | ||
} | ||
del(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.set(name, ""); | ||
}); | ||
this.set(name, ""); | ||
} | ||
@@ -62,0 +47,0 @@ } |
import { IStorage } from "./IStorage.js"; | ||
export declare class IStorageLocal extends IStorage { | ||
get(name: string, defaultValue: string): Promise<string>; | ||
set(name: string, value: string): Promise<void>; | ||
del(name: string): Promise<void>; | ||
get(name: string, defaultValue: string): string; | ||
set(name: string, value: string): void; | ||
del(name: string): void; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,15 +8,9 @@ exports.IStorageLocal = void 0; | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (_a = localStorage.getItem(name)) !== null && _a !== void 0 ? _a : defaultValue; | ||
}); | ||
return (_a = localStorage.getItem(name)) !== null && _a !== void 0 ? _a : defaultValue; | ||
} | ||
set(name, value) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
localStorage.setItem(name, value); | ||
}); | ||
localStorage.setItem(name, value); | ||
} | ||
del(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
localStorage.removeItem(name); | ||
}); | ||
localStorage.removeItem(name); | ||
} | ||
@@ -32,0 +17,0 @@ } |
@@ -6,5 +6,5 @@ import { IStorage } from "./IStorage"; | ||
}; | ||
get(name: string, defaultValue: string): Promise<string>; | ||
set(name: string, value: string): Promise<void>; | ||
del(name: string): Promise<void>; | ||
get(name: string, defaultValue: string): string; | ||
set(name: string, value: string): void; | ||
del(name: string): void; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,15 +8,9 @@ exports.IStorageMemory = void 0; | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (_a = IStorageMemory.data[name]) !== null && _a !== void 0 ? _a : defaultValue; | ||
}); | ||
return (_a = IStorageMemory.data[name]) !== null && _a !== void 0 ? _a : defaultValue; | ||
} | ||
set(name, value) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
IStorageMemory.data[name] = value; | ||
}); | ||
IStorageMemory.data[name] = value; | ||
} | ||
del(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
delete IStorageMemory.data[name]; | ||
}); | ||
delete IStorageMemory.data[name]; | ||
} | ||
@@ -32,0 +17,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
"private": false, | ||
"version": "1.3.74", | ||
"version": "1.3.75", | ||
"author": "Amir Abolhasani", | ||
@@ -14,0 +14,0 @@ "license": "MIT", |
@@ -27,3 +27,3 @@ import { IStorage } from "./IStorage"; | ||
let ans: DataType; | ||
let value = await this.storage.get(this.name, ""); | ||
let value = this.storage.get(this.name, ""); | ||
if (value) | ||
@@ -36,6 +36,6 @@ { | ||
ans = await this.getFromSource(); | ||
await this.set(ans); | ||
this.set(ans); | ||
return ans; | ||
} | ||
private async set(data: DataType) | ||
private set(data: DataType) | ||
{ | ||
@@ -45,3 +45,3 @@ let expires_at = new Date(); | ||
let value = JSON.stringify({ data, expires_at }); | ||
await this.storage.set(this.name, value); | ||
this.storage.set(this.name, value); | ||
// | ||
@@ -58,6 +58,6 @@ | ||
} | ||
async del() | ||
del() | ||
{ | ||
await this.storage.del(this.name); | ||
this.storage.del(this.name); | ||
} | ||
} |
export abstract class IStorage | ||
{ | ||
abstract get(name: string, defaultValue: string): Promise<string>; | ||
abstract set(name: string, value: string): Promise<void>; | ||
abstract del(name: string): Promise<void>; | ||
abstract get(name: string, defaultValue: string): string; | ||
abstract set(name: string, value: string): void; | ||
abstract del(name: string): void; | ||
} |
@@ -25,3 +25,3 @@ import { EncodingOperation } from "./EncodingOperation"; | ||
} | ||
override async get(name: string, defaultValue: string) | ||
override get(name: string, defaultValue: string) | ||
{ | ||
@@ -37,3 +37,3 @@ try | ||
} | ||
override async set(name: string, value: string) | ||
override set(name: string, value: string) | ||
{ | ||
@@ -51,3 +51,3 @@ try | ||
} | ||
override async del(name: string) | ||
override del(name: string) | ||
{ | ||
@@ -54,0 +54,0 @@ this.set(name, ""); |
@@ -5,11 +5,11 @@ import { IStorage } from "./IStorage.js"; | ||
{ | ||
override async get(name: string, defaultValue: string) | ||
override get(name: string, defaultValue: string) | ||
{ | ||
return localStorage.getItem(name) ?? defaultValue; | ||
} | ||
override async set(name: string, value: string) | ||
override set(name: string, value: string) | ||
{ | ||
localStorage.setItem(name, value); | ||
} | ||
override async del(name: string) | ||
override del(name: string) | ||
{ | ||
@@ -16,0 +16,0 @@ localStorage.removeItem(name); |
@@ -6,11 +6,11 @@ import { IStorage } from "./IStorage"; | ||
static data: { [name: string]: string } = {}; | ||
override async get(name: string, defaultValue: string) | ||
override get(name: string, defaultValue: string) | ||
{ | ||
return IStorageMemory.data[name] ?? defaultValue; | ||
} | ||
override async set(name: string, value: string) | ||
override set(name: string, value: string) | ||
{ | ||
IStorageMemory.data[name] = value; | ||
} | ||
override async del(name: string) | ||
override del(name: string) | ||
{ | ||
@@ -17,0 +17,0 @@ delete IStorageMemory.data[name]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
380922
4804