29 lines
786 B
TypeScript
29 lines
786 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");
|
|
} |