soon-utils
v0.0.9
Published
a collection of functions usually used
Readme
soon-utils
A collection of functions usually used
Download
// start a browser download task
export declare function downloadUrl(path: string, filename?: string): void;
// start a browser download task
export declare function downloadBlob(blob: Blob, filename?: string): void;
// extract filename from headers which have header key "content-disposition"
export declare function getHeaderFilename(
headers?: Headers
): string | undefined;Object
obj2keyObj
//example
const data = obj2keyObj({ name: "world", goods: { price: 1, amount: 10 } });
console.log(data);
// {name:'name',goods:'goods'}obj2keyPathObj
const data = obj2keyPathObj({ name: "world", goods: { price: 1, amount: 10 } });
console.log(data);
// {name:'name',goods:{price:'goods.price',amount:'goods.amount'}}JSON
//parse json or js object to JSON
export declare function parseJSON<T>(json: string): T | undefined;
//json convert to ts type
export declare function json2type(json: object | any[], name: string | undefined, config?: {
useInterface?: boolean;
useArray?: boolean;
addExport?: boolean;
addDeclare?: boolean;
extract?: number;
optional?: boolean;
nullable?: boolean;
}): {
name: string;
code: string;
}[];
Style
// add or replace style tag
export declare function replaceStyleTag(id: string, cssText: string): void;
types
// {a?:string} convert to {a:undefined|string}
export type RequiredUndefined<T> = Simplify<{
[Key in keyof Required<T>]: undefined | T[Key]
}>