This commit is contained in:
pakintada@gmail.com 2026-02-17 14:30:02 +07:00
commit 451223816b
338 changed files with 9938 additions and 0 deletions

View file

@ -0,0 +1,14 @@
export class AsyncStorage {
static async getItem<T>(key: string) {
return new Promise<T>((resolve) => {
resolve(localStorage.getItem(key) as T)
});
}
static async setItem(key: string, value: string){
return new Promise<void>((resolve) => {
localStorage.setItem(key, value);
resolve();
});
}
}

41
src/lib/helpers/cookie.ts Normal file
View file

@ -0,0 +1,41 @@
function extractCookieOnNonBrowser() {
let result: any = {};
let cookie_ent = document.cookie.split(';');
for (let i = 0; i < cookie_ent.length; i++) {
let c = cookie_ent[i].trim();
if (c.indexOf('=') > -1) {
let key = c.split('=')[0];
result[key] = c.split('=')[1];
}
}
return result;
}
function setCookieOnNonBrowser(name: string, value: string) {
let current = extractCookieOnNonBrowser();
let result = '';
for (let key of Object.keys(current)) {
if (key == name) continue;
result += `${key}=${current[key]}; `;
}
result += `${name}=${value};`;
document.cookie = result;
console.log('last set cookie', result);
}
function deleteCookiesOnNonBrowser(name: string) {
let current = extractCookieOnNonBrowser();
let result = '';
if (current[name]) {
for (let key of Object.keys(current)) {
if (key == name) continue;
result += `${key}=${current[key]}; `;
}
}
document.cookie = result;
}
export { extractCookieOnNonBrowser, setCookieOnNonBrowser, deleteCookiesOnNonBrowser };

View file

@ -0,0 +1,49 @@
class IcingGen {
private lastTimestamp = 0n;
private sequence = 0n;
private machineId: bigint;
constructor(machineId: number) {
this.machineId = BigInt(machineId) & 0b11111n;
}
private timestamp() {
return BigInt(new Date().getTime());
}
nextId() {
let now = this.timestamp();
if (now === this.lastTimestamp) {
this.sequence = (this.sequence + 1n) & 0b111111111111n;
if (this.sequence === 0n) now++;
} else {
this.sequence = 0n;
}
this.lastTimestamp = now;
const id = ((now - 1700000000000n) << 17n) | (this.machineId << 12n) | this.sequence;
return id.toString();
}
}
function toBase62(num: bigint): string {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let str = '';
while (num > 0n) {
const rem = num % 62n;
str = chars[Number(rem)] + str;
num = num / 62n;
}
return str;
}
export function generateIcing(machineId: number): string {
const icing = new IcingGen(machineId);
const nid = icing.nextId();
console.log('NEXT ID', nid);
const id = toBase62(BigInt(nid));
return id;
}

View file

@ -0,0 +1,3 @@
export function getProperty<Type, Key extends keyof Type>(obj: Type, key: Key) {
return obj[key];
}

20
src/lib/helpers/lang.ts Normal file
View file

@ -0,0 +1,20 @@
import { AsyncStorage } from "./asyncStorage";
export default class Lang {
static async initLanguageSwitcher(){
let currentLanguage = await Lang.getCurrentLanguage();
if(currentLanguage == null || currentLanguage == undefined){
await AsyncStorage.setItem('currentLanguage', 'th');
}
}
static getCurrentLanguage(){
return AsyncStorage.getItem('currentLanguage');
}
static async switchLanguage(){
let currentLanguage = await Lang.getCurrentLanguage();
let resultLang = currentLanguage == 'th' ? 'en' : 'th';
await AsyncStorage.setItem('currentLanguage', resultLang);
}
}

View file

@ -0,0 +1 @@
export function update