Files
77th_eventcalenderntfy/src/util.ts

41 lines
1022 B
TypeScript

export const createPlaceholders = ( arr: any[] ) => {
return arr.map(() => '?').join(', ');
}
export type AddDollarPrefix<T> = {
[K in keyof T as `$${string & K}`]: T[K];
};
export function prefixKeysWithDollar<T extends Record<string, any>>(obj: T): AddDollarPrefix<T> {
const result = {} as AddDollarPrefix<T>;
for (const key in obj) {
const newKey = `$${key}` as keyof AddDollarPrefix<T>;
result[newKey] = obj[key] as any;
}
return result;
}
export function transformArray<T extends Record<string, any>>(arr: T[]): AddDollarPrefix<T>[] {
return arr.map(prefixKeysWithDollar);
}
export function pad_l2 ( _thing: string | number ): string {
if ( typeof _thing == "number" ) {
_thing = JSON.stringify(_thing);
};
return _thing.padStart(2, "0");
}
export function getTsNow() {
const now = new Date();
const rtn = {
year: now.getFullYear(),
month: now.getMonth() + 1,
day: now.getDate(),
minute: now.getMinutes(),
seconds: now.getSeconds()
}
return rtn;
}