@noah-libjs/utils 0.0.23 → 0.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/Event.d.ts +27 -0
- package/dist/constant.d.ts +17 -0
- package/dist/dic-helper.d.ts +37 -0
- package/dist/es.js +2693 -0
- package/dist/helper.d.ts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/json-helper.d.ts +3 -0
- package/dist/lib.js +2889 -0
- package/dist/load-src.d.ts +16 -0
- package/dist/log.d.ts +17 -0
- package/dist/moment-help.d.ts +41 -0
- package/dist/option-help.d.ts +22 -0
- package/dist/small-fn.d.ts +45 -0
- package/dist/type-utils.d.ts +10 -0
- package/dist/types.d.ts +17 -0
- package/dist/typing.d.ts +942 -0
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface IOpt {
|
|
2
|
+
id?: string;
|
|
3
|
+
text?: string;
|
|
4
|
+
url?: string;
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
allowExternal?: boolean;
|
|
7
|
+
cache?: boolean;
|
|
8
|
+
async?: boolean;
|
|
9
|
+
type?: 'text/css' | 'text/javascript';
|
|
10
|
+
charset?: string;
|
|
11
|
+
}
|
|
12
|
+
type TMixOpt = IOpt | string;
|
|
13
|
+
export declare function create_load_src(): (items: TMixOpt | TMixOpt[], node?: HTMLHeadElement) => Promise<Element> | Promise<Element[]>;
|
|
14
|
+
export declare function load_src(items: TMixOpt, node?: HTMLHeadElement): Promise<Element>;
|
|
15
|
+
export declare function load_src(items: TMixOpt[], node?: HTMLHeadElement): Promise<Element[]>;
|
|
16
|
+
export {};
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface ILL {
|
|
2
|
+
log?(...optionalParams: any[]): void;
|
|
3
|
+
warn?(...optionalParams: any[]): void;
|
|
4
|
+
error?(...optionalParams: any[]): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class MyLog {
|
|
7
|
+
private _logMsg;
|
|
8
|
+
logBig(t: string): void;
|
|
9
|
+
private env;
|
|
10
|
+
private static _handler;
|
|
11
|
+
static set handler(v: ILL);
|
|
12
|
+
constructor(e: string);
|
|
13
|
+
log(...msg: any[]): void;
|
|
14
|
+
warn(...msg: any[]): void;
|
|
15
|
+
error(...msg: any[]): void;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import dayjs, { ConfigType, OpUnitType, QUnitType } from "dayjs";
|
|
2
|
+
export type Dayjs = dayjs.Dayjs;
|
|
3
|
+
export type DayjsConfigType = dayjs.ConfigType;
|
|
4
|
+
export declare function getMomentObj(s: DayjsConfigType): Dayjs;
|
|
5
|
+
export declare const formatDate: ((s?: any) => string | null) & {
|
|
6
|
+
format: "YYYY-MM-DD";
|
|
7
|
+
};
|
|
8
|
+
export declare const formatDateTime: ((s?: any) => string | null) & {
|
|
9
|
+
format: "YYYY-MM-DD HH:mm:ss";
|
|
10
|
+
};
|
|
11
|
+
export declare const formatDateTimeNoSecond: ((s?: any) => string | null) & {
|
|
12
|
+
format: "YYYY-MM-DD HH:mm";
|
|
13
|
+
};
|
|
14
|
+
export declare const formatTime: ((s?: any) => string | null) & {
|
|
15
|
+
format: "HH:mm:ss";
|
|
16
|
+
};
|
|
17
|
+
export declare function getMomentRange(m?: any): {
|
|
18
|
+
昨天: [dayjs.Dayjs, dayjs.Dayjs];
|
|
19
|
+
今天: [dayjs.Dayjs, dayjs.Dayjs];
|
|
20
|
+
明天: [dayjs.Dayjs, dayjs.Dayjs];
|
|
21
|
+
上周: [dayjs.Dayjs, dayjs.Dayjs];
|
|
22
|
+
近一周: [dayjs.Dayjs, dayjs.Dayjs];
|
|
23
|
+
下周: [dayjs.Dayjs, dayjs.Dayjs];
|
|
24
|
+
上月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
25
|
+
近一月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
26
|
+
下月: [dayjs.Dayjs, dayjs.Dayjs];
|
|
27
|
+
近一年: [dayjs.Dayjs, dayjs.Dayjs];
|
|
28
|
+
年初至今: [dayjs.Dayjs, dayjs.Dayjs];
|
|
29
|
+
};
|
|
30
|
+
export declare function presets_date(): {
|
|
31
|
+
label: string;
|
|
32
|
+
value: any;
|
|
33
|
+
}[];
|
|
34
|
+
export declare function isMoment(m: any): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* 获取若干天后的日期
|
|
37
|
+
*/
|
|
38
|
+
export declare function getFutureDate(num: number): any;
|
|
39
|
+
export declare function dayjs_quarter(input: Dayjs, which_quarter?: number): [Dayjs, number];
|
|
40
|
+
export declare function diff_between(a: ConfigType, b: ConfigType, unit: QUnitType | OpUnitType, float?: boolean): number;
|
|
41
|
+
export { dayjs };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnyObject } from './type-utils';
|
|
2
|
+
import { ICommonOption } from './types';
|
|
3
|
+
interface ISpectialOption {
|
|
4
|
+
sp?: ICommonOption[];
|
|
5
|
+
start?: number;
|
|
6
|
+
useString?: boolean;
|
|
7
|
+
useDefault?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const optionKey其他 = 99;
|
|
10
|
+
export declare const optionKey不详 = 100;
|
|
11
|
+
export declare const optionKey否 = 0;
|
|
12
|
+
type TOptionKey = string[] | string;
|
|
13
|
+
type TGetOptionKey = () => TOptionKey;
|
|
14
|
+
type TOptions<T extends TOptionKey | TGetOptionKey> = T extends TOptionKey ? ICommonOption[] : () => ICommonOption[];
|
|
15
|
+
export declare function getSimpleOptions<T extends TOptionKey | TGetOptionKey>(_arr: T, options?: ISpectialOption): TOptions<T>;
|
|
16
|
+
export declare function getSameOptions<T extends TOptionKey | TGetOptionKey>(_arr: T): TOptions<T>;
|
|
17
|
+
export declare function getDualModeOptions<T extends TOptionKey | TGetOptionKey>(arr: T, options?: ISpectialOption): readonly [TOptions<T>, TOptions<T>];
|
|
18
|
+
export declare function getPresetOptions(key: string, pure?: boolean): ICommonOption[];
|
|
19
|
+
export declare function getOptionLabel(k: string, value: any, defaultLabel?: string): string;
|
|
20
|
+
export declare function getOptionValue(k: string, label: any): any;
|
|
21
|
+
export declare function merge_preset_options(ops: AnyObject<() => ICommonOption[]>): void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AnyObject } from "./type-utils";
|
|
2
|
+
export type TCommonFileType = 'application/vnd.ms-excel' | 'text/csv;charset=utf-8' | 'application/msword';
|
|
3
|
+
export declare function get_global(): typeof globalThis;
|
|
4
|
+
export declare function getSearchParamsValue(key: string): string | null;
|
|
5
|
+
export declare function getSearchParamsAll(url?: URL): AnyObject<string>;
|
|
6
|
+
export declare function setSearchParamsValue(key: string, value: string | number): URL;
|
|
7
|
+
export declare function setSearchParamsAll(data: AnyObject<string | number>): URL;
|
|
8
|
+
export declare function scrollIntoView(symbol: string, finder?: (selectors: string) => Element | null): void;
|
|
9
|
+
export declare function base64ToBinary(data: string, type: TCommonFileType): Blob;
|
|
10
|
+
export declare function downloadFile(content: string | Blob, filename?: string, type?: TCommonFileType, isBase64?: boolean): void;
|
|
11
|
+
export declare function uuid(): string;
|
|
12
|
+
export declare function randomHex(): number;
|
|
13
|
+
export declare function charToUTF8(char: string): number[];
|
|
14
|
+
export declare function charToUnicode(char: string): number;
|
|
15
|
+
export declare function unicodeToChar(u: number): string | null;
|
|
16
|
+
export declare function unicode_to_UTF8(u: number): number[] | null;
|
|
17
|
+
export declare function getFilledArray(n: number): any[];
|
|
18
|
+
export declare function copyText(text: string): boolean;
|
|
19
|
+
export declare function dyn_cb<T>(cb: (ctx: T) => void, g_ctx: () => T): boolean;
|
|
20
|
+
export declare function safeExec<T extends (...args: any) => any>(fn?: T, ...args: Parameters<T>): any;
|
|
21
|
+
export declare function safeGetFromFuncOrData(fn: any, default_v?: any): any;
|
|
22
|
+
export declare function numberLikeCompare(a: number | string | boolean | null, b: number | string | boolean | null): boolean;
|
|
23
|
+
export declare function warpBase64Type(str: string, type: 'img' | 'pdf'): string;
|
|
24
|
+
export declare function safe_number_parse(value: any, defaultValue?: number): number;
|
|
25
|
+
export declare function expect_array<T>(value?: T[] | null, default_v?: T[]): T[];
|
|
26
|
+
export declare function gen_encoded_char_svg(props: {
|
|
27
|
+
char: string;
|
|
28
|
+
size?: number;
|
|
29
|
+
color?: string;
|
|
30
|
+
}): string;
|
|
31
|
+
export declare function base64_to_image(base64img: string): Promise<HTMLImageElement | null>;
|
|
32
|
+
export declare function image_to_base64(img_el: HTMLImageElement): string | null;
|
|
33
|
+
export declare function filter_obj_to_url_search(obj: Object | any[]): any;
|
|
34
|
+
export declare function safe_async_call<T extends (...args: any) => any>(cb?: T, ...args: Parameters<T>): Promise<ReturnType<T> | null>;
|
|
35
|
+
export declare function cache_fetch<T = any>(key: string, cb: () => Promise<T>, deep?: boolean): Promise<T>;
|
|
36
|
+
export declare function speculate_on_display(value?: any): string;
|
|
37
|
+
export declare function getFuckTimeInterval(star_hour?: number, end_hour?: number, min_interval?: 1 | 2 | 3 | 4 | 5 | 6 | 10 | 15 | 20 | 30): string[];
|
|
38
|
+
export declare function random_word(): string[];
|
|
39
|
+
export declare function confirm_operation(): boolean;
|
|
40
|
+
export declare function simple_encrypt(data: AnyObject | any[]): number[] | null;
|
|
41
|
+
export declare function simple_decrypt(code: number[]): AnyObject | null;
|
|
42
|
+
export declare function simple_encrypt_str(data: string, sp?: string): string | null;
|
|
43
|
+
export declare function simple_decrypt_str(code: string, sp?: string): string | null;
|
|
44
|
+
export declare function text_ellipsis(text: string, max: number): string;
|
|
45
|
+
export declare function calc_number(data: AnyObject | any[] | number | string | boolean): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type PropertyKey = string | number | symbol;
|
|
2
|
+
export type PartialAll<T> = {
|
|
3
|
+
[P in keyof T]?: T[P] extends Array<any> ? Partial<T[P][number]>[] : Partial<T[P]>;
|
|
4
|
+
};
|
|
5
|
+
export type PartialSome<T, K extends keyof T> = {
|
|
6
|
+
[P in K]?: T[P];
|
|
7
|
+
} & Pick<T, Exclude<keyof T, K>>;
|
|
8
|
+
export type AnyObject<T = any> = {
|
|
9
|
+
[x: string]: T;
|
|
10
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface ICommonOption {
|
|
2
|
+
value?: any;
|
|
3
|
+
label?: string;
|
|
4
|
+
tip?: string;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
sufix?: string;
|
|
7
|
+
suffix?: string;
|
|
8
|
+
props?: any;
|
|
9
|
+
warning?: boolean;
|
|
10
|
+
parentheses?: boolean;
|
|
11
|
+
exclusive?: boolean;
|
|
12
|
+
inputType?: string;
|
|
13
|
+
id?: any;
|
|
14
|
+
text?: any;
|
|
15
|
+
code?: any;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|