full-utils 2.0.0 → 2.0.2
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/dist/browser.cjs +3 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +1 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.mjs +3 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/index.cjs +2 -1038
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/node.cjs +3 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +166 -0
- package/dist/node.d.ts +166 -0
- package/dist/node.mjs +3 -0
- package/dist/node.mjs.map +1 -0
- package/package.json +12 -2
- package/dist/index.js +0 -978
- package/dist/index.js.map +0 -1
package/dist/node.d.cts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
export { FixedDecimal, JSONLike, PasswordOptions, RangeIPv4Options, TimeParts, changeFixedDecimalScale, cidrToRange, convertExponentialToParts, extractHost, fixedDecimalToNum, fixedDecimalToStr, floorDateToMinutes, formatDateToString, formatStrToFuncArgs, formatToBool, formatToLowerCase, formatToNormalCase, formatToNull, formatToNum, formatToPhone, formatToTrim, formatToUndefined, ipAddrToNum, isArr, isArrFilled, isBool, isDate, isEmail, isExists, isFunc, isIpAddr, isMacAddr, isNum, isNumFloat, isNumN, isNumNZ, isNumP, isNumPZ, isObj, isObjFilled, isPassword, isPhone, isStr, isStrAscDesc, isStrBool, isStrFilled, isVar, jsonDecode, jsonEncode, normalizeToDecimalComponents, numToIpAddr, parseIPv4, parseStringLike, parseToFixedDecimal, partsToSeconds, rangeIPv4, rangeIPv4ToArr, roundFixedDecimal, secondsToParts, splitArrToPortions, toGB, toGH, toH, toIPv4, tryParseJSON, wait } from './index.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options controlling TCP connection behavior, request formatting, and response handling.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
interface NetTCPOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Remote TCP port to connect to.
|
|
11
|
+
*
|
|
12
|
+
* @defaultValue 4028
|
|
13
|
+
* @remarks Must be an integer in the range 1–65535, otherwise `EBADPORT` is thrown.
|
|
14
|
+
*/
|
|
15
|
+
port?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Idle timeout in milliseconds applied to the underlying socket.
|
|
18
|
+
* If no data is received within this period after connection, the operation fails.
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue 0 (no idle timeout)
|
|
21
|
+
* @remarks On expiry, the promise rejects with `ETIMEDOUT` ("Idle timeout").
|
|
22
|
+
*/
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Cooperative cancellation token. If the signal is already aborted (or aborts later),
|
|
26
|
+
* the operation is terminated early.
|
|
27
|
+
*
|
|
28
|
+
* @remarks Rejects with `EABORT` ("Operation cancelled").
|
|
29
|
+
*/
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/**
|
|
32
|
+
* Hard cap on response size in bytes. If the cumulative number of bytes read
|
|
33
|
+
* exceeds this limit, the read is aborted.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue 0 (no limit)
|
|
36
|
+
* @remarks On overflow, rejects with `ERESPONSE_TOO_LARGE`.
|
|
37
|
+
*/
|
|
38
|
+
maxBytes?: number;
|
|
39
|
+
/**
|
|
40
|
+
* When `true`, call `socket.end()` immediately after the request payload is fully written.
|
|
41
|
+
* This is useful for protocols where the client signals “no more data” by half-closing.
|
|
42
|
+
*
|
|
43
|
+
* @defaultValue false
|
|
44
|
+
*/
|
|
45
|
+
halfCloseAfterWrite?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Optional line terminator automatically appended to the outgoing message.
|
|
48
|
+
*
|
|
49
|
+
* @defaultValue '' (no terminator)
|
|
50
|
+
* @remarks Common values are `'\n'` or `'\r\n'` for CRLF-terminated protocols.
|
|
51
|
+
*/
|
|
52
|
+
lineTerminator?: '' | '\n' | '\r\n';
|
|
53
|
+
/**
|
|
54
|
+
* Separate timeout for the **connect phase** (DNS+TCP handshake).
|
|
55
|
+
* If the connection is not established within this period, the operation fails.
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue 0 (no connect timeout)
|
|
58
|
+
* @remarks On expiry, rejects with `ETIMEDOUT` ("Connect timed out").
|
|
59
|
+
*/
|
|
60
|
+
connectTimeoutMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Text encoding used to encode the outgoing message and decode the response.
|
|
63
|
+
*
|
|
64
|
+
* @defaultValue 'utf8'
|
|
65
|
+
* @remarks The accepted values are `'utf8'` or `'utf-8'` (normalized to `'utf8'`).
|
|
66
|
+
*/
|
|
67
|
+
encoding?: 'utf8' | 'utf-8';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Error object shape for socket-level failures. Extends the standard {@link Error}
|
|
71
|
+
* with common Node.js errno-style fields when available.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
interface TcpError extends Error {
|
|
76
|
+
/**
|
|
77
|
+
* Optional string error code (e.g., `'ECONNREFUSED'`, `'ETIMEDOUT'`, `'EPIPE'`).
|
|
78
|
+
*/
|
|
79
|
+
code?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Optional numeric errno associated with low-level system errors.
|
|
82
|
+
*/
|
|
83
|
+
errno?: number;
|
|
84
|
+
/**
|
|
85
|
+
* The system call that failed, when available (e.g., `'connect'`, `'read'`, `'write'`).
|
|
86
|
+
*/
|
|
87
|
+
syscall?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Related filesystem/IPC path when applicable (usually `undefined` for TCP).
|
|
90
|
+
*/
|
|
91
|
+
path?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Open a TCP connection to a host, send a text payload, and return the server’s response as a string.
|
|
96
|
+
*
|
|
97
|
+
* @param message - The request body to send. If `lineTerminator` is set, it is appended automatically.
|
|
98
|
+
* @param host - Hostname or IP address to connect to.
|
|
99
|
+
* @param options - Behavior and safety knobs for the connection, timeouts, encoding, and buffering.
|
|
100
|
+
* @param options.port - Remote TCP port. Default: 4028}
|
|
101
|
+
* @param options.timeoutMs - Idle timeout after connect/read in milliseconds. Default: 0}
|
|
102
|
+
* @param options.signal - AbortSignal for cooperative cancellation.
|
|
103
|
+
* @param options.maxBytes - Maximum response size in bytes; 0 means unlimited. Default: 0}
|
|
104
|
+
* @param options.halfCloseAfterWrite - Call `socket.end()` after writing the request. Default: false}
|
|
105
|
+
* @param options.lineTerminator - Optional `'\n'` / `'\r\n'` suffix to append. Default: ''}
|
|
106
|
+
* @param options.connectTimeoutMs - Timeout for establishing the connection. Default: 0}
|
|
107
|
+
* @param options.encoding - `'utf8'` or `'utf-8'` used for I/O. Default: 'utf8'}
|
|
108
|
+
*
|
|
109
|
+
* @returns A promise that resolves to the full response string (decoded using `encoding`).
|
|
110
|
+
*
|
|
111
|
+
* @throws {Error} ENODEONLY
|
|
112
|
+
* Thrown when executed in a non-Node.js environment (e.g., a browser).
|
|
113
|
+
*
|
|
114
|
+
* @throws {Error} EBADHOST
|
|
115
|
+
* Thrown when `host` is not a non-empty string.
|
|
116
|
+
*
|
|
117
|
+
* @throws {Error} EBADMSG
|
|
118
|
+
* Thrown when `message` is not a non-empty string.
|
|
119
|
+
*
|
|
120
|
+
* @throws {Error} EBADPORT
|
|
121
|
+
* Thrown when `port` is outside the range 1–65535 or not an integer.
|
|
122
|
+
*
|
|
123
|
+
* @throws {Error} ENETIMPORT
|
|
124
|
+
* Thrown if dynamic import of the `node:net` module fails.
|
|
125
|
+
*
|
|
126
|
+
* @throws {Error} EABORT
|
|
127
|
+
* Thrown if the provided {@link AbortSignal} is already aborted or aborts during the operation.
|
|
128
|
+
*
|
|
129
|
+
* @throws {Error} ETIMEDOUT
|
|
130
|
+
* Thrown in these cases:
|
|
131
|
+
* - `"Connect timed out"`: connect phase exceeded `connectTimeoutMs`.
|
|
132
|
+
* - `"Idle timeout"`: no data within `timeoutMs` after connection.
|
|
133
|
+
*
|
|
134
|
+
* @throws {Error} ERESPONSE_TOO_LARGE
|
|
135
|
+
* Thrown when the accumulated response exceeds `maxBytes`.
|
|
136
|
+
*
|
|
137
|
+
* @throws {TcpError}
|
|
138
|
+
* Any socket `'error'` event is forwarded (e.g., `ECONNREFUSED`, `ENOTFOUND`, `EPIPE`).
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* - **Lifecycle:** The socket’s listeners are cleaned up and the socket destroyed on settle.
|
|
142
|
+
* - **Close semantics:** If the socket emits `'close'` with `hadError=true`, the promise rejects with `ECLOSE`.
|
|
143
|
+
* - **Performance:** If you expect large responses, set a realistic `maxBytes` to avoid excessive memory usage.
|
|
144
|
+
* - **Protocols:** For request/response style text protocols (e.g., simple line-based services), set
|
|
145
|
+
* `lineTerminator` (e.g., `'\n'`) and optionally `halfCloseAfterWrite=true` if the server expects EOF to start responding.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* // CRLF-terminated request with half-close to signal EOF
|
|
150
|
+
* const resp = await netTCP('STATUS', '192.0.2.10', {
|
|
151
|
+
* port: 9000,
|
|
152
|
+
* lineTerminator: '\r\n',
|
|
153
|
+
* halfCloseAfterWrite: true,
|
|
154
|
+
* timeoutMs: 3000,
|
|
155
|
+
* maxBytes: 256 * 1024, // 256 KiB cap
|
|
156
|
+
* });
|
|
157
|
+
* console.log(resp);
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @see AbortSignal
|
|
161
|
+
* @see https://nodejs.org/api/net.html Node.js net module
|
|
162
|
+
* @since 2.0.0
|
|
163
|
+
*/
|
|
164
|
+
declare function netTCP(message: string, host: string, { port, timeoutMs, connectTimeoutMs, encoding, signal, maxBytes, halfCloseAfterWrite, lineTerminator, }?: NetTCPOptions): Promise<string>;
|
|
165
|
+
|
|
166
|
+
export { type NetTCPOptions, type TcpError, netTCP };
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
export { FixedDecimal, JSONLike, PasswordOptions, RangeIPv4Options, TimeParts, changeFixedDecimalScale, cidrToRange, convertExponentialToParts, extractHost, fixedDecimalToNum, fixedDecimalToStr, floorDateToMinutes, formatDateToString, formatStrToFuncArgs, formatToBool, formatToLowerCase, formatToNormalCase, formatToNull, formatToNum, formatToPhone, formatToTrim, formatToUndefined, ipAddrToNum, isArr, isArrFilled, isBool, isDate, isEmail, isExists, isFunc, isIpAddr, isMacAddr, isNum, isNumFloat, isNumN, isNumNZ, isNumP, isNumPZ, isObj, isObjFilled, isPassword, isPhone, isStr, isStrAscDesc, isStrBool, isStrFilled, isVar, jsonDecode, jsonEncode, normalizeToDecimalComponents, numToIpAddr, parseIPv4, parseStringLike, parseToFixedDecimal, partsToSeconds, rangeIPv4, rangeIPv4ToArr, roundFixedDecimal, secondsToParts, splitArrToPortions, toGB, toGH, toH, toIPv4, tryParseJSON, wait } from './index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options controlling TCP connection behavior, request formatting, and response handling.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
interface NetTCPOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Remote TCP port to connect to.
|
|
11
|
+
*
|
|
12
|
+
* @defaultValue 4028
|
|
13
|
+
* @remarks Must be an integer in the range 1–65535, otherwise `EBADPORT` is thrown.
|
|
14
|
+
*/
|
|
15
|
+
port?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Idle timeout in milliseconds applied to the underlying socket.
|
|
18
|
+
* If no data is received within this period after connection, the operation fails.
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue 0 (no idle timeout)
|
|
21
|
+
* @remarks On expiry, the promise rejects with `ETIMEDOUT` ("Idle timeout").
|
|
22
|
+
*/
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Cooperative cancellation token. If the signal is already aborted (or aborts later),
|
|
26
|
+
* the operation is terminated early.
|
|
27
|
+
*
|
|
28
|
+
* @remarks Rejects with `EABORT` ("Operation cancelled").
|
|
29
|
+
*/
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
/**
|
|
32
|
+
* Hard cap on response size in bytes. If the cumulative number of bytes read
|
|
33
|
+
* exceeds this limit, the read is aborted.
|
|
34
|
+
*
|
|
35
|
+
* @defaultValue 0 (no limit)
|
|
36
|
+
* @remarks On overflow, rejects with `ERESPONSE_TOO_LARGE`.
|
|
37
|
+
*/
|
|
38
|
+
maxBytes?: number;
|
|
39
|
+
/**
|
|
40
|
+
* When `true`, call `socket.end()` immediately after the request payload is fully written.
|
|
41
|
+
* This is useful for protocols where the client signals “no more data” by half-closing.
|
|
42
|
+
*
|
|
43
|
+
* @defaultValue false
|
|
44
|
+
*/
|
|
45
|
+
halfCloseAfterWrite?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Optional line terminator automatically appended to the outgoing message.
|
|
48
|
+
*
|
|
49
|
+
* @defaultValue '' (no terminator)
|
|
50
|
+
* @remarks Common values are `'\n'` or `'\r\n'` for CRLF-terminated protocols.
|
|
51
|
+
*/
|
|
52
|
+
lineTerminator?: '' | '\n' | '\r\n';
|
|
53
|
+
/**
|
|
54
|
+
* Separate timeout for the **connect phase** (DNS+TCP handshake).
|
|
55
|
+
* If the connection is not established within this period, the operation fails.
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue 0 (no connect timeout)
|
|
58
|
+
* @remarks On expiry, rejects with `ETIMEDOUT` ("Connect timed out").
|
|
59
|
+
*/
|
|
60
|
+
connectTimeoutMs?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Text encoding used to encode the outgoing message and decode the response.
|
|
63
|
+
*
|
|
64
|
+
* @defaultValue 'utf8'
|
|
65
|
+
* @remarks The accepted values are `'utf8'` or `'utf-8'` (normalized to `'utf8'`).
|
|
66
|
+
*/
|
|
67
|
+
encoding?: 'utf8' | 'utf-8';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Error object shape for socket-level failures. Extends the standard {@link Error}
|
|
71
|
+
* with common Node.js errno-style fields when available.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
interface TcpError extends Error {
|
|
76
|
+
/**
|
|
77
|
+
* Optional string error code (e.g., `'ECONNREFUSED'`, `'ETIMEDOUT'`, `'EPIPE'`).
|
|
78
|
+
*/
|
|
79
|
+
code?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Optional numeric errno associated with low-level system errors.
|
|
82
|
+
*/
|
|
83
|
+
errno?: number;
|
|
84
|
+
/**
|
|
85
|
+
* The system call that failed, when available (e.g., `'connect'`, `'read'`, `'write'`).
|
|
86
|
+
*/
|
|
87
|
+
syscall?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Related filesystem/IPC path when applicable (usually `undefined` for TCP).
|
|
90
|
+
*/
|
|
91
|
+
path?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Open a TCP connection to a host, send a text payload, and return the server’s response as a string.
|
|
96
|
+
*
|
|
97
|
+
* @param message - The request body to send. If `lineTerminator` is set, it is appended automatically.
|
|
98
|
+
* @param host - Hostname or IP address to connect to.
|
|
99
|
+
* @param options - Behavior and safety knobs for the connection, timeouts, encoding, and buffering.
|
|
100
|
+
* @param options.port - Remote TCP port. Default: 4028}
|
|
101
|
+
* @param options.timeoutMs - Idle timeout after connect/read in milliseconds. Default: 0}
|
|
102
|
+
* @param options.signal - AbortSignal for cooperative cancellation.
|
|
103
|
+
* @param options.maxBytes - Maximum response size in bytes; 0 means unlimited. Default: 0}
|
|
104
|
+
* @param options.halfCloseAfterWrite - Call `socket.end()` after writing the request. Default: false}
|
|
105
|
+
* @param options.lineTerminator - Optional `'\n'` / `'\r\n'` suffix to append. Default: ''}
|
|
106
|
+
* @param options.connectTimeoutMs - Timeout for establishing the connection. Default: 0}
|
|
107
|
+
* @param options.encoding - `'utf8'` or `'utf-8'` used for I/O. Default: 'utf8'}
|
|
108
|
+
*
|
|
109
|
+
* @returns A promise that resolves to the full response string (decoded using `encoding`).
|
|
110
|
+
*
|
|
111
|
+
* @throws {Error} ENODEONLY
|
|
112
|
+
* Thrown when executed in a non-Node.js environment (e.g., a browser).
|
|
113
|
+
*
|
|
114
|
+
* @throws {Error} EBADHOST
|
|
115
|
+
* Thrown when `host` is not a non-empty string.
|
|
116
|
+
*
|
|
117
|
+
* @throws {Error} EBADMSG
|
|
118
|
+
* Thrown when `message` is not a non-empty string.
|
|
119
|
+
*
|
|
120
|
+
* @throws {Error} EBADPORT
|
|
121
|
+
* Thrown when `port` is outside the range 1–65535 or not an integer.
|
|
122
|
+
*
|
|
123
|
+
* @throws {Error} ENETIMPORT
|
|
124
|
+
* Thrown if dynamic import of the `node:net` module fails.
|
|
125
|
+
*
|
|
126
|
+
* @throws {Error} EABORT
|
|
127
|
+
* Thrown if the provided {@link AbortSignal} is already aborted or aborts during the operation.
|
|
128
|
+
*
|
|
129
|
+
* @throws {Error} ETIMEDOUT
|
|
130
|
+
* Thrown in these cases:
|
|
131
|
+
* - `"Connect timed out"`: connect phase exceeded `connectTimeoutMs`.
|
|
132
|
+
* - `"Idle timeout"`: no data within `timeoutMs` after connection.
|
|
133
|
+
*
|
|
134
|
+
* @throws {Error} ERESPONSE_TOO_LARGE
|
|
135
|
+
* Thrown when the accumulated response exceeds `maxBytes`.
|
|
136
|
+
*
|
|
137
|
+
* @throws {TcpError}
|
|
138
|
+
* Any socket `'error'` event is forwarded (e.g., `ECONNREFUSED`, `ENOTFOUND`, `EPIPE`).
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* - **Lifecycle:** The socket’s listeners are cleaned up and the socket destroyed on settle.
|
|
142
|
+
* - **Close semantics:** If the socket emits `'close'` with `hadError=true`, the promise rejects with `ECLOSE`.
|
|
143
|
+
* - **Performance:** If you expect large responses, set a realistic `maxBytes` to avoid excessive memory usage.
|
|
144
|
+
* - **Protocols:** For request/response style text protocols (e.g., simple line-based services), set
|
|
145
|
+
* `lineTerminator` (e.g., `'\n'`) and optionally `halfCloseAfterWrite=true` if the server expects EOF to start responding.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* // CRLF-terminated request with half-close to signal EOF
|
|
150
|
+
* const resp = await netTCP('STATUS', '192.0.2.10', {
|
|
151
|
+
* port: 9000,
|
|
152
|
+
* lineTerminator: '\r\n',
|
|
153
|
+
* halfCloseAfterWrite: true,
|
|
154
|
+
* timeoutMs: 3000,
|
|
155
|
+
* maxBytes: 256 * 1024, // 256 KiB cap
|
|
156
|
+
* });
|
|
157
|
+
* console.log(resp);
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @see AbortSignal
|
|
161
|
+
* @see https://nodejs.org/api/net.html Node.js net module
|
|
162
|
+
* @since 2.0.0
|
|
163
|
+
*/
|
|
164
|
+
declare function netTCP(message: string, host: string, { port, timeoutMs, connectTimeoutMs, encoding, signal, maxBytes, halfCloseAfterWrite, lineTerminator, }?: NetTCPOptions): Promise<string>;
|
|
165
|
+
|
|
166
|
+
export { type NetTCPOptions, type TcpError, netTCP };
|
package/dist/node.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function dt(t){if(!f(t))return [t];let n=t.trim();if(n==="")return [];if(n.startsWith("[")&&n.endsWith("]")&&(n=n.slice(1,-1).trim(),n===""))return [];let r="",e=false,i=null,o=false,s=0,p=0,d=0,T=[],w=()=>{let u=r.trim();u!==""&&T.push(u),r="";};for(let u=0;u<n.length;u++){let c=n[u];if(e){if(r+=c,o){o=false;continue}if(c==="\\"){o=true;continue}c===i&&(e=false,i=null);continue}if(c==='"'||c==="'"){e=true,i=c,r+=c;continue}if(c==="("){s++,r+=c;continue}if(c===")"){s=Math.max(0,s-1),r+=c;continue}if(c==="["){p++,r+=c;continue}if(c==="]"){p=Math.max(0,p-1),r+=c;continue}if(c==="{"){d++,r+=c;continue}if(c==="}"){d=Math.max(0,d-1),r+=c;continue}if(c===","&&s===0&&p===0&&d===0){w();continue}r+=c;}return r.length&&w(),T.map(u=>{if(u.startsWith("$")&&u.includes("(")&&u.endsWith(")"))return u;if(u==="null")return null;if(u==="undefined")return;if(W(u))return J(u);let c=F(u);if(Number.isFinite(c))return c;if(u==="Infinity")return 1/0;if(u==="-Infinity")return -1/0;let g=String(u||"");if(g.length>=2&&(g.startsWith("'")&&g.endsWith("'")||g.startsWith('"')&&g.endsWith('"')))return g.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\'/g,"'").replace(/\\"/g,'"');if(g.startsWith("{")&&g.endsWith("}")||g.startsWith("[")&&g.endsWith("]"))try{return Z(g)}catch{}return g})}function ht(t,n){if(!Number.isInteger(n)||n<=0)return [];let r=[],e=0;for(;e<t.length;)r.push(t.slice(e,e+n)),e+=n;return r}function J(t){switch(true){case $(t):return t;case S(t):return true;case _(t):return false;case(m(t)&&["true","1","yes","on"].includes(String(t??"").trim().toLowerCase())):return true;case(m(t)&&["false","0","no","off"].includes(String(t??"").trim().toLowerCase())):return false}return false}async function bt(t=0){await new Promise(n=>setTimeout(()=>n(true),t));}function yt(t=1,n=new Date){let r=Math.min(60,Math.max(1,Math.trunc(Math.abs(t)))),e=n.getMinutes(),i=Math.floor(e/r)*r,o=new Date(n);return o.setMinutes(i,0,0),o}function St(t=new Date){let n=d=>String(d).padStart(2,"0"),r=t.getFullYear(),e=n(t.getMonth()+1),i=n(t.getDate()),o=n(t.getHours()),s=n(t.getMinutes()),p=n(t.getSeconds());return `${r}-${e}-${i} ${o}:${s}:${p}`}function Ft(t){let{days:n=0,hours:r=0,minutes:e=0,seconds:i=0}=t;return n*86400+r*3600+e*60+i}function Ot(t){if(!Number.isFinite(t)||t<0)throw new Error("Invalid total seconds");let n=Math.floor(t/86400),r=Math.floor(t%86400/3600),e=Math.floor(t%3600/60),i=t%60;return {days:n,hours:r,minutes:e,seconds:i}}function G(t){let[n,r]=t.split("/"),e=I(n),i=r?Number(r):NaN;if(e===null||!Number.isInteger(i)||i<0||i>32)return null;let o=i===0?0:4294967295<<32-i>>>0,s=e&o,p=s|~o>>>0;return [D(s),D(p)]}function Bt(t){let n=t.split(".").map(o=>Number(o));if(n.length!==4||n.some(o=>!Number.isInteger(o)||o<0||o>255))throw new Error("Invalid IPv4 address");let r=new ArrayBuffer(4),e=new DataView(r),i=0;for(;i<4;)e.setUint8(i,n[i]),i++;return e.getUint32(0,false)}function Mt(t){if(!S(t))return "";let n=new ArrayBuffer(4),r=new DataView(n);r.setUint32(0,t,false);let e=[],i=0;for(;i<4;)e.push(r.getUint8(i)),i++;return e.join(".")}function I(t){if(!f(t))return null;let n=b(t).split(".");if(n.length!==4)return null;let r=0;for(let e=0;e<4;e++){if(!/^\d{1,3}$/.test(n[e]))return null;let i=Number(n[e]);if(i<0||i>255)return null;r=r<<8|i;}return r>>>0}function*H(t,n,r={}){let{includeNetwork:e=true,includeBroadcast:i=true}=r,o,s,p=false,d=null;if(n===void 0&&t.includes("/")){let u=G(t);if(!u)throw new Error(`Invalid CIDR: "${t}"`);let[c,g]=u,[l,k]=t.split("/");d=Number(k),o=I(c),s=I(g),p=true;}else {let u=I(t);if(u===null)throw new Error(`Invalid IPv4: "${t}"`);if(o=u,n&&n.trim()!==""){let c=I(n);if(c===null)throw new Error(`Invalid IPv4: "${n}"`);s=c;}else {let c=o>>>24&255,g=o>>>16&255,l=o>>>8&255;s=(c<<24|g<<16|l<<8|255)>>>0;}}o>s&&([o,s]=[s,o]);let T=-1,w=-1;p&&d!==null&&d<=30&&(T=o,w=s);for(let u=o;u<=s;u=u+1>>>0){if(!e&&u===T){if(u===s)break;continue}if(!i&&u===w){if(u===s)break;continue}if(yield D(u),u===4294967295)break}}function Gt(t,n,r={}){let{limit:e=1e6}=r,i=[],o=0;for(let s of H(t,n,r)){if(o>=e)throw new Error(`Range is too large (> ${e}). Use the generator version instead.`);i.push(s),o++;}return i}function D(t){if(!Number.isInteger(t)||t<0||t>4294967295)throw new Error(`Invalid IPv4 number: ${t}`);return [t>>>24&255,t>>>16&255,t>>>8&255,t&255].join(".")}function O(t){return Array.isArray(t)}function V(t){return O(t)&&t.length>0}function $(t){return typeof t=="boolean"}function Xt(t){if(t instanceof Date)return !Number.isNaN(t.getTime());if(f(t)||a(t)){let n=new Date(t);return !Number.isNaN(n.getTime())}return false}var ot=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z]{2,})+$/;function rn(t){return m(t)?ot.test(t):false}function on(t){return t!=null}function Q(t){return typeof t=="function"}var st=/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;function fn(t){if(!f(t))return false;let n=t.trim();return st.test(n)}function ln(t){return f(t)&&/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(t)}function a(t){return typeof t=="number"&&Number.isFinite(t)}function hn(t){return a(t)&&!Number.isInteger(t)}function wn(t){return a(t)&&t<0}function _(t){return a(t)&&t<=0}function S(t){return a(t)&&t>0}function v(t){return a(t)&&t>=0}function E(t){return typeof t=="object"&&t!==null&&Object.prototype.toString.call(t)==="[object Object]"&&!Array.isArray(t)}function K(t){return E(t)&&Object.keys(t).length>0}function An(t,{minLength:n=8,maxLength:r=256,requireUppercase:e=true,requireLowercase:i=true,requireDigit:o=true,requireSpecial:s=true}={}){return !(!f(t)||t.length<n||t.length>r||e&&!/[A-ZА-Я]/.test(t)||i&&!/[a-zа-я]/.test(t)||o&&!/\d/.test(t)||s&&!/[~!?@#$%^&*_\-+()\[\]{}><\\\/|"'.,:;=]/.test(t))}function Rn(t){if(!m(t)&&!a(t))return false;let n=String(t).trim();return !(n.startsWith("-")||(n.match(/\+/g)||[]).length>1||n.includes("+")&&!n.startsWith("+")||!/^\+?[0-9-]+$/.test(n)||n.length<3||n.length>20||!/[0-9]$/.test(n)||n.includes("--"))}function f(t){return typeof t=="string"}function W(t){if(!m(t))return false;let n=t.trim().toLowerCase();return n==="true"||n==="false"}function m(t){return f(t)&&t.trim().length>0}function Wn(t){if(!m(t))return false;let n=t.trim().toLowerCase();return n==="asc"||n==="desc"}function Gn(t){return f(t)&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)}var ut=/^(['"`])([\s\S]*)\1$/;function R(t,n){let r=t.trim(),e=Y(r);if(e.ok)return e.value;let i=ut.exec(r);return i?i[2]:n?r:null}function Y(t){try{return {ok:!0,value:JSON.parse(t)}}catch{}return {ok:false}}function Z(t,n=false){if(t===null||a(t)||$(t))return t;if(V(t)){let r=t,e=[];for(let i of r)m(i)?e.push(R(String(i),n)):e.push(i);return e}if(K(t)){let r=t,e={};for(let i of Object.keys(r)){let o=r[i];m(o)?e[i]=R(String(o),n):e[i]=o;}return e}return O(t)||E(t)?t:m(t)?R(String(t),n):null}function nr(t){try{return E(t)||O(t)?JSON.stringify(t):""}catch{}return ""}function er(t,n){let r=Math.trunc(n);if(r===0)return {...t};if(r>0)return {sign:t.sign,digitsInteger:t.digitsInteger,scale:t.scale+r};let e=10n**BigInt(-r);return {sign:t.sign,digitsInteger:t.digitsInteger*e,scale:t.scale+r}}function j(t,n){let r=/^([0-9]+)(?:\.([0-9]*))?e([+\-]?[0-9]+)$/i.exec((()=>{let[o,s]=n.split(/e/i),[p,d=""]=o.split("."),T=p.replace(/^0+/,"")+d,w=parseInt(s,10)-d.length;return `${T||"0"}e${w}`})());if(!r)throw new Error("Failed to parse exponential notation.");let e=r[1],i=parseInt(r[3],10);if(v(i))return e=e+"0".repeat(i),{sign:t,integerPart:e||"0",fractionalPart:""};{let o=-i;if(o>=e.length){let s="0".repeat(o-e.length);return {sign:t,integerPart:"0",fractionalPart:s+e}}else {let s=e.length-o;return {sign:t,integerPart:e.slice(0,s),fractionalPart:e.slice(s)}}}}function q(t){return Number(X(t))}function X(t){let n=t.sign<0?"-":"",r=t.digitsInteger.toString();if(t.scale===0)return n+r;let e=t.scale-r.length;if(e>=0)return n+"0."+"0".repeat(e)+r;let i=r.length-t.scale,o=r.slice(0,i),s=r.slice(i);return n+o+"."+s}function F(t,n=1){return q(n>1?tt(z(t),n,"half-up"):z(t))}function nt(t){if(typeof t=="bigint"){let n=t<0n?-1:1,r=(t<0n?-t:t).toString();return {sign:n,integerPart:r,fractionalPart:""}}if(typeof t=="number"){if(!Number.isFinite(t))throw new Error("Input number is not finite.");let n=t<0?-1:1,e=Math.abs(t).toExponential(30);return j(n,e)}if(typeof t=="string"){let n=t.trim().replace(",",".");if(!n)throw new Error("Input string is empty.");let r=1;if((n.startsWith("+")||n.startsWith("-"))&&(r=n.startsWith("-")?-1:1,n=n.slice(1)),/^[0-9]*\.?[0-9]*(e[+\-]?[0-9]+)?$/i.test(n)){if(/e/i.test(n))return j(r,n);let[e="0",i=""]=n.split(".");return {sign:r,integerPart:e,fractionalPart:i}}throw new Error("Invalid numeric string.")}throw new Error("Unsupported input type.")}function z(t){let{sign:n,integerPart:r,fractionalPart:e}=nt(t),i=r.replace(/^0+/,"")||"0",o=e.replace(/0+$/,""),s=i+o||"0";return {sign:n,digitsInteger:BigInt(s),scale:o.length}}function tt(t,n,r="half-up"){let e=Math.max(0,Math.trunc(n));if(t.scale<=e)return {...t};let i=t.scale-e,o=10n**BigInt(i),s=t.digitsInteger/o,p=t.digitsInteger%o;if(r==="trunc"||p===0n)return {sign:t.sign,digitsInteger:s,scale:e};let d=o/2n,w=p>=d?s+1n:s;return {sign:t.sign,digitsInteger:w,scale:e}}function rt(t){if(!f(t))return "";let n=b(t);return m(n)?n.toLowerCase():""}function br(t){if(!f(t))return "";let n=rt(t);return m(n)?n[0].toUpperCase()+n.slice(1):""}function Sr(t){return f(t)&&b(t)===""||t===void 0?null:t}function Ir(t,n="+7"){if(!f(t))return null;let r=b(t).replace(/[\s\-().]/g,"");return /^00\d{8,15}$/.test(r)?r="+"+r.slice(2):/^\d{10}$/.test(r)?r=n+r:/^\d{9,15}$/.test(r)&&!r.startsWith("0")&&(r="+"+r),/^\+\d{10,15}$/.test(r)?r:null}function b(t){return String(f(t)?t.trim().normalize("NFKC").replace(/[\u200B-\u200D\uFEFF]/g,""):"")}function $r(t){return f(t)&&b(t)===""||t===null?void 0:t}var ct=1024,et=ct*1024,A=et*1024,it=A*1024,ft=it*1024;function Cr(t,n=""){let r=F(t);if(!a(r))throw new Error(`toGB: value "${t}" is not numeric`);let e=String(n).trim().toLowerCase().replace(/\s+/g,""),i=e?e[0]:"g",o;switch(i){case "b":o=r/A;break;case "k":o=r/et;break;case "m":o=r/A;break;case "g":o=r;break;case "t":o=r*(it/A);break;case "p":o=r*(ft/A);break;default:o=r;break}if(!a(o))throw new Error(`toGB: result is not finite (value="${t}", unit="${n}")`);return Object.is(o,-0)?0:o}function L(t){return String(t).trim().toLowerCase().replace(/\s+/g,"").replace(/(?:\/?s|hash(?:es)?)$/i,"")}var at={h:1e-9,k:1e-6,m:.001,g:1,t:1e3,p:1e6,e:1e9};function Jr(t,n=""){let r=F(t);if(!a(r))return 0;let e=L(n),i=e?e[0]:"g",o=at[i]??1,s=r*o;if(!a(s))throw new Error(`toGH: result is not finite (value="${r}", unit="${e}")`);return Object.is(s,-0)?0:s}var mt={h:1,k:1e3,m:1e6,g:1e9,t:1e12,p:1e15,e:1e18};function Gr(t,n=""){let r=F(t);if(!a(r))return 0;let e=L(n),i=e?e[0]:"h",o=mt[i]??1,s=r*o;if(!a(s))throw new Error(`toH: result is not finite (value="${r}", unit="${e}")`);return Object.is(s,-0)?0:s}var lt=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function Qr(t=""){if(!m(t))return "";let n=t.trim(),r=lt.test(n)?n:`http://${n}`;try{return new URL(r).hostname}catch{let i=(n.split("@").pop()||n).split(/[/?#]/,1)[0],o=i.match(/^\[([^\]]+)\]/);return o?o[1]:i.split(":",1)[0]||""}}function x(t,n){let r=new Error(n??t);return r.code=t,r}var C=null;async function Xr(t,n,{port:r=4028,timeoutMs:e=0,connectTimeoutMs:i=0,encoding:o="utf8",signal:s,maxBytes:p=0,halfCloseAfterWrite:d=false,lineTerminator:T=""}={}){if(!(typeof process<"u"&&!!process.versions?.node))throw x("ENODEONLY","connectTCP is Node-only");if(!m(n))throw x("EBADHOST","`host` must be a non-empty string");if(!m(t))throw x("EBADMSG","`message` must be a non-empty string");if(!S(r)||r<1||r>65535)throw x("EBADPORT","`port` must be an integer in range 1..65535");let u=o.toLowerCase()==="utf-8"?"utf8":o;if(!C)try{C=await import('net');}catch{}if(!C)throw x("ENETIMPORT","FATAL: node:net import failed");return new Promise((c,g)=>{let l=new C.Socket,k=false,B=0,y=null,U=()=>{l.destroyed||l.destroy(x("EABORT","Operation cancelled")),N(x("EABORT","Operation cancelled"));},N=(h,P)=>{k||(k=true,l.removeAllListeners(),s&&s.removeEventListener("abort",U),l.destroyed||l.destroy(),y&&clearTimeout(y),h?g(h):c(P??""));};if(s){if(s.aborted)return N(x("EABORT","Operation cancelled"));s.addEventListener("abort",U,{once:true});}S(i)&&(y=setTimeout(()=>N(x("ETIMEDOUT","Connect timed out")),i),y&&Q(y.unref)&&y.unref()),S(e)&&(l.setTimeout(e),l.once("timeout",()=>N(x("ETIMEDOUT","Idle timeout"))));let M=[];l.on("data",h=>{if(k)return;let P=Buffer.isBuffer(h)?h:Buffer.from(h,u);if(S(p)&&B+P.length>p)return N(x("ERESPONSE_TOO_LARGE","Response exceeds maxBytes"));M.push(P),B+=P.length;}),l.once("end",()=>{if(k)return;let h=Buffer.concat(M,B).toString(u);N(void 0,h);}),l.once("close",h=>{if(k)return;let P=Buffer.concat(M,B).toString(u);h?N(x("ECLOSE","Socket closed with error")):N(void 0,P);}),l.once("error",h=>{k||N(h);}),l.once("connect",()=>{y&&(clearTimeout(y),y=null);let h=T?t+T:t;l.write(h,u)?d&&l.end():l.once("drain",()=>{d&&!k&&l.end();});}),l.connect({host:n,port:r});})}
|
|
2
|
+
export{er as changeFixedDecimalScale,G as cidrToRange,j as convertExponentialToParts,Qr as extractHost,q as fixedDecimalToNum,X as fixedDecimalToStr,yt as floorDateToMinutes,St as formatDateToString,dt as formatStrToFuncArgs,J as formatToBool,rt as formatToLowerCase,br as formatToNormalCase,Sr as formatToNull,F as formatToNum,Ir as formatToPhone,b as formatToTrim,$r as formatToUndefined,Bt as ipAddrToNum,O as isArr,V as isArrFilled,$ as isBool,Xt as isDate,rn as isEmail,on as isExists,Q as isFunc,fn as isIpAddr,ln as isMacAddr,a as isNum,hn as isNumFloat,wn as isNumN,_ as isNumNZ,S as isNumP,v as isNumPZ,E as isObj,K as isObjFilled,An as isPassword,Rn as isPhone,f as isStr,Wn as isStrAscDesc,W as isStrBool,m as isStrFilled,Gn as isVar,Z as jsonDecode,nr as jsonEncode,Xr as netTCP,nt as normalizeToDecimalComponents,Mt as numToIpAddr,I as parseIPv4,R as parseStringLike,z as parseToFixedDecimal,Ft as partsToSeconds,H as rangeIPv4,Gt as rangeIPv4ToArr,tt as roundFixedDecimal,Ot as secondsToParts,ht as splitArrToPortions,Cr as toGB,Jr as toGH,Gr as toH,D as toIPv4,Y as tryParseJSON,bt as wait};//# sourceMappingURL=node.mjs.map
|
|
3
|
+
//# sourceMappingURL=node.mjs.map
|