full-utils 1.0.11 → 2.0.1

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.
Files changed (170) hide show
  1. package/README.md +189 -1
  2. package/dist/browser.cjs +3 -0
  3. package/dist/browser.cjs.map +1 -0
  4. package/dist/browser.d.cts +1 -0
  5. package/dist/browser.d.ts +1 -0
  6. package/dist/browser.mjs +3 -0
  7. package/dist/browser.mjs.map +1 -0
  8. package/dist/index.cjs +3 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +4495 -0
  11. package/dist/index.d.ts +4495 -49
  12. package/dist/index.mjs +3 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/node.cjs +3 -0
  15. package/dist/node.cjs.map +1 -0
  16. package/dist/node.d.cts +166 -0
  17. package/dist/node.d.ts +166 -0
  18. package/dist/node.mjs +3 -0
  19. package/dist/node.mjs.map +1 -0
  20. package/package.json +65 -19
  21. package/dist/index.js +0 -100
  22. package/dist/index.js.map +0 -1
  23. package/dist/src/from/fromJSON.d.ts +0 -5
  24. package/dist/src/from/fromJSON.js +0 -71
  25. package/dist/src/from/fromJSON.js.map +0 -1
  26. package/dist/src/from/fromTimestamp.d.ts +0 -6
  27. package/dist/src/from/fromTimestamp.js +0 -8
  28. package/dist/src/from/fromTimestamp.js.map +0 -1
  29. package/dist/src/index.d.ts +0 -49
  30. package/dist/src/index.js +0 -100
  31. package/dist/src/index.js.map +0 -1
  32. package/dist/src/is/isArr.d.ts +0 -1
  33. package/dist/src/is/isArr.js +0 -7
  34. package/dist/src/is/isArr.js.map +0 -1
  35. package/dist/src/is/isArrFilled.d.ts +0 -1
  36. package/dist/src/is/isArrFilled.js +0 -8
  37. package/dist/src/is/isArrFilled.js.map +0 -1
  38. package/dist/src/is/isBool.d.ts +0 -1
  39. package/dist/src/is/isBool.js +0 -7
  40. package/dist/src/is/isBool.js.map +0 -1
  41. package/dist/src/is/isDate.d.ts +0 -1
  42. package/dist/src/is/isDate.js +0 -16
  43. package/dist/src/is/isDate.js.map +0 -1
  44. package/dist/src/is/isEmail.d.ts +0 -1
  45. package/dist/src/is/isEmail.js +0 -9
  46. package/dist/src/is/isEmail.js.map +0 -1
  47. package/dist/src/is/isExists.d.ts +0 -1
  48. package/dist/src/is/isExists.js +0 -7
  49. package/dist/src/is/isExists.js.map +0 -1
  50. package/dist/src/is/isFunc.d.ts +0 -1
  51. package/dist/src/is/isFunc.js +0 -7
  52. package/dist/src/is/isFunc.js.map +0 -1
  53. package/dist/src/is/isIp.d.ts +0 -1
  54. package/dist/src/is/isIp.js +0 -13
  55. package/dist/src/is/isIp.js.map +0 -1
  56. package/dist/src/is/isMac.d.ts +0 -1
  57. package/dist/src/is/isMac.js +0 -8
  58. package/dist/src/is/isMac.js.map +0 -1
  59. package/dist/src/is/isNum.d.ts +0 -1
  60. package/dist/src/is/isNum.js +0 -7
  61. package/dist/src/is/isNum.js.map +0 -1
  62. package/dist/src/is/isNumFloat.d.ts +0 -1
  63. package/dist/src/is/isNumFloat.js +0 -8
  64. package/dist/src/is/isNumFloat.js.map +0 -1
  65. package/dist/src/is/isNumN.d.ts +0 -1
  66. package/dist/src/is/isNumN.js +0 -8
  67. package/dist/src/is/isNumN.js.map +0 -1
  68. package/dist/src/is/isNumNZ.d.ts +0 -1
  69. package/dist/src/is/isNumNZ.js +0 -8
  70. package/dist/src/is/isNumNZ.js.map +0 -1
  71. package/dist/src/is/isNumP.d.ts +0 -1
  72. package/dist/src/is/isNumP.js +0 -8
  73. package/dist/src/is/isNumP.js.map +0 -1
  74. package/dist/src/is/isNumPZ.d.ts +0 -1
  75. package/dist/src/is/isNumPZ.js +0 -8
  76. package/dist/src/is/isNumPZ.js.map +0 -1
  77. package/dist/src/is/isObj.d.ts +0 -1
  78. package/dist/src/is/isObj.js +0 -10
  79. package/dist/src/is/isObj.js.map +0 -1
  80. package/dist/src/is/isObjFilled.d.ts +0 -1
  81. package/dist/src/is/isObjFilled.js +0 -8
  82. package/dist/src/is/isObjFilled.js.map +0 -1
  83. package/dist/src/is/isPassword.d.ts +0 -10
  84. package/dist/src/is/isPassword.js +0 -26
  85. package/dist/src/is/isPassword.js.map +0 -1
  86. package/dist/src/is/isPhone.d.ts +0 -1
  87. package/dist/src/is/isPhone.js +0 -35
  88. package/dist/src/is/isPhone.js.map +0 -1
  89. package/dist/src/is/isStr.d.ts +0 -1
  90. package/dist/src/is/isStr.js +0 -7
  91. package/dist/src/is/isStr.js.map +0 -1
  92. package/dist/src/is/isStrBool.d.ts +0 -1
  93. package/dist/src/is/isStrBool.js +0 -12
  94. package/dist/src/is/isStrBool.js.map +0 -1
  95. package/dist/src/is/isStrFilled.d.ts +0 -1
  96. package/dist/src/is/isStrFilled.js +0 -8
  97. package/dist/src/is/isStrFilled.js.map +0 -1
  98. package/dist/src/is/isStrOrderType.d.ts +0 -1
  99. package/dist/src/is/isStrOrderType.js +0 -12
  100. package/dist/src/is/isStrOrderType.js.map +0 -1
  101. package/dist/src/is/isVar.d.ts +0 -1
  102. package/dist/src/is/isVar.js +0 -8
  103. package/dist/src/is/isVar.js.map +0 -1
  104. package/dist/src/net/netTCP.d.ts +0 -6
  105. package/dist/src/net/netTCP.js +0 -52
  106. package/dist/src/net/netTCP.js.map +0 -1
  107. package/dist/src/to/toArrFuncArgs.d.ts +0 -1
  108. package/dist/src/to/toArrFuncArgs.js +0 -139
  109. package/dist/src/to/toArrFuncArgs.js.map +0 -1
  110. package/dist/src/to/toBool.d.ts +0 -1
  111. package/dist/src/to/toBool.js +0 -23
  112. package/dist/src/to/toBool.js.map +0 -1
  113. package/dist/src/to/toCellDate.d.ts +0 -1
  114. package/dist/src/to/toCellDate.js +0 -12
  115. package/dist/src/to/toCellDate.js.map +0 -1
  116. package/dist/src/to/toDateStr.d.ts +0 -1
  117. package/dist/src/to/toDateStr.js +0 -14
  118. package/dist/src/to/toDateStr.js.map +0 -1
  119. package/dist/src/to/toGB.d.ts +0 -1
  120. package/dist/src/to/toGB.js +0 -47
  121. package/dist/src/to/toGB.js.map +0 -1
  122. package/dist/src/to/toGH.d.ts +0 -1
  123. package/dist/src/to/toGH.js +0 -36
  124. package/dist/src/to/toGH.js.map +0 -1
  125. package/dist/src/to/toH.d.ts +0 -1
  126. package/dist/src/to/toH.js +0 -36
  127. package/dist/src/to/toH.js.map +0 -1
  128. package/dist/src/to/toInetAton.d.ts +0 -1
  129. package/dist/src/to/toInetAton.js +0 -18
  130. package/dist/src/to/toInetAton.js.map +0 -1
  131. package/dist/src/to/toInetNtoa.d.ts +0 -1
  132. package/dist/src/to/toInetNtoa.js +0 -16
  133. package/dist/src/to/toInetNtoa.js.map +0 -1
  134. package/dist/src/to/toJSON.d.ts +0 -1
  135. package/dist/src/to/toJSON.js +0 -14
  136. package/dist/src/to/toJSON.js.map +0 -1
  137. package/dist/src/to/toLower.d.ts +0 -1
  138. package/dist/src/to/toLower.js +0 -14
  139. package/dist/src/to/toLower.js.map +0 -1
  140. package/dist/src/to/toNull.d.ts +0 -1
  141. package/dist/src/to/toNull.js +0 -11
  142. package/dist/src/to/toNull.js.map +0 -1
  143. package/dist/src/to/toNum.d.ts +0 -1
  144. package/dist/src/to/toNum.js +0 -40
  145. package/dist/src/to/toNum.js.map +0 -1
  146. package/dist/src/to/toPhone.d.ts +0 -1
  147. package/dist/src/to/toPhone.js +0 -24
  148. package/dist/src/to/toPhone.js.map +0 -1
  149. package/dist/src/to/toPoolName.d.ts +0 -1
  150. package/dist/src/to/toPoolName.js +0 -19
  151. package/dist/src/to/toPoolName.js.map +0 -1
  152. package/dist/src/to/toPortions.d.ts +0 -1
  153. package/dist/src/to/toPortions.js +0 -16
  154. package/dist/src/to/toPortions.js.map +0 -1
  155. package/dist/src/to/toRangeip.d.ts +0 -1
  156. package/dist/src/to/toRangeip.js +0 -24
  157. package/dist/src/to/toRangeip.js.map +0 -1
  158. package/dist/src/to/toSqlUpdateMany.d.ts +0 -1
  159. package/dist/src/to/toSqlUpdateMany.js +0 -39
  160. package/dist/src/to/toSqlUpdateMany.js.map +0 -1
  161. package/dist/src/to/toTimestamp.d.ts +0 -6
  162. package/dist/src/to/toTimestamp.js +0 -11
  163. package/dist/src/to/toTimestamp.js.map +0 -1
  164. package/dist/src/to/toTrim.d.ts +0 -1
  165. package/dist/src/to/toTrim.js +0 -10
  166. package/dist/src/to/toTrim.js.map +0 -1
  167. package/dist/src/to/toUndefined.d.ts +0 -1
  168. package/dist/src/to/toUndefined.js +0 -11
  169. package/dist/src/to/toUndefined.js.map +0 -1
  170. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -0,0 +1,166 @@
1
+ export { FixedDecimal, JSONLike, PasswordOptions, RangeIPv4Options, TimeParts, changeFixedDecimalScale, cidrToRange, convertExponentialToParts, extractHost, fixedDecimalToNum, fixedDecimalToStr, floorDateToMinutes, formatDateToString, formatStrToFuncArgs, formatToBool, formatToLowerCase, 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, 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 pt(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 U(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 gt(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 U(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 wt(t=0){await new Promise(n=>setTimeout(()=>n(true),t));}function kt(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 Nt(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 Pt(t){let{days:n=0,hours:r=0,minutes:e=0,seconds:i=0}=t;return n*86400+r*3600+e*60+i}function It(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 At(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 _t(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 qt(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 it=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z]{2,})+$/;function nn(t){return m(t)?it.test(t):false}function en(t){return t!=null}function Q(t){return typeof t=="function"}var ot=/^(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 cn(t){if(!f(t))return false;let n=t.trim();return ot.test(n)}function mn(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 gn(t){return a(t)&&!Number.isInteger(t)}function Tn(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 Dn(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 $n(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 Un(t){if(!m(t))return false;let n=t.trim().toLowerCase();return n==="asc"||n==="desc"}function _n(t){return f(t)&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(t)}var st=/^(['"`])([\s\S]*)\1$/;function R(t,n){let r=t.trim(),e=Y(r);if(e.ok)return e.value;let i=st.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 tr(t){try{return E(t)||O(t)?JSON.stringify(t):""}catch{}return ""}function rr(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 xr(t){if(!f(t))return "";let n=b(t);return m(n)?n.toLowerCase():""}function kr(t){return f(t)&&b(t)===""||t===void 0?null:t}function Sr(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 Dr(t){return f(t)&&b(t)===""||t===null?void 0:t}var ut=1024,rt=ut*1024,A=rt*1024,et=A*1024,ct=et*1024;function $r(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/rt;break;case "m":o=r/A;break;case "g":o=r;break;case "t":o=r*(et/A);break;case "p":o=r*(ct/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 ft={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=ft[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 at={h:1,k:1e3,m:1e6,g:1e9,t:1e12,p:1e15,e:1e18};function Wr(t,n=""){let r=F(t);if(!a(r))return 0;let e=L(n),i=e?e[0]:"h",o=at[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 mt=/^[a-zA-Z][a-zA-Z\d+\-.]*:/;function Gr(t=""){if(!m(t))return "";let n=t.trim(),r=mt.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 M=null;async function Kr(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(!M)try{M=await import('net');}catch{}if(!M)throw x("ENETIMPORT","FATAL: node:net import failed");return new Promise((c,g)=>{let l=new M.Socket,k=false,B=0,y=null,J=()=>{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",J),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",J,{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 C=[];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"));C.push(P),B+=P.length;}),l.once("end",()=>{if(k)return;let h=Buffer.concat(C,B).toString(u);N(void 0,h);}),l.once("close",h=>{if(k)return;let P=Buffer.concat(C,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{rr as changeFixedDecimalScale,G as cidrToRange,j as convertExponentialToParts,Gr as extractHost,q as fixedDecimalToNum,X as fixedDecimalToStr,kt as floorDateToMinutes,Nt as formatDateToString,pt as formatStrToFuncArgs,U as formatToBool,xr as formatToLowerCase,kr as formatToNull,F as formatToNum,Sr as formatToPhone,b as formatToTrim,Dr as formatToUndefined,At as ipAddrToNum,O as isArr,V as isArrFilled,$ as isBool,qt as isDate,nn as isEmail,en as isExists,Q as isFunc,cn as isIpAddr,mn as isMacAddr,a as isNum,gn as isNumFloat,Tn as isNumN,_ as isNumNZ,S as isNumP,v as isNumPZ,E as isObj,K as isObjFilled,Dn as isPassword,$n as isPhone,f as isStr,Un as isStrAscDesc,W as isStrBool,m as isStrFilled,_n as isVar,Z as jsonDecode,tr as jsonEncode,Kr as netTCP,nt as normalizeToDecimalComponents,Mt as numToIpAddr,I as parseIPv4,R as parseStringLike,z as parseToFixedDecimal,Pt as partsToSeconds,H as rangeIPv4,_t as rangeIPv4ToArr,tt as roundFixedDecimal,It as secondsToParts,gt as splitArrToPortions,$r as toGB,jr as toGH,Wr as toH,D as toIPv4,Y as tryParseJSON,wt as wait};//# sourceMappingURL=node.mjs.map
3
+ //# sourceMappingURL=node.mjs.map