forked from metarhia/metautil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metautil.d.ts
114 lines (98 loc) · 3.56 KB
/
metautil.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { EventEmitter } from 'events';
import { IncomingMessage } from 'http';
export function cryptoRandom(): number;
export function generateKey(length: number, possible: string): string;
export function crcToken(secret: string, key: string): string;
export function md5(fileName: string): Promise<string>;
export function generateToken(
secret: string,
characters: string,
length: number
): string;
export function validateToken(secret: string, token: string): boolean;
export function hashPassword(password: string): Promise<string>;
export function validatePassword(
password: string,
serHash: string
): Promise<boolean>;
export function random(min: number, max?: number): number;
export function sample(arr: Array<any>): any;
export function ipToInt(ip?: string): number;
export function parseHost(host?: string): string;
export function parseParams(params: string): object;
export function replace(str: string, substr: string, newstr: string): string;
export function split(s: string, separator: string): [string, string];
export function fileExt(fileName: string): string;
export function parsePath(relPath: string): Array<string>;
export function between(s: string, prefix: string, suffix: string): string;
export function isFirstUpper(s: string): boolean;
export function toLowerCamel(s: string): string;
export function toUpperCamel(s: string): string;
export function toLower(s: string): string;
export function toCamel(separator: string): (s: string) => string;
export function spinalToCamel(s: string): string;
export function snakeToCamel(s: string): string;
export function isConstant(s: string): boolean;
export function nowDate(date?: Date): string;
export function nowDateTimeUTC(date?: Date, timeSep?: string): string;
export function duration(s: string | number): number;
export function bytesToSize(bytes: number): string;
export function sizeToBytes(size: string): number;
export function namespaceByPath(namespace: object, path: string): object | null;
type Every = {
month: number;
day: number;
dd: number;
hh: number;
mm: number;
interval: number;
};
export type { Every };
export function parseEvery(s: string): Every;
export function nextEvent(every: Every, date?: Date): number;
export function makePrivate(instance: object): object;
export function protect(
allowMixins: Array<string>,
...namespaces: Array<object>
): void;
export function parseCookies(cookie: string): object;
export interface AbortController {
abort: Function;
signal: EventEmitter;
}
export function createAbortController(): AbortController;
export function timeout(msec: number, signal?: EventEmitter): Promise<void>;
export function delay(msec: number, signal?: EventEmitter): Promise<void>;
export interface QueueElement {
resolve: Function;
timer: NodeJS.Timer;
}
export class Semaphore {
constructor(concurrency: number, size?: number, timeout?: number);
concurrency: number;
counter: number;
timeout: number;
size: number;
empty: boolean;
queue: Array<QueueElement>;
enter(): Promise<void>;
leave(): void;
}
export class Pool {
constructor(options: { timeout?: number });
items: Array<object>;
free: Array<boolean>;
queue: Array<object>;
current: number;
size: number;
available: number;
timeout: number;
next(): Promise<object | null>;
add(item: object): void;
capture(): Promise<object | null>;
release(item: object): void;
isFree(item: object): boolean;
}
export function fetch(url: string): Promise<string>;
export function jsonParse(buffer: Buffer): object | null;
export function receiveBody(req: IncomingMessage): Promise<Buffer | null>;