@utilix-tech/sdk 0.3.1 → 0.4.0
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 +18 -6
- package/dist/{chunk-UC656APA.js → chunk-DNCOIO5N.js} +64 -1
- package/dist/{chunk-3BAHSW4C.js → chunk-V5JKVDBA.js} +60 -1
- package/dist/{data-rMjWNiOJ.d.cts → data-CakDxAcT.d.cts} +36 -2
- package/dist/{data-rMjWNiOJ.d.ts → data-CakDxAcT.d.ts} +36 -2
- package/dist/index.cjs +122 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{network-CNtmrDeN.d.cts → network-DwyAjwJS.d.cts} +39 -2
- package/dist/{network-CNtmrDeN.d.ts → network-DwyAjwJS.d.ts} +39 -2
- package/dist/tools/data.cjs +63 -0
- package/dist/tools/data.d.cts +1 -1
- package/dist/tools/data.d.ts +1 -1
- package/dist/tools/data.js +1 -1
- package/dist/tools/network.cjs +59 -0
- package/dist/tools/network.d.cts +1 -1
- package/dist/tools/network.d.ts +1 -1
- package/dist/tools/network.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,11 +152,12 @@ detectPassiveVoice("The report was reviewed by the committee. They approved it."
|
|
|
152
152
|
|
|
153
153
|
---
|
|
154
154
|
|
|
155
|
-
### `/data`: CSV / YAML / TOML / XML / INI
|
|
155
|
+
### `/data`: CSV / YAML / TOML / XML / INI / NDJSON
|
|
156
156
|
|
|
157
157
|
```ts
|
|
158
158
|
import { parseCsv, csvToJson, validateYaml, tomlToJson, jsonToToml,
|
|
159
|
-
formatXml, xmlToJson, jsonToXml, parseIni
|
|
159
|
+
formatXml, xmlToJson, jsonToXml, parseIni,
|
|
160
|
+
validateNdjson, formatNdjson, ndjsonToJsonArray } from "@utilix-tech/sdk/data";
|
|
160
161
|
|
|
161
162
|
// CSV
|
|
162
163
|
const rows = parseCsv("name,age\nalice,30\nbob,25");
|
|
@@ -175,6 +176,11 @@ xmlToJson("<root><item>hello</item></root>");
|
|
|
175
176
|
|
|
176
177
|
// INI
|
|
177
178
|
parseIni("[db]\nhost=localhost\nport=5432");
|
|
179
|
+
|
|
180
|
+
// NDJSON (JSON Lines): one JSON value per line
|
|
181
|
+
validateNdjson('{"id":1}\n{"id":2}'); // { valid: true, totalLines: 2, ... }
|
|
182
|
+
formatNdjson('{"id":1}'); // '{\n "id": 1\n}'
|
|
183
|
+
ndjsonToJsonArray('{"id":1}\n{"id":2}'); // '[\n { "id": 1 },\n { "id": 2 }\n]'
|
|
178
184
|
```
|
|
179
185
|
|
|
180
186
|
---
|
|
@@ -250,11 +256,12 @@ formatValue(1234567.89, { locale: "en-US", currency: "USD" });
|
|
|
250
256
|
|
|
251
257
|
---
|
|
252
258
|
|
|
253
|
-
### `/network`: URLs, IPs, HTTP
|
|
259
|
+
### `/network`: URLs, IPs, HTTP, HAR
|
|
254
260
|
|
|
255
261
|
```ts
|
|
256
262
|
import { getStatusCode, isValidIp, isValidIpv4, isValidIpv6,
|
|
257
|
-
searchStatusCodes, buildGeoUrl, countryCodeToFlag
|
|
263
|
+
searchStatusCodes, buildGeoUrl, countryCodeToFlag,
|
|
264
|
+
parseHar } from "@utilix-tech/sdk/network";
|
|
258
265
|
|
|
259
266
|
getStatusCode(404);
|
|
260
267
|
// { code: 404, text: "Not Found", description: "...", category: "Client Error" }
|
|
@@ -266,6 +273,11 @@ isValidIpv6("::1"); // true
|
|
|
266
273
|
isValidIp("256.0.0.1"); // false
|
|
267
274
|
|
|
268
275
|
countryCodeToFlag("US"); // "🇺🇸"
|
|
276
|
+
|
|
277
|
+
// Parse a DevTools .har network export into entries + summary stats
|
|
278
|
+
const har = await fs.promises.readFile("network.har", "utf-8");
|
|
279
|
+
parseHar(har);
|
|
280
|
+
// { version: "1.2", entries: [...], summary: { totalRequests, totalSize, failedRequests, ... } }
|
|
269
281
|
```
|
|
270
282
|
|
|
271
283
|
---
|
|
@@ -424,11 +436,11 @@ Supports PNG, JPEG, GIF, WebP, and BMP.
|
|
|
424
436
|
| `@utilix-tech/sdk/encoding` | Base64, URL, HTML entities, Base32 encode/decode |
|
|
425
437
|
| `@utilix-tech/sdk/hashing` | MD5, SHA-1/256/512, bcrypt, HMAC, .htpasswd |
|
|
426
438
|
| `@utilix-tech/sdk/text` | Case convert, slugify, word count, lorem ipsum, line ops, HTML→Markdown |
|
|
427
|
-
| `@utilix-tech/sdk/data` | CSV, YAML, TOML, XML, INI parse and convert |
|
|
439
|
+
| `@utilix-tech/sdk/data` | CSV, YAML, TOML, XML, INI, NDJSON parse and convert |
|
|
428
440
|
| `@utilix-tech/sdk/generators` | UUID v4/v7, ULID, passwords, strength check, fake data |
|
|
429
441
|
| `@utilix-tech/sdk/time` | Date diff, timezone convert, cron parse, relative time |
|
|
430
442
|
| `@utilix-tech/sdk/units` | Bytes, CSS px/rem, number bases, currency format |
|
|
431
|
-
| `@utilix-tech/sdk/network` | HTTP status codes, IP validation, country flags, geolocation URLs |
|
|
443
|
+
| `@utilix-tech/sdk/network` | HTTP status codes, IP validation, country flags, geolocation URLs, HAR file parsing |
|
|
432
444
|
| `@utilix-tech/sdk/api` | cURL build/parse, JWT decode/sign, CORS headers, CSP header |
|
|
433
445
|
| `@utilix-tech/sdk/code` | SQL format/minify, HTML format/minify, regex tester, GraphQL format |
|
|
434
446
|
| `@utilix-tech/sdk/color` | Hex/RGB/HSL/HSV/CMYK convert, palette generation, contrast check |
|
|
@@ -9,6 +9,7 @@ __export(data_exports, {
|
|
|
9
9
|
detectDelimiter: () => detectDelimiter,
|
|
10
10
|
envToExport: () => envToExport,
|
|
11
11
|
envToJson: () => envToJson,
|
|
12
|
+
formatNdjson: () => formatNdjson,
|
|
12
13
|
formatToml: () => formatToml,
|
|
13
14
|
formatXml: () => formatXml,
|
|
14
15
|
getSection: () => getSection,
|
|
@@ -17,11 +18,14 @@ __export(data_exports, {
|
|
|
17
18
|
getXmlStats: () => getXmlStats,
|
|
18
19
|
getYamlStats: () => getYamlStats,
|
|
19
20
|
iniToJson: () => iniToJson,
|
|
21
|
+
jsonArrayToNdjson: () => jsonArrayToNdjson,
|
|
20
22
|
jsonToIni: () => jsonToIni,
|
|
21
23
|
jsonToToml: () => jsonToToml,
|
|
22
24
|
jsonToXml: () => jsonToXml,
|
|
25
|
+
minifyNdjson: () => minifyNdjson,
|
|
23
26
|
minifyToml: () => minifyToml,
|
|
24
27
|
minifyXml: () => minifyXml,
|
|
28
|
+
ndjsonToJsonArray: () => ndjsonToJsonArray,
|
|
25
29
|
parseCsv: () => parseCsv,
|
|
26
30
|
parseEnv: () => parseEnv,
|
|
27
31
|
parseIni: () => parseIni,
|
|
@@ -31,6 +35,7 @@ __export(data_exports, {
|
|
|
31
35
|
tomlToJson: () => tomlToJson,
|
|
32
36
|
validateEnvKey: () => validateEnvKey,
|
|
33
37
|
validateIni: () => validateIni,
|
|
38
|
+
validateNdjson: () => validateNdjson,
|
|
34
39
|
validateToml: () => validateToml,
|
|
35
40
|
validateXml: () => validateXml,
|
|
36
41
|
validateYaml: () => validateYaml,
|
|
@@ -1076,5 +1081,63 @@ function envToExport(input) {
|
|
|
1076
1081
|
function validateEnvKey(key) {
|
|
1077
1082
|
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(key);
|
|
1078
1083
|
}
|
|
1084
|
+
function validateNdjson(input) {
|
|
1085
|
+
const rawLines = input.split("\n");
|
|
1086
|
+
const lines = [];
|
|
1087
|
+
let validCount = 0;
|
|
1088
|
+
rawLines.forEach((raw, idx) => {
|
|
1089
|
+
if (raw.trim() === "") return;
|
|
1090
|
+
const lineNum = idx + 1;
|
|
1091
|
+
try {
|
|
1092
|
+
JSON.parse(raw);
|
|
1093
|
+
lines.push({ line: lineNum, raw, valid: true });
|
|
1094
|
+
validCount++;
|
|
1095
|
+
} catch (e) {
|
|
1096
|
+
lines.push({
|
|
1097
|
+
line: lineNum,
|
|
1098
|
+
raw,
|
|
1099
|
+
valid: false,
|
|
1100
|
+
error: e instanceof Error ? e.message : String(e)
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1104
|
+
return {
|
|
1105
|
+
valid: lines.length > 0 && validCount === lines.length,
|
|
1106
|
+
totalLines: lines.length,
|
|
1107
|
+
validLines: validCount,
|
|
1108
|
+
invalidLines: lines.length - validCount,
|
|
1109
|
+
lines
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
function _firstNdjsonError(result) {
|
|
1113
|
+
const firstError = result.lines.find((l) => !l.valid);
|
|
1114
|
+
return firstError ? `Line ${firstError.line}: ${firstError.error}` : "Invalid NDJSON";
|
|
1115
|
+
}
|
|
1116
|
+
function minifyNdjson(input) {
|
|
1117
|
+
const result = validateNdjson(input);
|
|
1118
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
1119
|
+
return result.lines.map((l) => JSON.stringify(JSON.parse(l.raw))).join("\n");
|
|
1120
|
+
}
|
|
1121
|
+
function formatNdjson(input, indent = 2) {
|
|
1122
|
+
const result = validateNdjson(input);
|
|
1123
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
1124
|
+
return result.lines.map((l) => JSON.stringify(JSON.parse(l.raw), null, indent)).join("\n");
|
|
1125
|
+
}
|
|
1126
|
+
function ndjsonToJsonArray(input) {
|
|
1127
|
+
const result = validateNdjson(input);
|
|
1128
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
1129
|
+
const values = result.lines.map((l) => JSON.parse(l.raw));
|
|
1130
|
+
return JSON.stringify(values, null, 2);
|
|
1131
|
+
}
|
|
1132
|
+
function jsonArrayToNdjson(input) {
|
|
1133
|
+
let parsed;
|
|
1134
|
+
try {
|
|
1135
|
+
parsed = JSON.parse(input);
|
|
1136
|
+
} catch (e) {
|
|
1137
|
+
return { error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
1138
|
+
}
|
|
1139
|
+
if (!Array.isArray(parsed)) return { error: "Input must be a JSON array" };
|
|
1140
|
+
return parsed.map((item) => JSON.stringify(item)).join("\n");
|
|
1141
|
+
}
|
|
1079
1142
|
|
|
1080
|
-
export { csvToJson, data_exports, detectDelimiter, envToExport, envToJson, formatToml, formatXml, getSection, getSectionNames, getTomlStats, getXmlStats, getYamlStats, iniToJson, jsonToIni, jsonToToml, jsonToXml, minifyToml, minifyXml, parseCsv, parseEnv, parseIni, parseXmlToObject, stringifyIni, toCsvString, tomlToJson, validateEnvKey, validateIni, validateToml, validateXml, validateYaml, xmlToJson };
|
|
1143
|
+
export { csvToJson, data_exports, detectDelimiter, envToExport, envToJson, formatNdjson, formatToml, formatXml, getSection, getSectionNames, getTomlStats, getXmlStats, getYamlStats, iniToJson, jsonArrayToNdjson, jsonToIni, jsonToToml, jsonToXml, minifyNdjson, minifyToml, minifyXml, ndjsonToJsonArray, parseCsv, parseEnv, parseIni, parseXmlToObject, stringifyIni, toCsvString, tomlToJson, validateEnvKey, validateIni, validateNdjson, validateToml, validateXml, validateYaml, xmlToJson };
|
|
@@ -25,6 +25,7 @@ __export(network_exports, {
|
|
|
25
25
|
isValidIpv6: () => isValidIpv6,
|
|
26
26
|
parseDnsResponse: () => parseDnsResponse,
|
|
27
27
|
parseGeoResponse: () => parseGeoResponse,
|
|
28
|
+
parseHar: () => parseHar,
|
|
28
29
|
searchHeaders: () => searchHeaders,
|
|
29
30
|
searchStatusCodes: () => searchStatusCodes,
|
|
30
31
|
statusCodeToText: () => statusCodeToText,
|
|
@@ -1381,5 +1382,63 @@ function validateHeaderValue(name, value) {
|
|
|
1381
1382
|
}
|
|
1382
1383
|
return { valid: true };
|
|
1383
1384
|
}
|
|
1385
|
+
function parseHar(input) {
|
|
1386
|
+
if (!input || !input.trim()) {
|
|
1387
|
+
return { error: "Input is empty" };
|
|
1388
|
+
}
|
|
1389
|
+
let data;
|
|
1390
|
+
try {
|
|
1391
|
+
data = JSON.parse(input);
|
|
1392
|
+
} catch (e) {
|
|
1393
|
+
return { error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
1394
|
+
}
|
|
1395
|
+
if (typeof data !== "object" || data === null || !("log" in data)) {
|
|
1396
|
+
return { error: 'Not a valid HAR file: missing "log" property' };
|
|
1397
|
+
}
|
|
1398
|
+
const log = data.log;
|
|
1399
|
+
if (typeof log !== "object" || log === null || !Array.isArray(log.entries)) {
|
|
1400
|
+
return { error: 'Not a valid HAR file: "log.entries" must be an array' };
|
|
1401
|
+
}
|
|
1402
|
+
const logObj = log;
|
|
1403
|
+
const entries = [];
|
|
1404
|
+
const methods = {};
|
|
1405
|
+
const statusCodes = {};
|
|
1406
|
+
let totalSize = 0;
|
|
1407
|
+
let totalTime = 0;
|
|
1408
|
+
let failedRequests = 0;
|
|
1409
|
+
for (const raw of logObj.entries) {
|
|
1410
|
+
if (typeof raw !== "object" || raw === null) continue;
|
|
1411
|
+
const e = raw;
|
|
1412
|
+
const request = e.request ?? {};
|
|
1413
|
+
const response = e.response ?? {};
|
|
1414
|
+
const content = response.content ?? {};
|
|
1415
|
+
const method = typeof request.method === "string" ? request.method : "GET";
|
|
1416
|
+
const url = typeof request.url === "string" ? request.url : "";
|
|
1417
|
+
const status = typeof response.status === "number" ? response.status : 0;
|
|
1418
|
+
const statusText = typeof response.statusText === "string" ? response.statusText : "";
|
|
1419
|
+
const httpVersion = typeof response.httpVersion === "string" ? response.httpVersion : "";
|
|
1420
|
+
const mimeType = typeof content.mimeType === "string" ? content.mimeType : "";
|
|
1421
|
+
const size = typeof content.size === "number" && content.size > 0 ? content.size : 0;
|
|
1422
|
+
const time = typeof e.time === "number" ? e.time : 0;
|
|
1423
|
+
const startedDateTime = typeof e.startedDateTime === "string" ? e.startedDateTime : "";
|
|
1424
|
+
entries.push({ method, url, status, statusText, httpVersion, mimeType, size, time, startedDateTime });
|
|
1425
|
+
methods[method] = (methods[method] ?? 0) + 1;
|
|
1426
|
+
if (status > 0) statusCodes[String(status)] = (statusCodes[String(status)] ?? 0) + 1;
|
|
1427
|
+
totalSize += size;
|
|
1428
|
+
totalTime += time;
|
|
1429
|
+
if (status === 0 || status >= 400) failedRequests++;
|
|
1430
|
+
}
|
|
1431
|
+
const totalRequests = entries.length;
|
|
1432
|
+
const avgTime = totalRequests > 0 ? Math.round(totalTime / totalRequests * 100) / 100 : 0;
|
|
1433
|
+
return {
|
|
1434
|
+
version: typeof logObj.version === "string" ? logObj.version : "",
|
|
1435
|
+
creator: {
|
|
1436
|
+
name: typeof logObj.creator?.name === "string" ? logObj.creator.name : "",
|
|
1437
|
+
version: typeof logObj.creator?.version === "string" ? logObj.creator.version : ""
|
|
1438
|
+
},
|
|
1439
|
+
entries,
|
|
1440
|
+
summary: { totalRequests, totalSize, totalTime, avgTime, failedRequests, methods, statusCodes }
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1384
1443
|
|
|
1385
|
-
export { DNS_RECORD_TYPES, HTTP_HEADERS, STATUS_CODES, buildDnsQueryUrl, buildGeoUrl, buildMapUrl, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, network_exports, parseDnsResponse, parseGeoResponse, searchHeaders, searchStatusCodes, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue };
|
|
1444
|
+
export { DNS_RECORD_TYPES, HTTP_HEADERS, STATUS_CODES, buildDnsQueryUrl, buildGeoUrl, buildMapUrl, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, network_exports, parseDnsResponse, parseGeoResponse, parseHar, searchHeaders, searchStatusCodes, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue };
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* - csv-viewer : detectDelimiter, parseCsv, csvToJson, toCsvString
|
|
11
11
|
* - ini-parser : parseIni, stringifyIni, iniToJson, jsonToIni, getSection, getSectionNames, validateIni
|
|
12
12
|
* - env-parser : parseEnv, envToJson, envToExport, validateEnvKey
|
|
13
|
+
* - ndjson-formatter: validateNdjson, minifyNdjson, formatNdjson, ndjsonToJsonArray, jsonArrayToNdjson
|
|
13
14
|
*/
|
|
14
15
|
interface ValidationResult {
|
|
15
16
|
valid: boolean;
|
|
@@ -167,11 +168,39 @@ declare function envToJson(input: string): string | {
|
|
|
167
168
|
};
|
|
168
169
|
declare function envToExport(input: string): string;
|
|
169
170
|
declare function validateEnvKey(key: string): boolean;
|
|
171
|
+
interface NdjsonLineResult {
|
|
172
|
+
line: number;
|
|
173
|
+
raw: string;
|
|
174
|
+
valid: boolean;
|
|
175
|
+
error?: string;
|
|
176
|
+
}
|
|
177
|
+
interface NdjsonValidateResult {
|
|
178
|
+
valid: boolean;
|
|
179
|
+
totalLines: number;
|
|
180
|
+
validLines: number;
|
|
181
|
+
invalidLines: number;
|
|
182
|
+
lines: NdjsonLineResult[];
|
|
183
|
+
}
|
|
184
|
+
declare function validateNdjson(input: string): NdjsonValidateResult;
|
|
185
|
+
declare function minifyNdjson(input: string): string | {
|
|
186
|
+
error: string;
|
|
187
|
+
};
|
|
188
|
+
declare function formatNdjson(input: string, indent?: number): string | {
|
|
189
|
+
error: string;
|
|
190
|
+
};
|
|
191
|
+
declare function ndjsonToJsonArray(input: string): string | {
|
|
192
|
+
error: string;
|
|
193
|
+
};
|
|
194
|
+
declare function jsonArrayToNdjson(input: string): string | {
|
|
195
|
+
error: string;
|
|
196
|
+
};
|
|
170
197
|
|
|
171
198
|
type data_CsvParseResult = CsvParseResult;
|
|
172
199
|
type data_EnvEntry = EnvEntry;
|
|
173
200
|
type data_EnvParseResult = EnvParseResult;
|
|
174
201
|
type data_IniSection = IniSection;
|
|
202
|
+
type data_NdjsonLineResult = NdjsonLineResult;
|
|
203
|
+
type data_NdjsonValidateResult = NdjsonValidateResult;
|
|
175
204
|
type data_ParseOptions = ParseOptions;
|
|
176
205
|
type data_ParsedIni = ParsedIni;
|
|
177
206
|
type data_TomlFormatResult = TomlFormatResult;
|
|
@@ -182,6 +211,7 @@ declare const data_csvToJson: typeof csvToJson;
|
|
|
182
211
|
declare const data_detectDelimiter: typeof detectDelimiter;
|
|
183
212
|
declare const data_envToExport: typeof envToExport;
|
|
184
213
|
declare const data_envToJson: typeof envToJson;
|
|
214
|
+
declare const data_formatNdjson: typeof formatNdjson;
|
|
185
215
|
declare const data_formatToml: typeof formatToml;
|
|
186
216
|
declare const data_formatXml: typeof formatXml;
|
|
187
217
|
declare const data_getSection: typeof getSection;
|
|
@@ -190,11 +220,14 @@ declare const data_getTomlStats: typeof getTomlStats;
|
|
|
190
220
|
declare const data_getXmlStats: typeof getXmlStats;
|
|
191
221
|
declare const data_getYamlStats: typeof getYamlStats;
|
|
192
222
|
declare const data_iniToJson: typeof iniToJson;
|
|
223
|
+
declare const data_jsonArrayToNdjson: typeof jsonArrayToNdjson;
|
|
193
224
|
declare const data_jsonToIni: typeof jsonToIni;
|
|
194
225
|
declare const data_jsonToToml: typeof jsonToToml;
|
|
195
226
|
declare const data_jsonToXml: typeof jsonToXml;
|
|
227
|
+
declare const data_minifyNdjson: typeof minifyNdjson;
|
|
196
228
|
declare const data_minifyToml: typeof minifyToml;
|
|
197
229
|
declare const data_minifyXml: typeof minifyXml;
|
|
230
|
+
declare const data_ndjsonToJsonArray: typeof ndjsonToJsonArray;
|
|
198
231
|
declare const data_parseCsv: typeof parseCsv;
|
|
199
232
|
declare const data_parseEnv: typeof parseEnv;
|
|
200
233
|
declare const data_parseIni: typeof parseIni;
|
|
@@ -204,12 +237,13 @@ declare const data_toCsvString: typeof toCsvString;
|
|
|
204
237
|
declare const data_tomlToJson: typeof tomlToJson;
|
|
205
238
|
declare const data_validateEnvKey: typeof validateEnvKey;
|
|
206
239
|
declare const data_validateIni: typeof validateIni;
|
|
240
|
+
declare const data_validateNdjson: typeof validateNdjson;
|
|
207
241
|
declare const data_validateToml: typeof validateToml;
|
|
208
242
|
declare const data_validateXml: typeof validateXml;
|
|
209
243
|
declare const data_validateYaml: typeof validateYaml;
|
|
210
244
|
declare const data_xmlToJson: typeof xmlToJson;
|
|
211
245
|
declare namespace data {
|
|
212
|
-
export { type data_CsvParseResult as CsvParseResult, type data_EnvEntry as EnvEntry, type data_EnvParseResult as EnvParseResult, type data_IniSection as IniSection, type data_ParseOptions as ParseOptions, type data_ParsedIni as ParsedIni, type data_TomlFormatResult as TomlFormatResult, type data_ValidationResult as ValidationResult, type data_XmlFormatResult as XmlFormatResult, type data_XmlToJsonOptions as XmlToJsonOptions, data_csvToJson as csvToJson, data_detectDelimiter as detectDelimiter, data_envToExport as envToExport, data_envToJson as envToJson, data_formatToml as formatToml, data_formatXml as formatXml, data_getSection as getSection, data_getSectionNames as getSectionNames, data_getTomlStats as getTomlStats, data_getXmlStats as getXmlStats, data_getYamlStats as getYamlStats, data_iniToJson as iniToJson, data_jsonToIni as jsonToIni, data_jsonToToml as jsonToToml, data_jsonToXml as jsonToXml, data_minifyToml as minifyToml, data_minifyXml as minifyXml, data_parseCsv as parseCsv, data_parseEnv as parseEnv, data_parseIni as parseIni, data_parseXmlToObject as parseXmlToObject, data_stringifyIni as stringifyIni, data_toCsvString as toCsvString, data_tomlToJson as tomlToJson, data_validateEnvKey as validateEnvKey, data_validateIni as validateIni, data_validateToml as validateToml, data_validateXml as validateXml, data_validateYaml as validateYaml, data_xmlToJson as xmlToJson };
|
|
246
|
+
export { type data_CsvParseResult as CsvParseResult, type data_EnvEntry as EnvEntry, type data_EnvParseResult as EnvParseResult, type data_IniSection as IniSection, type data_NdjsonLineResult as NdjsonLineResult, type data_NdjsonValidateResult as NdjsonValidateResult, type data_ParseOptions as ParseOptions, type data_ParsedIni as ParsedIni, type data_TomlFormatResult as TomlFormatResult, type data_ValidationResult as ValidationResult, type data_XmlFormatResult as XmlFormatResult, type data_XmlToJsonOptions as XmlToJsonOptions, data_csvToJson as csvToJson, data_detectDelimiter as detectDelimiter, data_envToExport as envToExport, data_envToJson as envToJson, data_formatNdjson as formatNdjson, data_formatToml as formatToml, data_formatXml as formatXml, data_getSection as getSection, data_getSectionNames as getSectionNames, data_getTomlStats as getTomlStats, data_getXmlStats as getXmlStats, data_getYamlStats as getYamlStats, data_iniToJson as iniToJson, data_jsonArrayToNdjson as jsonArrayToNdjson, data_jsonToIni as jsonToIni, data_jsonToToml as jsonToToml, data_jsonToXml as jsonToXml, data_minifyNdjson as minifyNdjson, data_minifyToml as minifyToml, data_minifyXml as minifyXml, data_ndjsonToJsonArray as ndjsonToJsonArray, data_parseCsv as parseCsv, data_parseEnv as parseEnv, data_parseIni as parseIni, data_parseXmlToObject as parseXmlToObject, data_stringifyIni as stringifyIni, data_toCsvString as toCsvString, data_tomlToJson as tomlToJson, data_validateEnvKey as validateEnvKey, data_validateIni as validateIni, data_validateNdjson as validateNdjson, data_validateToml as validateToml, data_validateXml as validateXml, data_validateYaml as validateYaml, data_xmlToJson as xmlToJson };
|
|
213
247
|
}
|
|
214
248
|
|
|
215
|
-
export {
|
|
249
|
+
export { parseCsv as A, parseEnv as B, type CsvParseResult as C, parseIni as D, type EnvEntry as E, parseXmlToObject as F, stringifyIni as G, toCsvString as H, type IniSection as I, tomlToJson as J, validateEnvKey as K, validateIni as L, validateNdjson as M, type NdjsonLineResult as N, validateToml as O, type ParseOptions as P, validateXml as Q, validateYaml as R, xmlToJson as S, type TomlFormatResult as T, type ValidationResult as V, type XmlFormatResult as X, type EnvParseResult as a, type NdjsonValidateResult as b, type ParsedIni as c, data as d, type XmlToJsonOptions as e, csvToJson as f, detectDelimiter as g, envToExport as h, envToJson as i, formatNdjson as j, formatToml as k, formatXml as l, getSection as m, getSectionNames as n, getTomlStats as o, getXmlStats as p, getYamlStats as q, iniToJson as r, jsonArrayToNdjson as s, jsonToIni as t, jsonToToml as u, jsonToXml as v, minifyNdjson as w, minifyToml as x, minifyXml as y, ndjsonToJsonArray as z };
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* - csv-viewer : detectDelimiter, parseCsv, csvToJson, toCsvString
|
|
11
11
|
* - ini-parser : parseIni, stringifyIni, iniToJson, jsonToIni, getSection, getSectionNames, validateIni
|
|
12
12
|
* - env-parser : parseEnv, envToJson, envToExport, validateEnvKey
|
|
13
|
+
* - ndjson-formatter: validateNdjson, minifyNdjson, formatNdjson, ndjsonToJsonArray, jsonArrayToNdjson
|
|
13
14
|
*/
|
|
14
15
|
interface ValidationResult {
|
|
15
16
|
valid: boolean;
|
|
@@ -167,11 +168,39 @@ declare function envToJson(input: string): string | {
|
|
|
167
168
|
};
|
|
168
169
|
declare function envToExport(input: string): string;
|
|
169
170
|
declare function validateEnvKey(key: string): boolean;
|
|
171
|
+
interface NdjsonLineResult {
|
|
172
|
+
line: number;
|
|
173
|
+
raw: string;
|
|
174
|
+
valid: boolean;
|
|
175
|
+
error?: string;
|
|
176
|
+
}
|
|
177
|
+
interface NdjsonValidateResult {
|
|
178
|
+
valid: boolean;
|
|
179
|
+
totalLines: number;
|
|
180
|
+
validLines: number;
|
|
181
|
+
invalidLines: number;
|
|
182
|
+
lines: NdjsonLineResult[];
|
|
183
|
+
}
|
|
184
|
+
declare function validateNdjson(input: string): NdjsonValidateResult;
|
|
185
|
+
declare function minifyNdjson(input: string): string | {
|
|
186
|
+
error: string;
|
|
187
|
+
};
|
|
188
|
+
declare function formatNdjson(input: string, indent?: number): string | {
|
|
189
|
+
error: string;
|
|
190
|
+
};
|
|
191
|
+
declare function ndjsonToJsonArray(input: string): string | {
|
|
192
|
+
error: string;
|
|
193
|
+
};
|
|
194
|
+
declare function jsonArrayToNdjson(input: string): string | {
|
|
195
|
+
error: string;
|
|
196
|
+
};
|
|
170
197
|
|
|
171
198
|
type data_CsvParseResult = CsvParseResult;
|
|
172
199
|
type data_EnvEntry = EnvEntry;
|
|
173
200
|
type data_EnvParseResult = EnvParseResult;
|
|
174
201
|
type data_IniSection = IniSection;
|
|
202
|
+
type data_NdjsonLineResult = NdjsonLineResult;
|
|
203
|
+
type data_NdjsonValidateResult = NdjsonValidateResult;
|
|
175
204
|
type data_ParseOptions = ParseOptions;
|
|
176
205
|
type data_ParsedIni = ParsedIni;
|
|
177
206
|
type data_TomlFormatResult = TomlFormatResult;
|
|
@@ -182,6 +211,7 @@ declare const data_csvToJson: typeof csvToJson;
|
|
|
182
211
|
declare const data_detectDelimiter: typeof detectDelimiter;
|
|
183
212
|
declare const data_envToExport: typeof envToExport;
|
|
184
213
|
declare const data_envToJson: typeof envToJson;
|
|
214
|
+
declare const data_formatNdjson: typeof formatNdjson;
|
|
185
215
|
declare const data_formatToml: typeof formatToml;
|
|
186
216
|
declare const data_formatXml: typeof formatXml;
|
|
187
217
|
declare const data_getSection: typeof getSection;
|
|
@@ -190,11 +220,14 @@ declare const data_getTomlStats: typeof getTomlStats;
|
|
|
190
220
|
declare const data_getXmlStats: typeof getXmlStats;
|
|
191
221
|
declare const data_getYamlStats: typeof getYamlStats;
|
|
192
222
|
declare const data_iniToJson: typeof iniToJson;
|
|
223
|
+
declare const data_jsonArrayToNdjson: typeof jsonArrayToNdjson;
|
|
193
224
|
declare const data_jsonToIni: typeof jsonToIni;
|
|
194
225
|
declare const data_jsonToToml: typeof jsonToToml;
|
|
195
226
|
declare const data_jsonToXml: typeof jsonToXml;
|
|
227
|
+
declare const data_minifyNdjson: typeof minifyNdjson;
|
|
196
228
|
declare const data_minifyToml: typeof minifyToml;
|
|
197
229
|
declare const data_minifyXml: typeof minifyXml;
|
|
230
|
+
declare const data_ndjsonToJsonArray: typeof ndjsonToJsonArray;
|
|
198
231
|
declare const data_parseCsv: typeof parseCsv;
|
|
199
232
|
declare const data_parseEnv: typeof parseEnv;
|
|
200
233
|
declare const data_parseIni: typeof parseIni;
|
|
@@ -204,12 +237,13 @@ declare const data_toCsvString: typeof toCsvString;
|
|
|
204
237
|
declare const data_tomlToJson: typeof tomlToJson;
|
|
205
238
|
declare const data_validateEnvKey: typeof validateEnvKey;
|
|
206
239
|
declare const data_validateIni: typeof validateIni;
|
|
240
|
+
declare const data_validateNdjson: typeof validateNdjson;
|
|
207
241
|
declare const data_validateToml: typeof validateToml;
|
|
208
242
|
declare const data_validateXml: typeof validateXml;
|
|
209
243
|
declare const data_validateYaml: typeof validateYaml;
|
|
210
244
|
declare const data_xmlToJson: typeof xmlToJson;
|
|
211
245
|
declare namespace data {
|
|
212
|
-
export { type data_CsvParseResult as CsvParseResult, type data_EnvEntry as EnvEntry, type data_EnvParseResult as EnvParseResult, type data_IniSection as IniSection, type data_ParseOptions as ParseOptions, type data_ParsedIni as ParsedIni, type data_TomlFormatResult as TomlFormatResult, type data_ValidationResult as ValidationResult, type data_XmlFormatResult as XmlFormatResult, type data_XmlToJsonOptions as XmlToJsonOptions, data_csvToJson as csvToJson, data_detectDelimiter as detectDelimiter, data_envToExport as envToExport, data_envToJson as envToJson, data_formatToml as formatToml, data_formatXml as formatXml, data_getSection as getSection, data_getSectionNames as getSectionNames, data_getTomlStats as getTomlStats, data_getXmlStats as getXmlStats, data_getYamlStats as getYamlStats, data_iniToJson as iniToJson, data_jsonToIni as jsonToIni, data_jsonToToml as jsonToToml, data_jsonToXml as jsonToXml, data_minifyToml as minifyToml, data_minifyXml as minifyXml, data_parseCsv as parseCsv, data_parseEnv as parseEnv, data_parseIni as parseIni, data_parseXmlToObject as parseXmlToObject, data_stringifyIni as stringifyIni, data_toCsvString as toCsvString, data_tomlToJson as tomlToJson, data_validateEnvKey as validateEnvKey, data_validateIni as validateIni, data_validateToml as validateToml, data_validateXml as validateXml, data_validateYaml as validateYaml, data_xmlToJson as xmlToJson };
|
|
246
|
+
export { type data_CsvParseResult as CsvParseResult, type data_EnvEntry as EnvEntry, type data_EnvParseResult as EnvParseResult, type data_IniSection as IniSection, type data_NdjsonLineResult as NdjsonLineResult, type data_NdjsonValidateResult as NdjsonValidateResult, type data_ParseOptions as ParseOptions, type data_ParsedIni as ParsedIni, type data_TomlFormatResult as TomlFormatResult, type data_ValidationResult as ValidationResult, type data_XmlFormatResult as XmlFormatResult, type data_XmlToJsonOptions as XmlToJsonOptions, data_csvToJson as csvToJson, data_detectDelimiter as detectDelimiter, data_envToExport as envToExport, data_envToJson as envToJson, data_formatNdjson as formatNdjson, data_formatToml as formatToml, data_formatXml as formatXml, data_getSection as getSection, data_getSectionNames as getSectionNames, data_getTomlStats as getTomlStats, data_getXmlStats as getXmlStats, data_getYamlStats as getYamlStats, data_iniToJson as iniToJson, data_jsonArrayToNdjson as jsonArrayToNdjson, data_jsonToIni as jsonToIni, data_jsonToToml as jsonToToml, data_jsonToXml as jsonToXml, data_minifyNdjson as minifyNdjson, data_minifyToml as minifyToml, data_minifyXml as minifyXml, data_ndjsonToJsonArray as ndjsonToJsonArray, data_parseCsv as parseCsv, data_parseEnv as parseEnv, data_parseIni as parseIni, data_parseXmlToObject as parseXmlToObject, data_stringifyIni as stringifyIni, data_toCsvString as toCsvString, data_tomlToJson as tomlToJson, data_validateEnvKey as validateEnvKey, data_validateIni as validateIni, data_validateNdjson as validateNdjson, data_validateToml as validateToml, data_validateXml as validateXml, data_validateYaml as validateYaml, data_xmlToJson as xmlToJson };
|
|
213
247
|
}
|
|
214
248
|
|
|
215
|
-
export {
|
|
249
|
+
export { parseCsv as A, parseEnv as B, type CsvParseResult as C, parseIni as D, type EnvEntry as E, parseXmlToObject as F, stringifyIni as G, toCsvString as H, type IniSection as I, tomlToJson as J, validateEnvKey as K, validateIni as L, validateNdjson as M, type NdjsonLineResult as N, validateToml as O, type ParseOptions as P, validateXml as Q, validateYaml as R, xmlToJson as S, type TomlFormatResult as T, type ValidationResult as V, type XmlFormatResult as X, type EnvParseResult as a, type NdjsonValidateResult as b, type ParsedIni as c, data as d, type XmlToJsonOptions as e, csvToJson as f, detectDelimiter as g, envToExport as h, envToJson as i, formatNdjson as j, formatToml as k, formatXml as l, getSection as m, getSectionNames as n, getTomlStats as o, getXmlStats as p, getYamlStats as q, iniToJson as r, jsonArrayToNdjson as s, jsonToIni as t, jsonToToml as u, jsonToXml as v, minifyNdjson as w, minifyToml as x, minifyXml as y, ndjsonToJsonArray as z };
|
package/dist/index.cjs
CHANGED
|
@@ -4197,6 +4197,7 @@ __export(data_exports, {
|
|
|
4197
4197
|
detectDelimiter: () => detectDelimiter2,
|
|
4198
4198
|
envToExport: () => envToExport,
|
|
4199
4199
|
envToJson: () => envToJson,
|
|
4200
|
+
formatNdjson: () => formatNdjson,
|
|
4200
4201
|
formatToml: () => formatToml,
|
|
4201
4202
|
formatXml: () => formatXml,
|
|
4202
4203
|
getSection: () => getSection,
|
|
@@ -4205,11 +4206,14 @@ __export(data_exports, {
|
|
|
4205
4206
|
getXmlStats: () => getXmlStats,
|
|
4206
4207
|
getYamlStats: () => getYamlStats,
|
|
4207
4208
|
iniToJson: () => iniToJson,
|
|
4209
|
+
jsonArrayToNdjson: () => jsonArrayToNdjson,
|
|
4208
4210
|
jsonToIni: () => jsonToIni,
|
|
4209
4211
|
jsonToToml: () => jsonToToml,
|
|
4210
4212
|
jsonToXml: () => jsonToXml,
|
|
4213
|
+
minifyNdjson: () => minifyNdjson,
|
|
4211
4214
|
minifyToml: () => minifyToml,
|
|
4212
4215
|
minifyXml: () => minifyXml,
|
|
4216
|
+
ndjsonToJsonArray: () => ndjsonToJsonArray,
|
|
4213
4217
|
parseCsv: () => parseCsv,
|
|
4214
4218
|
parseEnv: () => parseEnv,
|
|
4215
4219
|
parseIni: () => parseIni,
|
|
@@ -4219,6 +4223,7 @@ __export(data_exports, {
|
|
|
4219
4223
|
tomlToJson: () => tomlToJson,
|
|
4220
4224
|
validateEnvKey: () => validateEnvKey,
|
|
4221
4225
|
validateIni: () => validateIni,
|
|
4226
|
+
validateNdjson: () => validateNdjson,
|
|
4222
4227
|
validateToml: () => validateToml,
|
|
4223
4228
|
validateXml: () => validateXml,
|
|
4224
4229
|
validateYaml: () => validateYaml,
|
|
@@ -5264,6 +5269,64 @@ function envToExport(input) {
|
|
|
5264
5269
|
function validateEnvKey(key) {
|
|
5265
5270
|
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(key);
|
|
5266
5271
|
}
|
|
5272
|
+
function validateNdjson(input) {
|
|
5273
|
+
const rawLines = input.split("\n");
|
|
5274
|
+
const lines = [];
|
|
5275
|
+
let validCount = 0;
|
|
5276
|
+
rawLines.forEach((raw, idx) => {
|
|
5277
|
+
if (raw.trim() === "") return;
|
|
5278
|
+
const lineNum = idx + 1;
|
|
5279
|
+
try {
|
|
5280
|
+
JSON.parse(raw);
|
|
5281
|
+
lines.push({ line: lineNum, raw, valid: true });
|
|
5282
|
+
validCount++;
|
|
5283
|
+
} catch (e) {
|
|
5284
|
+
lines.push({
|
|
5285
|
+
line: lineNum,
|
|
5286
|
+
raw,
|
|
5287
|
+
valid: false,
|
|
5288
|
+
error: e instanceof Error ? e.message : String(e)
|
|
5289
|
+
});
|
|
5290
|
+
}
|
|
5291
|
+
});
|
|
5292
|
+
return {
|
|
5293
|
+
valid: lines.length > 0 && validCount === lines.length,
|
|
5294
|
+
totalLines: lines.length,
|
|
5295
|
+
validLines: validCount,
|
|
5296
|
+
invalidLines: lines.length - validCount,
|
|
5297
|
+
lines
|
|
5298
|
+
};
|
|
5299
|
+
}
|
|
5300
|
+
function _firstNdjsonError(result) {
|
|
5301
|
+
const firstError = result.lines.find((l) => !l.valid);
|
|
5302
|
+
return firstError ? `Line ${firstError.line}: ${firstError.error}` : "Invalid NDJSON";
|
|
5303
|
+
}
|
|
5304
|
+
function minifyNdjson(input) {
|
|
5305
|
+
const result = validateNdjson(input);
|
|
5306
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
5307
|
+
return result.lines.map((l) => JSON.stringify(JSON.parse(l.raw))).join("\n");
|
|
5308
|
+
}
|
|
5309
|
+
function formatNdjson(input, indent = 2) {
|
|
5310
|
+
const result = validateNdjson(input);
|
|
5311
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
5312
|
+
return result.lines.map((l) => JSON.stringify(JSON.parse(l.raw), null, indent)).join("\n");
|
|
5313
|
+
}
|
|
5314
|
+
function ndjsonToJsonArray(input) {
|
|
5315
|
+
const result = validateNdjson(input);
|
|
5316
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
5317
|
+
const values = result.lines.map((l) => JSON.parse(l.raw));
|
|
5318
|
+
return JSON.stringify(values, null, 2);
|
|
5319
|
+
}
|
|
5320
|
+
function jsonArrayToNdjson(input) {
|
|
5321
|
+
let parsed;
|
|
5322
|
+
try {
|
|
5323
|
+
parsed = JSON.parse(input);
|
|
5324
|
+
} catch (e) {
|
|
5325
|
+
return { error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
5326
|
+
}
|
|
5327
|
+
if (!Array.isArray(parsed)) return { error: "Input must be a JSON array" };
|
|
5328
|
+
return parsed.map((item) => JSON.stringify(item)).join("\n");
|
|
5329
|
+
}
|
|
5267
5330
|
|
|
5268
5331
|
// src/tools/generators.ts
|
|
5269
5332
|
var generators_exports = {};
|
|
@@ -7380,6 +7443,7 @@ __export(network_exports, {
|
|
|
7380
7443
|
isValidIpv6: () => isValidIpv6,
|
|
7381
7444
|
parseDnsResponse: () => parseDnsResponse,
|
|
7382
7445
|
parseGeoResponse: () => parseGeoResponse,
|
|
7446
|
+
parseHar: () => parseHar,
|
|
7383
7447
|
searchHeaders: () => searchHeaders,
|
|
7384
7448
|
searchStatusCodes: () => searchStatusCodes,
|
|
7385
7449
|
statusCodeToText: () => statusCodeToText,
|
|
@@ -8736,6 +8800,64 @@ function validateHeaderValue(name, value) {
|
|
|
8736
8800
|
}
|
|
8737
8801
|
return { valid: true };
|
|
8738
8802
|
}
|
|
8803
|
+
function parseHar(input) {
|
|
8804
|
+
if (!input || !input.trim()) {
|
|
8805
|
+
return { error: "Input is empty" };
|
|
8806
|
+
}
|
|
8807
|
+
let data;
|
|
8808
|
+
try {
|
|
8809
|
+
data = JSON.parse(input);
|
|
8810
|
+
} catch (e) {
|
|
8811
|
+
return { error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
8812
|
+
}
|
|
8813
|
+
if (typeof data !== "object" || data === null || !("log" in data)) {
|
|
8814
|
+
return { error: 'Not a valid HAR file: missing "log" property' };
|
|
8815
|
+
}
|
|
8816
|
+
const log = data.log;
|
|
8817
|
+
if (typeof log !== "object" || log === null || !Array.isArray(log.entries)) {
|
|
8818
|
+
return { error: 'Not a valid HAR file: "log.entries" must be an array' };
|
|
8819
|
+
}
|
|
8820
|
+
const logObj = log;
|
|
8821
|
+
const entries = [];
|
|
8822
|
+
const methods = {};
|
|
8823
|
+
const statusCodes = {};
|
|
8824
|
+
let totalSize = 0;
|
|
8825
|
+
let totalTime = 0;
|
|
8826
|
+
let failedRequests = 0;
|
|
8827
|
+
for (const raw of logObj.entries) {
|
|
8828
|
+
if (typeof raw !== "object" || raw === null) continue;
|
|
8829
|
+
const e = raw;
|
|
8830
|
+
const request = e.request ?? {};
|
|
8831
|
+
const response = e.response ?? {};
|
|
8832
|
+
const content = response.content ?? {};
|
|
8833
|
+
const method = typeof request.method === "string" ? request.method : "GET";
|
|
8834
|
+
const url = typeof request.url === "string" ? request.url : "";
|
|
8835
|
+
const status = typeof response.status === "number" ? response.status : 0;
|
|
8836
|
+
const statusText = typeof response.statusText === "string" ? response.statusText : "";
|
|
8837
|
+
const httpVersion = typeof response.httpVersion === "string" ? response.httpVersion : "";
|
|
8838
|
+
const mimeType = typeof content.mimeType === "string" ? content.mimeType : "";
|
|
8839
|
+
const size = typeof content.size === "number" && content.size > 0 ? content.size : 0;
|
|
8840
|
+
const time = typeof e.time === "number" ? e.time : 0;
|
|
8841
|
+
const startedDateTime = typeof e.startedDateTime === "string" ? e.startedDateTime : "";
|
|
8842
|
+
entries.push({ method, url, status, statusText, httpVersion, mimeType, size, time, startedDateTime });
|
|
8843
|
+
methods[method] = (methods[method] ?? 0) + 1;
|
|
8844
|
+
if (status > 0) statusCodes[String(status)] = (statusCodes[String(status)] ?? 0) + 1;
|
|
8845
|
+
totalSize += size;
|
|
8846
|
+
totalTime += time;
|
|
8847
|
+
if (status === 0 || status >= 400) failedRequests++;
|
|
8848
|
+
}
|
|
8849
|
+
const totalRequests = entries.length;
|
|
8850
|
+
const avgTime = totalRequests > 0 ? Math.round(totalTime / totalRequests * 100) / 100 : 0;
|
|
8851
|
+
return {
|
|
8852
|
+
version: typeof logObj.version === "string" ? logObj.version : "",
|
|
8853
|
+
creator: {
|
|
8854
|
+
name: typeof logObj.creator?.name === "string" ? logObj.creator.name : "",
|
|
8855
|
+
version: typeof logObj.creator?.version === "string" ? logObj.creator.version : ""
|
|
8856
|
+
},
|
|
8857
|
+
entries,
|
|
8858
|
+
summary: { totalRequests, totalSize, totalTime, avgTime, failedRequests, methods, statusCodes }
|
|
8859
|
+
};
|
|
8860
|
+
}
|
|
8739
8861
|
|
|
8740
8862
|
// src/tools/api.ts
|
|
8741
8863
|
var api_exports = {};
|
package/dist/index.d.cts
CHANGED
|
@@ -2,11 +2,11 @@ export { j as json } from './json-BjSoIS1h.cjs';
|
|
|
2
2
|
export { e as encoding } from './encoding-7gmq-vkV.cjs';
|
|
3
3
|
export { h as hashing } from './hashing-CnetQFD_.cjs';
|
|
4
4
|
export { t as text } from './text-CI7JAl7F.cjs';
|
|
5
|
-
export { d as data } from './data-
|
|
5
|
+
export { d as data } from './data-CakDxAcT.cjs';
|
|
6
6
|
export { g as generators } from './generators-BGtRGpJZ.cjs';
|
|
7
7
|
export { t as time } from './time-DbT8fjaF.cjs';
|
|
8
8
|
export { u as units } from './units-6lwDYBvX.cjs';
|
|
9
|
-
export { n as network } from './network-
|
|
9
|
+
export { n as network } from './network-DwyAjwJS.cjs';
|
|
10
10
|
export { a as api } from './api-8aZtWhSj.cjs';
|
|
11
11
|
export { c as code } from './code-BUqyaofO.cjs';
|
|
12
12
|
export { c as color } from './color-tPwZCr9H.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export { j as json } from './json-BjSoIS1h.js';
|
|
|
2
2
|
export { e as encoding } from './encoding-7gmq-vkV.js';
|
|
3
3
|
export { h as hashing } from './hashing-CnetQFD_.js';
|
|
4
4
|
export { t as text } from './text-CI7JAl7F.js';
|
|
5
|
-
export { d as data } from './data-
|
|
5
|
+
export { d as data } from './data-CakDxAcT.js';
|
|
6
6
|
export { g as generators } from './generators-BGtRGpJZ.js';
|
|
7
7
|
export { t as time } from './time-DbT8fjaF.js';
|
|
8
8
|
export { u as units } from './units-6lwDYBvX.js';
|
|
9
|
-
export { n as network } from './network-
|
|
9
|
+
export { n as network } from './network-DwyAjwJS.js';
|
|
10
10
|
export { a as api } from './api-8aZtWhSj.js';
|
|
11
11
|
export { c as code } from './code-BUqyaofO.js';
|
|
12
12
|
export { c as color } from './color-tPwZCr9H.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { media_exports as media } from './chunk-N7C52YGL.js';
|
|
2
2
|
export { units_exports as units } from './chunk-QJE743LY.js';
|
|
3
|
-
export { network_exports as network } from './chunk-
|
|
3
|
+
export { network_exports as network } from './chunk-V5JKVDBA.js';
|
|
4
4
|
export { api_exports as api } from './chunk-HFRTZE7T.js';
|
|
5
5
|
export { code_exports as code } from './chunk-V5S6OJ4A.js';
|
|
6
6
|
export { color_exports as color } from './chunk-BPVAB4P2.js';
|
|
@@ -11,7 +11,7 @@ export { json_exports as json } from './chunk-TSAGO3XP.js';
|
|
|
11
11
|
export { encoding_exports as encoding } from './chunk-IPR7FSX4.js';
|
|
12
12
|
export { hashing_exports as hashing } from './chunk-FL53T24A.js';
|
|
13
13
|
export { text_exports as text } from './chunk-YBBYFAOV.js';
|
|
14
|
-
export { data_exports as data } from './chunk-
|
|
14
|
+
export { data_exports as data } from './chunk-DNCOIO5N.js';
|
|
15
15
|
export { generators_exports as generators } from './chunk-2CJSLYWI.js';
|
|
16
16
|
export { time_exports as time } from './chunk-ZPQZEIXP.js';
|
|
17
17
|
import './chunk-MLKGABMK.js';
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - ip-geolocation: IP address geolocation via ip-api.com
|
|
8
8
|
* - http-status : HTTP status code lookup and search
|
|
9
9
|
* - http-headers : HTTP header reference lookup and validation
|
|
10
|
+
* - har-viewer : parseHar
|
|
10
11
|
*/
|
|
11
12
|
declare const DNS_RECORD_TYPES: readonly ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SOA", "PTR", "SRV", "CAA"];
|
|
12
13
|
type DnsRecordType = typeof DNS_RECORD_TYPES[number];
|
|
@@ -124,6 +125,38 @@ declare function validateHeaderValue(name: string, value: string): {
|
|
|
124
125
|
valid: boolean;
|
|
125
126
|
warning?: string;
|
|
126
127
|
};
|
|
128
|
+
interface HarEntry {
|
|
129
|
+
method: string;
|
|
130
|
+
url: string;
|
|
131
|
+
status: number;
|
|
132
|
+
statusText: string;
|
|
133
|
+
httpVersion: string;
|
|
134
|
+
mimeType: string;
|
|
135
|
+
size: number;
|
|
136
|
+
time: number;
|
|
137
|
+
startedDateTime: string;
|
|
138
|
+
}
|
|
139
|
+
interface HarSummary {
|
|
140
|
+
totalRequests: number;
|
|
141
|
+
totalSize: number;
|
|
142
|
+
totalTime: number;
|
|
143
|
+
avgTime: number;
|
|
144
|
+
failedRequests: number;
|
|
145
|
+
methods: Record<string, number>;
|
|
146
|
+
statusCodes: Record<string, number>;
|
|
147
|
+
}
|
|
148
|
+
interface HarParseResult {
|
|
149
|
+
version: string;
|
|
150
|
+
creator: {
|
|
151
|
+
name: string;
|
|
152
|
+
version: string;
|
|
153
|
+
};
|
|
154
|
+
entries: HarEntry[];
|
|
155
|
+
summary: HarSummary;
|
|
156
|
+
}
|
|
157
|
+
declare function parseHar(input: string): HarParseResult | {
|
|
158
|
+
error: string;
|
|
159
|
+
};
|
|
127
160
|
|
|
128
161
|
declare const network_DNS_RECORD_TYPES: typeof DNS_RECORD_TYPES;
|
|
129
162
|
type network_DnsRecord = DnsRecord;
|
|
@@ -131,6 +164,9 @@ type network_DnsRecordType = DnsRecordType;
|
|
|
131
164
|
type network_DnsResponse = DnsResponse;
|
|
132
165
|
type network_GeoResult = GeoResult;
|
|
133
166
|
declare const network_HTTP_HEADERS: typeof HTTP_HEADERS;
|
|
167
|
+
type network_HarEntry = HarEntry;
|
|
168
|
+
type network_HarParseResult = HarParseResult;
|
|
169
|
+
type network_HarSummary = HarSummary;
|
|
134
170
|
type network_HeaderCategory = HeaderCategory;
|
|
135
171
|
type network_HttpHeader = HttpHeader;
|
|
136
172
|
type network_ParsedDnsResult = ParsedDnsResult;
|
|
@@ -156,6 +192,7 @@ declare const network_isValidIpv4: typeof isValidIpv4;
|
|
|
156
192
|
declare const network_isValidIpv6: typeof isValidIpv6;
|
|
157
193
|
declare const network_parseDnsResponse: typeof parseDnsResponse;
|
|
158
194
|
declare const network_parseGeoResponse: typeof parseGeoResponse;
|
|
195
|
+
declare const network_parseHar: typeof parseHar;
|
|
159
196
|
declare const network_searchHeaders: typeof searchHeaders;
|
|
160
197
|
declare const network_searchStatusCodes: typeof searchStatusCodes;
|
|
161
198
|
declare const network_statusCodeToText: typeof statusCodeToText;
|
|
@@ -164,7 +201,7 @@ declare const network_validateDomain: typeof validateDomain;
|
|
|
164
201
|
declare const network_validateHeaderName: typeof validateHeaderName;
|
|
165
202
|
declare const network_validateHeaderValue: typeof validateHeaderValue;
|
|
166
203
|
declare namespace network {
|
|
167
|
-
export { network_DNS_RECORD_TYPES as DNS_RECORD_TYPES, type network_DnsRecord as DnsRecord, type network_DnsRecordType as DnsRecordType, type network_DnsResponse as DnsResponse, type network_GeoResult as GeoResult, network_HTTP_HEADERS as HTTP_HEADERS, type network_HeaderCategory as HeaderCategory, type network_HttpHeader as HttpHeader, type network_ParsedDnsResult as ParsedDnsResult, type network_ParsedGeoResult as ParsedGeoResult, network_STATUS_CODES as STATUS_CODES, type network_StatusCode as StatusCode, network_buildDnsQueryUrl as buildDnsQueryUrl, network_buildGeoUrl as buildGeoUrl, network_buildMapUrl as buildMapUrl, network_countryCodeToFlag as countryCodeToFlag, network_formatCoordinates as formatCoordinates, network_formatTtl as formatTtl, network_getByCategory as getByCategory, network_getHeader as getHeader, network_getHeadersByCategory as getHeadersByCategory, network_getStatusByCategory as getStatusByCategory, network_getStatusCode as getStatusCode, network_isClientError as isClientError, network_isServerError as isServerError, network_isSuccess as isSuccess, network_isValidIp as isValidIp, network_isValidIpv4 as isValidIpv4, network_isValidIpv6 as isValidIpv6, network_parseDnsResponse as parseDnsResponse, network_parseGeoResponse as parseGeoResponse, network_searchHeaders as searchHeaders, network_searchStatusCodes as searchStatusCodes, network_statusCodeToText as statusCodeToText, network_typeNumberToLabel as typeNumberToLabel, network_validateDomain as validateDomain, network_validateHeaderName as validateHeaderName, network_validateHeaderValue as validateHeaderValue };
|
|
204
|
+
export { network_DNS_RECORD_TYPES as DNS_RECORD_TYPES, type network_DnsRecord as DnsRecord, type network_DnsRecordType as DnsRecordType, type network_DnsResponse as DnsResponse, type network_GeoResult as GeoResult, network_HTTP_HEADERS as HTTP_HEADERS, type network_HarEntry as HarEntry, type network_HarParseResult as HarParseResult, type network_HarSummary as HarSummary, type network_HeaderCategory as HeaderCategory, type network_HttpHeader as HttpHeader, type network_ParsedDnsResult as ParsedDnsResult, type network_ParsedGeoResult as ParsedGeoResult, network_STATUS_CODES as STATUS_CODES, type network_StatusCode as StatusCode, network_buildDnsQueryUrl as buildDnsQueryUrl, network_buildGeoUrl as buildGeoUrl, network_buildMapUrl as buildMapUrl, network_countryCodeToFlag as countryCodeToFlag, network_formatCoordinates as formatCoordinates, network_formatTtl as formatTtl, network_getByCategory as getByCategory, network_getHeader as getHeader, network_getHeadersByCategory as getHeadersByCategory, network_getStatusByCategory as getStatusByCategory, network_getStatusCode as getStatusCode, network_isClientError as isClientError, network_isServerError as isServerError, network_isSuccess as isSuccess, network_isValidIp as isValidIp, network_isValidIpv4 as isValidIpv4, network_isValidIpv6 as isValidIpv6, network_parseDnsResponse as parseDnsResponse, network_parseGeoResponse as parseGeoResponse, network_parseHar as parseHar, network_searchHeaders as searchHeaders, network_searchStatusCodes as searchStatusCodes, network_statusCodeToText as statusCodeToText, network_typeNumberToLabel as typeNumberToLabel, network_validateDomain as validateDomain, network_validateHeaderName as validateHeaderName, network_validateHeaderValue as validateHeaderValue };
|
|
168
205
|
}
|
|
169
206
|
|
|
170
|
-
export {
|
|
207
|
+
export { isValidIpv4 as A, isValidIpv6 as B, parseDnsResponse as C, DNS_RECORD_TYPES as D, parseGeoResponse as E, parseHar as F, type GeoResult as G, HTTP_HEADERS as H, searchHeaders as I, searchStatusCodes as J, statusCodeToText as K, typeNumberToLabel as L, validateDomain as M, validateHeaderName as N, validateHeaderValue as O, type ParsedDnsResult as P, STATUS_CODES as S, type DnsRecord as a, type DnsRecordType as b, type DnsResponse as c, type HarEntry as d, type HarParseResult as e, type HarSummary as f, type HeaderCategory as g, type HttpHeader as h, type ParsedGeoResult as i, type StatusCode as j, buildDnsQueryUrl as k, buildGeoUrl as l, buildMapUrl as m, network as n, countryCodeToFlag as o, formatCoordinates as p, formatTtl as q, getByCategory as r, getHeader as s, getHeadersByCategory as t, getStatusByCategory as u, getStatusCode as v, isClientError as w, isServerError as x, isSuccess as y, isValidIp as z };
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - ip-geolocation: IP address geolocation via ip-api.com
|
|
8
8
|
* - http-status : HTTP status code lookup and search
|
|
9
9
|
* - http-headers : HTTP header reference lookup and validation
|
|
10
|
+
* - har-viewer : parseHar
|
|
10
11
|
*/
|
|
11
12
|
declare const DNS_RECORD_TYPES: readonly ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SOA", "PTR", "SRV", "CAA"];
|
|
12
13
|
type DnsRecordType = typeof DNS_RECORD_TYPES[number];
|
|
@@ -124,6 +125,38 @@ declare function validateHeaderValue(name: string, value: string): {
|
|
|
124
125
|
valid: boolean;
|
|
125
126
|
warning?: string;
|
|
126
127
|
};
|
|
128
|
+
interface HarEntry {
|
|
129
|
+
method: string;
|
|
130
|
+
url: string;
|
|
131
|
+
status: number;
|
|
132
|
+
statusText: string;
|
|
133
|
+
httpVersion: string;
|
|
134
|
+
mimeType: string;
|
|
135
|
+
size: number;
|
|
136
|
+
time: number;
|
|
137
|
+
startedDateTime: string;
|
|
138
|
+
}
|
|
139
|
+
interface HarSummary {
|
|
140
|
+
totalRequests: number;
|
|
141
|
+
totalSize: number;
|
|
142
|
+
totalTime: number;
|
|
143
|
+
avgTime: number;
|
|
144
|
+
failedRequests: number;
|
|
145
|
+
methods: Record<string, number>;
|
|
146
|
+
statusCodes: Record<string, number>;
|
|
147
|
+
}
|
|
148
|
+
interface HarParseResult {
|
|
149
|
+
version: string;
|
|
150
|
+
creator: {
|
|
151
|
+
name: string;
|
|
152
|
+
version: string;
|
|
153
|
+
};
|
|
154
|
+
entries: HarEntry[];
|
|
155
|
+
summary: HarSummary;
|
|
156
|
+
}
|
|
157
|
+
declare function parseHar(input: string): HarParseResult | {
|
|
158
|
+
error: string;
|
|
159
|
+
};
|
|
127
160
|
|
|
128
161
|
declare const network_DNS_RECORD_TYPES: typeof DNS_RECORD_TYPES;
|
|
129
162
|
type network_DnsRecord = DnsRecord;
|
|
@@ -131,6 +164,9 @@ type network_DnsRecordType = DnsRecordType;
|
|
|
131
164
|
type network_DnsResponse = DnsResponse;
|
|
132
165
|
type network_GeoResult = GeoResult;
|
|
133
166
|
declare const network_HTTP_HEADERS: typeof HTTP_HEADERS;
|
|
167
|
+
type network_HarEntry = HarEntry;
|
|
168
|
+
type network_HarParseResult = HarParseResult;
|
|
169
|
+
type network_HarSummary = HarSummary;
|
|
134
170
|
type network_HeaderCategory = HeaderCategory;
|
|
135
171
|
type network_HttpHeader = HttpHeader;
|
|
136
172
|
type network_ParsedDnsResult = ParsedDnsResult;
|
|
@@ -156,6 +192,7 @@ declare const network_isValidIpv4: typeof isValidIpv4;
|
|
|
156
192
|
declare const network_isValidIpv6: typeof isValidIpv6;
|
|
157
193
|
declare const network_parseDnsResponse: typeof parseDnsResponse;
|
|
158
194
|
declare const network_parseGeoResponse: typeof parseGeoResponse;
|
|
195
|
+
declare const network_parseHar: typeof parseHar;
|
|
159
196
|
declare const network_searchHeaders: typeof searchHeaders;
|
|
160
197
|
declare const network_searchStatusCodes: typeof searchStatusCodes;
|
|
161
198
|
declare const network_statusCodeToText: typeof statusCodeToText;
|
|
@@ -164,7 +201,7 @@ declare const network_validateDomain: typeof validateDomain;
|
|
|
164
201
|
declare const network_validateHeaderName: typeof validateHeaderName;
|
|
165
202
|
declare const network_validateHeaderValue: typeof validateHeaderValue;
|
|
166
203
|
declare namespace network {
|
|
167
|
-
export { network_DNS_RECORD_TYPES as DNS_RECORD_TYPES, type network_DnsRecord as DnsRecord, type network_DnsRecordType as DnsRecordType, type network_DnsResponse as DnsResponse, type network_GeoResult as GeoResult, network_HTTP_HEADERS as HTTP_HEADERS, type network_HeaderCategory as HeaderCategory, type network_HttpHeader as HttpHeader, type network_ParsedDnsResult as ParsedDnsResult, type network_ParsedGeoResult as ParsedGeoResult, network_STATUS_CODES as STATUS_CODES, type network_StatusCode as StatusCode, network_buildDnsQueryUrl as buildDnsQueryUrl, network_buildGeoUrl as buildGeoUrl, network_buildMapUrl as buildMapUrl, network_countryCodeToFlag as countryCodeToFlag, network_formatCoordinates as formatCoordinates, network_formatTtl as formatTtl, network_getByCategory as getByCategory, network_getHeader as getHeader, network_getHeadersByCategory as getHeadersByCategory, network_getStatusByCategory as getStatusByCategory, network_getStatusCode as getStatusCode, network_isClientError as isClientError, network_isServerError as isServerError, network_isSuccess as isSuccess, network_isValidIp as isValidIp, network_isValidIpv4 as isValidIpv4, network_isValidIpv6 as isValidIpv6, network_parseDnsResponse as parseDnsResponse, network_parseGeoResponse as parseGeoResponse, network_searchHeaders as searchHeaders, network_searchStatusCodes as searchStatusCodes, network_statusCodeToText as statusCodeToText, network_typeNumberToLabel as typeNumberToLabel, network_validateDomain as validateDomain, network_validateHeaderName as validateHeaderName, network_validateHeaderValue as validateHeaderValue };
|
|
204
|
+
export { network_DNS_RECORD_TYPES as DNS_RECORD_TYPES, type network_DnsRecord as DnsRecord, type network_DnsRecordType as DnsRecordType, type network_DnsResponse as DnsResponse, type network_GeoResult as GeoResult, network_HTTP_HEADERS as HTTP_HEADERS, type network_HarEntry as HarEntry, type network_HarParseResult as HarParseResult, type network_HarSummary as HarSummary, type network_HeaderCategory as HeaderCategory, type network_HttpHeader as HttpHeader, type network_ParsedDnsResult as ParsedDnsResult, type network_ParsedGeoResult as ParsedGeoResult, network_STATUS_CODES as STATUS_CODES, type network_StatusCode as StatusCode, network_buildDnsQueryUrl as buildDnsQueryUrl, network_buildGeoUrl as buildGeoUrl, network_buildMapUrl as buildMapUrl, network_countryCodeToFlag as countryCodeToFlag, network_formatCoordinates as formatCoordinates, network_formatTtl as formatTtl, network_getByCategory as getByCategory, network_getHeader as getHeader, network_getHeadersByCategory as getHeadersByCategory, network_getStatusByCategory as getStatusByCategory, network_getStatusCode as getStatusCode, network_isClientError as isClientError, network_isServerError as isServerError, network_isSuccess as isSuccess, network_isValidIp as isValidIp, network_isValidIpv4 as isValidIpv4, network_isValidIpv6 as isValidIpv6, network_parseDnsResponse as parseDnsResponse, network_parseGeoResponse as parseGeoResponse, network_parseHar as parseHar, network_searchHeaders as searchHeaders, network_searchStatusCodes as searchStatusCodes, network_statusCodeToText as statusCodeToText, network_typeNumberToLabel as typeNumberToLabel, network_validateDomain as validateDomain, network_validateHeaderName as validateHeaderName, network_validateHeaderValue as validateHeaderValue };
|
|
168
205
|
}
|
|
169
206
|
|
|
170
|
-
export {
|
|
207
|
+
export { isValidIpv4 as A, isValidIpv6 as B, parseDnsResponse as C, DNS_RECORD_TYPES as D, parseGeoResponse as E, parseHar as F, type GeoResult as G, HTTP_HEADERS as H, searchHeaders as I, searchStatusCodes as J, statusCodeToText as K, typeNumberToLabel as L, validateDomain as M, validateHeaderName as N, validateHeaderValue as O, type ParsedDnsResult as P, STATUS_CODES as S, type DnsRecord as a, type DnsRecordType as b, type DnsResponse as c, type HarEntry as d, type HarParseResult as e, type HarSummary as f, type HeaderCategory as g, type HttpHeader as h, type ParsedGeoResult as i, type StatusCode as j, buildDnsQueryUrl as k, buildGeoUrl as l, buildMapUrl as m, network as n, countryCodeToFlag as o, formatCoordinates as p, formatTtl as q, getByCategory as r, getHeader as s, getHeadersByCategory as t, getStatusByCategory as u, getStatusCode as v, isClientError as w, isServerError as x, isSuccess as y, isValidIp as z };
|
package/dist/tools/data.cjs
CHANGED
|
@@ -1064,11 +1064,70 @@ function envToExport(input) {
|
|
|
1064
1064
|
function validateEnvKey(key) {
|
|
1065
1065
|
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(key);
|
|
1066
1066
|
}
|
|
1067
|
+
function validateNdjson(input) {
|
|
1068
|
+
const rawLines = input.split("\n");
|
|
1069
|
+
const lines = [];
|
|
1070
|
+
let validCount = 0;
|
|
1071
|
+
rawLines.forEach((raw, idx) => {
|
|
1072
|
+
if (raw.trim() === "") return;
|
|
1073
|
+
const lineNum = idx + 1;
|
|
1074
|
+
try {
|
|
1075
|
+
JSON.parse(raw);
|
|
1076
|
+
lines.push({ line: lineNum, raw, valid: true });
|
|
1077
|
+
validCount++;
|
|
1078
|
+
} catch (e) {
|
|
1079
|
+
lines.push({
|
|
1080
|
+
line: lineNum,
|
|
1081
|
+
raw,
|
|
1082
|
+
valid: false,
|
|
1083
|
+
error: e instanceof Error ? e.message : String(e)
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
return {
|
|
1088
|
+
valid: lines.length > 0 && validCount === lines.length,
|
|
1089
|
+
totalLines: lines.length,
|
|
1090
|
+
validLines: validCount,
|
|
1091
|
+
invalidLines: lines.length - validCount,
|
|
1092
|
+
lines
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
function _firstNdjsonError(result) {
|
|
1096
|
+
const firstError = result.lines.find((l) => !l.valid);
|
|
1097
|
+
return firstError ? `Line ${firstError.line}: ${firstError.error}` : "Invalid NDJSON";
|
|
1098
|
+
}
|
|
1099
|
+
function minifyNdjson(input) {
|
|
1100
|
+
const result = validateNdjson(input);
|
|
1101
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
1102
|
+
return result.lines.map((l) => JSON.stringify(JSON.parse(l.raw))).join("\n");
|
|
1103
|
+
}
|
|
1104
|
+
function formatNdjson(input, indent = 2) {
|
|
1105
|
+
const result = validateNdjson(input);
|
|
1106
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
1107
|
+
return result.lines.map((l) => JSON.stringify(JSON.parse(l.raw), null, indent)).join("\n");
|
|
1108
|
+
}
|
|
1109
|
+
function ndjsonToJsonArray(input) {
|
|
1110
|
+
const result = validateNdjson(input);
|
|
1111
|
+
if (!result.valid) return { error: _firstNdjsonError(result) };
|
|
1112
|
+
const values = result.lines.map((l) => JSON.parse(l.raw));
|
|
1113
|
+
return JSON.stringify(values, null, 2);
|
|
1114
|
+
}
|
|
1115
|
+
function jsonArrayToNdjson(input) {
|
|
1116
|
+
let parsed;
|
|
1117
|
+
try {
|
|
1118
|
+
parsed = JSON.parse(input);
|
|
1119
|
+
} catch (e) {
|
|
1120
|
+
return { error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
1121
|
+
}
|
|
1122
|
+
if (!Array.isArray(parsed)) return { error: "Input must be a JSON array" };
|
|
1123
|
+
return parsed.map((item) => JSON.stringify(item)).join("\n");
|
|
1124
|
+
}
|
|
1067
1125
|
|
|
1068
1126
|
exports.csvToJson = csvToJson;
|
|
1069
1127
|
exports.detectDelimiter = detectDelimiter;
|
|
1070
1128
|
exports.envToExport = envToExport;
|
|
1071
1129
|
exports.envToJson = envToJson;
|
|
1130
|
+
exports.formatNdjson = formatNdjson;
|
|
1072
1131
|
exports.formatToml = formatToml;
|
|
1073
1132
|
exports.formatXml = formatXml;
|
|
1074
1133
|
exports.getSection = getSection;
|
|
@@ -1077,11 +1136,14 @@ exports.getTomlStats = getTomlStats;
|
|
|
1077
1136
|
exports.getXmlStats = getXmlStats;
|
|
1078
1137
|
exports.getYamlStats = getYamlStats;
|
|
1079
1138
|
exports.iniToJson = iniToJson;
|
|
1139
|
+
exports.jsonArrayToNdjson = jsonArrayToNdjson;
|
|
1080
1140
|
exports.jsonToIni = jsonToIni;
|
|
1081
1141
|
exports.jsonToToml = jsonToToml;
|
|
1082
1142
|
exports.jsonToXml = jsonToXml;
|
|
1143
|
+
exports.minifyNdjson = minifyNdjson;
|
|
1083
1144
|
exports.minifyToml = minifyToml;
|
|
1084
1145
|
exports.minifyXml = minifyXml;
|
|
1146
|
+
exports.ndjsonToJsonArray = ndjsonToJsonArray;
|
|
1085
1147
|
exports.parseCsv = parseCsv;
|
|
1086
1148
|
exports.parseEnv = parseEnv;
|
|
1087
1149
|
exports.parseIni = parseIni;
|
|
@@ -1091,6 +1153,7 @@ exports.toCsvString = toCsvString;
|
|
|
1091
1153
|
exports.tomlToJson = tomlToJson;
|
|
1092
1154
|
exports.validateEnvKey = validateEnvKey;
|
|
1093
1155
|
exports.validateIni = validateIni;
|
|
1156
|
+
exports.validateNdjson = validateNdjson;
|
|
1094
1157
|
exports.validateToml = validateToml;
|
|
1095
1158
|
exports.validateXml = validateXml;
|
|
1096
1159
|
exports.validateYaml = validateYaml;
|
package/dist/tools/data.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as CsvParseResult, E as EnvEntry, a as EnvParseResult, I as IniSection, P as ParseOptions,
|
|
1
|
+
export { C as CsvParseResult, E as EnvEntry, a as EnvParseResult, I as IniSection, N as NdjsonLineResult, b as NdjsonValidateResult, P as ParseOptions, c as ParsedIni, T as TomlFormatResult, V as ValidationResult, X as XmlFormatResult, e as XmlToJsonOptions, f as csvToJson, g as detectDelimiter, h as envToExport, i as envToJson, j as formatNdjson, k as formatToml, l as formatXml, m as getSection, n as getSectionNames, o as getTomlStats, p as getXmlStats, q as getYamlStats, r as iniToJson, s as jsonArrayToNdjson, t as jsonToIni, u as jsonToToml, v as jsonToXml, w as minifyNdjson, x as minifyToml, y as minifyXml, z as ndjsonToJsonArray, A as parseCsv, B as parseEnv, D as parseIni, F as parseXmlToObject, G as stringifyIni, H as toCsvString, J as tomlToJson, K as validateEnvKey, L as validateIni, M as validateNdjson, O as validateToml, Q as validateXml, R as validateYaml, S as xmlToJson } from '../data-CakDxAcT.cjs';
|
package/dist/tools/data.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as CsvParseResult, E as EnvEntry, a as EnvParseResult, I as IniSection, P as ParseOptions,
|
|
1
|
+
export { C as CsvParseResult, E as EnvEntry, a as EnvParseResult, I as IniSection, N as NdjsonLineResult, b as NdjsonValidateResult, P as ParseOptions, c as ParsedIni, T as TomlFormatResult, V as ValidationResult, X as XmlFormatResult, e as XmlToJsonOptions, f as csvToJson, g as detectDelimiter, h as envToExport, i as envToJson, j as formatNdjson, k as formatToml, l as formatXml, m as getSection, n as getSectionNames, o as getTomlStats, p as getXmlStats, q as getYamlStats, r as iniToJson, s as jsonArrayToNdjson, t as jsonToIni, u as jsonToToml, v as jsonToXml, w as minifyNdjson, x as minifyToml, y as minifyXml, z as ndjsonToJsonArray, A as parseCsv, B as parseEnv, D as parseIni, F as parseXmlToObject, G as stringifyIni, H as toCsvString, J as tomlToJson, K as validateEnvKey, L as validateIni, M as validateNdjson, O as validateToml, Q as validateXml, R as validateYaml, S as xmlToJson } from '../data-CakDxAcT.js';
|
package/dist/tools/data.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { csvToJson, detectDelimiter, envToExport, envToJson, formatToml, formatXml, getSection, getSectionNames, getTomlStats, getXmlStats, getYamlStats, iniToJson, jsonToIni, jsonToToml, jsonToXml, minifyToml, minifyXml, parseCsv, parseEnv, parseIni, parseXmlToObject, stringifyIni, toCsvString, tomlToJson, validateEnvKey, validateIni, validateToml, validateXml, validateYaml, xmlToJson } from '../chunk-
|
|
1
|
+
export { csvToJson, detectDelimiter, envToExport, envToJson, formatNdjson, formatToml, formatXml, getSection, getSectionNames, getTomlStats, getXmlStats, getYamlStats, iniToJson, jsonArrayToNdjson, jsonToIni, jsonToToml, jsonToXml, minifyNdjson, minifyToml, minifyXml, ndjsonToJsonArray, parseCsv, parseEnv, parseIni, parseXmlToObject, stringifyIni, toCsvString, tomlToJson, validateEnvKey, validateIni, validateNdjson, validateToml, validateXml, validateYaml, xmlToJson } from '../chunk-DNCOIO5N.js';
|
|
2
2
|
import '../chunk-MLKGABMK.js';
|
package/dist/tools/network.cjs
CHANGED
|
@@ -1349,6 +1349,64 @@ function validateHeaderValue(name, value) {
|
|
|
1349
1349
|
}
|
|
1350
1350
|
return { valid: true };
|
|
1351
1351
|
}
|
|
1352
|
+
function parseHar(input) {
|
|
1353
|
+
if (!input || !input.trim()) {
|
|
1354
|
+
return { error: "Input is empty" };
|
|
1355
|
+
}
|
|
1356
|
+
let data;
|
|
1357
|
+
try {
|
|
1358
|
+
data = JSON.parse(input);
|
|
1359
|
+
} catch (e) {
|
|
1360
|
+
return { error: `Invalid JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
1361
|
+
}
|
|
1362
|
+
if (typeof data !== "object" || data === null || !("log" in data)) {
|
|
1363
|
+
return { error: 'Not a valid HAR file: missing "log" property' };
|
|
1364
|
+
}
|
|
1365
|
+
const log = data.log;
|
|
1366
|
+
if (typeof log !== "object" || log === null || !Array.isArray(log.entries)) {
|
|
1367
|
+
return { error: 'Not a valid HAR file: "log.entries" must be an array' };
|
|
1368
|
+
}
|
|
1369
|
+
const logObj = log;
|
|
1370
|
+
const entries = [];
|
|
1371
|
+
const methods = {};
|
|
1372
|
+
const statusCodes = {};
|
|
1373
|
+
let totalSize = 0;
|
|
1374
|
+
let totalTime = 0;
|
|
1375
|
+
let failedRequests = 0;
|
|
1376
|
+
for (const raw of logObj.entries) {
|
|
1377
|
+
if (typeof raw !== "object" || raw === null) continue;
|
|
1378
|
+
const e = raw;
|
|
1379
|
+
const request = e.request ?? {};
|
|
1380
|
+
const response = e.response ?? {};
|
|
1381
|
+
const content = response.content ?? {};
|
|
1382
|
+
const method = typeof request.method === "string" ? request.method : "GET";
|
|
1383
|
+
const url = typeof request.url === "string" ? request.url : "";
|
|
1384
|
+
const status = typeof response.status === "number" ? response.status : 0;
|
|
1385
|
+
const statusText = typeof response.statusText === "string" ? response.statusText : "";
|
|
1386
|
+
const httpVersion = typeof response.httpVersion === "string" ? response.httpVersion : "";
|
|
1387
|
+
const mimeType = typeof content.mimeType === "string" ? content.mimeType : "";
|
|
1388
|
+
const size = typeof content.size === "number" && content.size > 0 ? content.size : 0;
|
|
1389
|
+
const time = typeof e.time === "number" ? e.time : 0;
|
|
1390
|
+
const startedDateTime = typeof e.startedDateTime === "string" ? e.startedDateTime : "";
|
|
1391
|
+
entries.push({ method, url, status, statusText, httpVersion, mimeType, size, time, startedDateTime });
|
|
1392
|
+
methods[method] = (methods[method] ?? 0) + 1;
|
|
1393
|
+
if (status > 0) statusCodes[String(status)] = (statusCodes[String(status)] ?? 0) + 1;
|
|
1394
|
+
totalSize += size;
|
|
1395
|
+
totalTime += time;
|
|
1396
|
+
if (status === 0 || status >= 400) failedRequests++;
|
|
1397
|
+
}
|
|
1398
|
+
const totalRequests = entries.length;
|
|
1399
|
+
const avgTime = totalRequests > 0 ? Math.round(totalTime / totalRequests * 100) / 100 : 0;
|
|
1400
|
+
return {
|
|
1401
|
+
version: typeof logObj.version === "string" ? logObj.version : "",
|
|
1402
|
+
creator: {
|
|
1403
|
+
name: typeof logObj.creator?.name === "string" ? logObj.creator.name : "",
|
|
1404
|
+
version: typeof logObj.creator?.version === "string" ? logObj.creator.version : ""
|
|
1405
|
+
},
|
|
1406
|
+
entries,
|
|
1407
|
+
summary: { totalRequests, totalSize, totalTime, avgTime, failedRequests, methods, statusCodes }
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1352
1410
|
|
|
1353
1411
|
exports.DNS_RECORD_TYPES = DNS_RECORD_TYPES;
|
|
1354
1412
|
exports.HTTP_HEADERS = HTTP_HEADERS;
|
|
@@ -1372,6 +1430,7 @@ exports.isValidIpv4 = isValidIpv4;
|
|
|
1372
1430
|
exports.isValidIpv6 = isValidIpv6;
|
|
1373
1431
|
exports.parseDnsResponse = parseDnsResponse;
|
|
1374
1432
|
exports.parseGeoResponse = parseGeoResponse;
|
|
1433
|
+
exports.parseHar = parseHar;
|
|
1375
1434
|
exports.searchHeaders = searchHeaders;
|
|
1376
1435
|
exports.searchStatusCodes = searchStatusCodes;
|
|
1377
1436
|
exports.statusCodeToText = statusCodeToText;
|
package/dist/tools/network.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { D as DNS_RECORD_TYPES, a as DnsRecord, b as DnsRecordType, c as DnsResponse, G as GeoResult, H as HTTP_HEADERS, d as
|
|
1
|
+
export { D as DNS_RECORD_TYPES, a as DnsRecord, b as DnsRecordType, c as DnsResponse, G as GeoResult, H as HTTP_HEADERS, d as HarEntry, e as HarParseResult, f as HarSummary, g as HeaderCategory, h as HttpHeader, P as ParsedDnsResult, i as ParsedGeoResult, S as STATUS_CODES, j as StatusCode, k as buildDnsQueryUrl, l as buildGeoUrl, m as buildMapUrl, o as countryCodeToFlag, p as formatCoordinates, q as formatTtl, r as getByCategory, s as getHeader, t as getHeadersByCategory, u as getStatusByCategory, v as getStatusCode, w as isClientError, x as isServerError, y as isSuccess, z as isValidIp, A as isValidIpv4, B as isValidIpv6, C as parseDnsResponse, E as parseGeoResponse, F as parseHar, I as searchHeaders, J as searchStatusCodes, K as statusCodeToText, L as typeNumberToLabel, M as validateDomain, N as validateHeaderName, O as validateHeaderValue } from '../network-DwyAjwJS.cjs';
|
package/dist/tools/network.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { D as DNS_RECORD_TYPES, a as DnsRecord, b as DnsRecordType, c as DnsResponse, G as GeoResult, H as HTTP_HEADERS, d as
|
|
1
|
+
export { D as DNS_RECORD_TYPES, a as DnsRecord, b as DnsRecordType, c as DnsResponse, G as GeoResult, H as HTTP_HEADERS, d as HarEntry, e as HarParseResult, f as HarSummary, g as HeaderCategory, h as HttpHeader, P as ParsedDnsResult, i as ParsedGeoResult, S as STATUS_CODES, j as StatusCode, k as buildDnsQueryUrl, l as buildGeoUrl, m as buildMapUrl, o as countryCodeToFlag, p as formatCoordinates, q as formatTtl, r as getByCategory, s as getHeader, t as getHeadersByCategory, u as getStatusByCategory, v as getStatusCode, w as isClientError, x as isServerError, y as isSuccess, z as isValidIp, A as isValidIpv4, B as isValidIpv6, C as parseDnsResponse, E as parseGeoResponse, F as parseHar, I as searchHeaders, J as searchStatusCodes, K as statusCodeToText, L as typeNumberToLabel, M as validateDomain, N as validateHeaderName, O as validateHeaderValue } from '../network-DwyAjwJS.js';
|
package/dist/tools/network.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { DNS_RECORD_TYPES, HTTP_HEADERS, STATUS_CODES, buildDnsQueryUrl, buildGeoUrl, buildMapUrl, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, parseDnsResponse, parseGeoResponse, searchHeaders, searchStatusCodes, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue } from '../chunk-
|
|
1
|
+
export { DNS_RECORD_TYPES, HTTP_HEADERS, STATUS_CODES, buildDnsQueryUrl, buildGeoUrl, buildMapUrl, countryCodeToFlag, formatCoordinates, formatTtl, getByCategory, getHeader, getHeadersByCategory, getStatusByCategory, getStatusCode, isClientError, isServerError, isSuccess, isValidIp, isValidIpv4, isValidIpv6, parseDnsResponse, parseGeoResponse, parseHar, searchHeaders, searchStatusCodes, statusCodeToText, typeNumberToLabel, validateDomain, validateHeaderName, validateHeaderValue } from '../chunk-V5JKVDBA.js';
|
|
2
2
|
import '../chunk-MLKGABMK.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utilix-tech/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "140+ developer utility tools for Node.js: JSON, encoding, hashing, color, CSS, network and more. Runs locally, no API key required.",
|
|
5
5
|
"author": "Utilix <hello@utilix.tech>",
|
|
6
6
|
"license": "MIT",
|