@crawlee/utils 4.0.0-beta.8 → 4.0.0-beta.80
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 +17 -13
- package/index.d.ts +4 -5
- package/index.js +3 -4
- package/internals/blocked.d.ts +0 -1
- package/internals/blocked.js +0 -1
- package/internals/cheerio.d.ts +3 -2
- package/internals/cheerio.js +4 -5
- package/internals/chunk.d.ts +0 -1
- package/internals/chunk.js +0 -1
- package/internals/debug.d.ts +11 -1
- package/internals/debug.js +34 -1
- package/internals/extract-urls.d.ts +5 -1
- package/internals/extract-urls.js +8 -5
- package/internals/general.d.ts +17 -15
- package/internals/general.js +44 -83
- package/internals/iterables.d.ts +126 -0
- package/internals/iterables.js +230 -0
- package/internals/open_graph_parser.d.ts +2 -3
- package/internals/open_graph_parser.js +8 -9
- package/internals/robots.d.ts +20 -4
- package/internals/robots.js +31 -33
- package/internals/sitemap.d.ts +64 -7
- package/internals/sitemap.js +174 -34
- package/internals/social.d.ts +1 -2
- package/internals/social.js +7 -5
- package/internals/typedefs.d.ts +0 -1
- package/internals/typedefs.js +0 -1
- package/internals/url.d.ts +1 -2
- package/internals/url.js +1 -2
- package/package.json +6 -6
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/internals/blocked.d.ts.map +0 -1
- package/internals/blocked.js.map +0 -1
- package/internals/cheerio.d.ts.map +0 -1
- package/internals/cheerio.js.map +0 -1
- package/internals/chunk.d.ts.map +0 -1
- package/internals/chunk.js.map +0 -1
- package/internals/debug.d.ts.map +0 -1
- package/internals/debug.js.map +0 -1
- package/internals/extract-urls.d.ts.map +0 -1
- package/internals/extract-urls.js.map +0 -1
- package/internals/general.d.ts.map +0 -1
- package/internals/general.js.map +0 -1
- package/internals/memory-info.d.ts +0 -26
- package/internals/memory-info.d.ts.map +0 -1
- package/internals/memory-info.js +0 -131
- package/internals/memory-info.js.map +0 -1
- package/internals/open_graph_parser.d.ts.map +0 -1
- package/internals/open_graph_parser.js.map +0 -1
- package/internals/robots.d.ts.map +0 -1
- package/internals/robots.js.map +0 -1
- package/internals/sitemap.d.ts.map +0 -1
- package/internals/sitemap.js.map +0 -1
- package/internals/social.d.ts.map +0 -1
- package/internals/social.js.map +0 -1
- package/internals/systemInfoV2/cpu-info.d.ts +0 -64
- package/internals/systemInfoV2/cpu-info.d.ts.map +0 -1
- package/internals/systemInfoV2/cpu-info.js +0 -211
- package/internals/systemInfoV2/cpu-info.js.map +0 -1
- package/internals/systemInfoV2/memory-info.d.ts +0 -28
- package/internals/systemInfoV2/memory-info.d.ts.map +0 -1
- package/internals/systemInfoV2/memory-info.js +0 -118
- package/internals/systemInfoV2/memory-info.js.map +0 -1
- package/internals/systemInfoV2/ps-tree.d.ts +0 -18
- package/internals/systemInfoV2/ps-tree.d.ts.map +0 -1
- package/internals/systemInfoV2/ps-tree.js +0 -145
- package/internals/systemInfoV2/ps-tree.js.map +0 -1
- package/internals/typedefs.d.ts.map +0 -1
- package/internals/typedefs.js.map +0 -1
- package/internals/url.d.ts.map +0 -1
- package/internals/url.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'node:child_process';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { freemem, totalmem } from 'node:os';
|
|
4
|
-
import log from '@apify/log';
|
|
5
|
-
import { getCgroupsVersion, isLambda } from '../general.js';
|
|
6
|
-
import { psTree } from './ps-tree.js';
|
|
7
|
-
const MEMORY_FILE_PATHS = {
|
|
8
|
-
TOTAL: {
|
|
9
|
-
V1: '/sys/fs/cgroup/memory/memory.limit_in_bytes',
|
|
10
|
-
V2: '/sys/fs/cgroup/memory.max',
|
|
11
|
-
},
|
|
12
|
-
USED: {
|
|
13
|
-
V1: '/sys/fs/cgroup/memory/memory.usage_in_bytes',
|
|
14
|
-
V2: '/sys/fs/cgroup/memory.current',
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Returns memory statistics of the process and the system, see {@link MemoryInfo}.
|
|
19
|
-
*
|
|
20
|
-
* If the process runs inside of a container, the `getMemoryInfo` gets container memory limits,
|
|
21
|
-
* otherwise it gets system memory limits.
|
|
22
|
-
*
|
|
23
|
-
* Beware that the function is quite inefficient because it spawns a new process.
|
|
24
|
-
* Therefore you shouldn't call it too often, like more than once per second.
|
|
25
|
-
* @returns An object containing the free and used memory metrics.
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export async function getMemoryInfoV2(containerized = false) {
|
|
29
|
-
let mainProcessBytes = -1;
|
|
30
|
-
let childProcessesBytes = 0;
|
|
31
|
-
// lambda does *not* have `ps` and other command line tools
|
|
32
|
-
// required to extract memory usage.
|
|
33
|
-
if (isLambda()) {
|
|
34
|
-
// reported in bytes
|
|
35
|
-
mainProcessBytes = process.memoryUsage().rss;
|
|
36
|
-
// https://stackoverflow.com/a/55914335/129415
|
|
37
|
-
const memInfo = execSync('cat /proc/meminfo').toString();
|
|
38
|
-
const values = memInfo.split(/[\n: ]/).filter((val) => val.trim());
|
|
39
|
-
// /proc/meminfo reports in kb, not bytes, the total used memory is reported by meminfo
|
|
40
|
-
// subtract memory used by the main node process in order to infer memory used by any child processes
|
|
41
|
-
childProcessesBytes = +values[19] * 1000 - mainProcessBytes;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
// Query both root and child processes
|
|
45
|
-
const processes = await psTree(process.pid, true);
|
|
46
|
-
processes.forEach((rec) => {
|
|
47
|
-
// Obtain main process' memory separately
|
|
48
|
-
if (rec.PID === `${process.pid}`) {
|
|
49
|
-
mainProcessBytes = rec.RSS;
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
childProcessesBytes += rec.RSS;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
let totalBytes;
|
|
56
|
-
let usedBytes;
|
|
57
|
-
let freeBytes;
|
|
58
|
-
if (isLambda()) {
|
|
59
|
-
// memory size is defined in megabytes
|
|
60
|
-
totalBytes = parseInt(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE, 10) * 1000000;
|
|
61
|
-
usedBytes = mainProcessBytes + childProcessesBytes;
|
|
62
|
-
freeBytes = totalBytes - usedBytes;
|
|
63
|
-
log.debug(`lambda size of ${totalBytes} with ${freeBytes} free bytes`);
|
|
64
|
-
}
|
|
65
|
-
else if (containerized) {
|
|
66
|
-
// When running inside a container, use container memory limits
|
|
67
|
-
const cgroupsVersion = await getCgroupsVersion();
|
|
68
|
-
try {
|
|
69
|
-
if (cgroupsVersion === null) {
|
|
70
|
-
throw new Error('cgroup not available');
|
|
71
|
-
}
|
|
72
|
-
let [totalBytesStr, usedBytesStr] = await Promise.all([
|
|
73
|
-
readFile(MEMORY_FILE_PATHS.TOTAL[cgroupsVersion], 'utf8'),
|
|
74
|
-
readFile(MEMORY_FILE_PATHS.USED[cgroupsVersion], 'utf8'),
|
|
75
|
-
]);
|
|
76
|
-
// Cgroups V2 files contains newline character. Getting rid of it for better handling in later part of the code.
|
|
77
|
-
totalBytesStr = totalBytesStr.replace(/[^a-zA-Z0-9 ]/g, '');
|
|
78
|
-
usedBytesStr = usedBytesStr.replace(/[^a-zA-Z0-9 ]/g, '');
|
|
79
|
-
// Cgroups V2 contains 'max' string if memory is not limited
|
|
80
|
-
// See https://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git/tree/Documentation/admin-guide/cgroup-v2.rst (see "memory.max")
|
|
81
|
-
if (totalBytesStr === 'max') {
|
|
82
|
-
totalBytes = totalmem();
|
|
83
|
-
// Cgroups V1 is set to number related to platform and page size if memory is not limited
|
|
84
|
-
// See https://unix.stackexchange.com/q/420906
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
totalBytes = parseInt(totalBytesStr, 10);
|
|
88
|
-
const containerRunsWithUnlimitedMemory = totalBytes > Number.MAX_SAFE_INTEGER;
|
|
89
|
-
if (containerRunsWithUnlimitedMemory)
|
|
90
|
-
totalBytes = totalmem();
|
|
91
|
-
}
|
|
92
|
-
usedBytes = parseInt(usedBytesStr, 10);
|
|
93
|
-
freeBytes = totalBytes - usedBytes;
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
// log.deprecated logs a warning only once
|
|
97
|
-
log.deprecated('Your environment is containerized, but your system does not support memory cgroups. ' +
|
|
98
|
-
"If you're running containers with limited memory, memory auto-scaling will not work properly.\n\n" +
|
|
99
|
-
`Cause: ${err.message}`);
|
|
100
|
-
totalBytes = totalmem();
|
|
101
|
-
freeBytes = freemem();
|
|
102
|
-
usedBytes = totalBytes - freeBytes;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
totalBytes = totalmem();
|
|
107
|
-
freeBytes = freemem();
|
|
108
|
-
usedBytes = totalBytes - freeBytes;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
totalBytes,
|
|
112
|
-
freeBytes,
|
|
113
|
-
usedBytes,
|
|
114
|
-
mainProcessBytes,
|
|
115
|
-
childProcessesBytes,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
//# sourceMappingURL=memory-info.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory-info.js","sourceRoot":"","sources":["../../../src/internals/systemInfoV2/memory-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,MAAM,iBAAiB,GAAG;IACtB,KAAK,EAAE;QACH,EAAE,EAA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AAE,EAAE,CAAC,CAAC;gBACzC,MAAM,gCAAgC,GAAG,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;gBAC9E,IAAI,gCAAgC;oBAAE,UAAU,GAAG,QAAQ,EAAE,CAAC;YAClE,CAAC;YACD,SAAS,GAAG,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YACvC,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;QACvC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,0CAA0C;YAC1C,GAAG,CAAC,UAAU,CACV,sFAAsF;gBAClF,mGAAmG;gBACnG,UAAW,GAAa,CAAC,OAAO,EAAE,CACzC,CAAC;YACF,UAAU,GAAG,QAAQ,EAAE,CAAC;YACxB,SAAS,GAAG,OAAO,EAAE,CAAC;YACtB,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;QACvC,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,UAAU,GAAG,QAAQ,EAAE,CAAC;QACxB,SAAS,GAAG,OAAO,EAAE,CAAC;QACtB,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IACvC,CAAC;IAED,OAAO;QACH,UAAU;QACV,SAAS;QACT,SAAS;QACT,gBAAgB;QAChB,mBAAmB;KACtB,CAAC;AACN,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface ProcessInfo {
|
|
2
|
-
PPID: string;
|
|
3
|
-
PID: string;
|
|
4
|
-
STAT: string | null;
|
|
5
|
-
RSS: number;
|
|
6
|
-
COMMAND: string;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Returns a promise that resolves with an array of ProcessInfo objects representing
|
|
10
|
-
* the children of the given PID.
|
|
11
|
-
*
|
|
12
|
-
* @param pid - The PID (number or string) for which to list child processes.
|
|
13
|
-
* @param includeRoot - Optional flag. When true, include the process with the given PID if found.
|
|
14
|
-
* Defaults to false.
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export declare function psTree(pid: number | string, includeRoot?: boolean): Promise<ProcessInfo[]>;
|
|
18
|
-
//# sourceMappingURL=ps-tree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ps-tree.d.ts","sourceRoot":"","sources":["../../../src/internals/systemInfoV2/ps-tree.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACnB;AAOD;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,UAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CA+G9F"}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import * as readline from 'node:readline';
|
|
3
|
-
/**
|
|
4
|
-
* Returns a promise that resolves with an array of ProcessInfo objects representing
|
|
5
|
-
* the children of the given PID.
|
|
6
|
-
*
|
|
7
|
-
* @param pid - The PID (number or string) for which to list child processes.
|
|
8
|
-
* @param includeRoot - Optional flag. When true, include the process with the given PID if found.
|
|
9
|
-
* Defaults to false.
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export async function psTree(pid, includeRoot = false) {
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
if (typeof pid === 'number') {
|
|
15
|
-
pid = pid.toString();
|
|
16
|
-
}
|
|
17
|
-
let processLister;
|
|
18
|
-
if (process.platform === 'win32') {
|
|
19
|
-
processLister = spawn('powershell', [
|
|
20
|
-
'-NoProfile',
|
|
21
|
-
'-Command',
|
|
22
|
-
'Get-CimInstance Win32_Process | Format-Table ProcessId,ParentProcessId,WorkingSetSize,Name',
|
|
23
|
-
]);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
processLister = spawn('ps', ['-A', '-o', 'ppid,pid,stat,rss,comm']);
|
|
27
|
-
}
|
|
28
|
-
processLister.on('error', reject);
|
|
29
|
-
if (!processLister.stdout) {
|
|
30
|
-
reject(new Error('Child process stdout is null'));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
// Create a readline interface to process stdout line-by-line.
|
|
34
|
-
const rl = readline.createInterface({
|
|
35
|
-
input: processLister.stdout,
|
|
36
|
-
});
|
|
37
|
-
const rows = [];
|
|
38
|
-
let headers = null;
|
|
39
|
-
rl.on('line', (line) => {
|
|
40
|
-
const trimmed = line.trim();
|
|
41
|
-
if (trimmed === '') {
|
|
42
|
-
return; // Skip empty lines.
|
|
43
|
-
}
|
|
44
|
-
// When headers have been set, skip a dashed separator line.
|
|
45
|
-
const fields = trimmed.split(/\s+/);
|
|
46
|
-
if (headers !== null && fields.every((field) => /^-+$/.test(field))) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
// The first nonempty line is assumed to be the header row.
|
|
50
|
-
if (!headers) {
|
|
51
|
-
headers = fields.map(normalizeHeader);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Copy the fields into an array to process.
|
|
55
|
-
const columns = fields.slice();
|
|
56
|
-
// Build the process row object.
|
|
57
|
-
const row = {};
|
|
58
|
-
const hdrs = headers.slice();
|
|
59
|
-
// For all headers except the last one, assign one column per header.
|
|
60
|
-
// The last header gets all remaining columns joined (in case the command name contains spaces).
|
|
61
|
-
for (const [index, header] of hdrs.entries()) {
|
|
62
|
-
let value;
|
|
63
|
-
if (index === hdrs.length - 1) {
|
|
64
|
-
value = columns.join(' ');
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
value = columns.shift();
|
|
68
|
-
}
|
|
69
|
-
if (header === 'RSS') {
|
|
70
|
-
row[header] = Number.parseInt(value, 10);
|
|
71
|
-
if (process.platform !== 'win32') {
|
|
72
|
-
// On Unix like systems, convert RSS (in KB) to bytes.
|
|
73
|
-
row[header] *= 1024;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
row[header] = value;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// On Windows, add STAT with a null value for compatibility.
|
|
81
|
-
if (process.platform === 'win32') {
|
|
82
|
-
row.STAT = null;
|
|
83
|
-
}
|
|
84
|
-
rows.push(row);
|
|
85
|
-
});
|
|
86
|
-
rl.on('close', () => {
|
|
87
|
-
const parents = {};
|
|
88
|
-
const children = [];
|
|
89
|
-
// Seed with the provided PID.
|
|
90
|
-
parents[pid] = true;
|
|
91
|
-
// Build the list of child processes.
|
|
92
|
-
rows.forEach((proc) => {
|
|
93
|
-
// Skip the 'ps' or 'powershell' commands used by psTree to query the processes
|
|
94
|
-
if (proc.COMMAND === 'ps' || proc.COMMAND === 'powershell.exe') {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (parents[proc.PPID]) {
|
|
98
|
-
parents[proc.PID] = true;
|
|
99
|
-
children.push(proc);
|
|
100
|
-
}
|
|
101
|
-
else if (includeRoot && pid === proc.PID) {
|
|
102
|
-
children.push(proc);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
resolve(children);
|
|
106
|
-
});
|
|
107
|
-
// Also listen for errors on the stdout stream.
|
|
108
|
-
processLister.stdout.on('error', reject);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Normalizes the header names so that the rest of the code can work uniformly.
|
|
113
|
-
*
|
|
114
|
-
* On non‑Windows systems, we only adjust "COMM" to "COMMAND" (e.g. on macOS).
|
|
115
|
-
* On Windows, the headers from Get-CimInstance + Format-Table are:
|
|
116
|
-
*
|
|
117
|
-
* ProcessId, ParentProcessId, WorkingSetSize, Name
|
|
118
|
-
*
|
|
119
|
-
* which are mapped to:
|
|
120
|
-
*
|
|
121
|
-
* PID, PPID, RSS, COMMAND
|
|
122
|
-
*/
|
|
123
|
-
function normalizeHeader(str) {
|
|
124
|
-
if (process.platform !== 'win32') {
|
|
125
|
-
// macOS may output "COMM" instead of "COMMAND"
|
|
126
|
-
if (str === 'COMM')
|
|
127
|
-
return 'COMMAND';
|
|
128
|
-
return str;
|
|
129
|
-
}
|
|
130
|
-
switch (str) {
|
|
131
|
-
case 'Name':
|
|
132
|
-
return 'COMMAND';
|
|
133
|
-
case 'ParentProcessId':
|
|
134
|
-
return 'PPID';
|
|
135
|
-
case 'ProcessId':
|
|
136
|
-
return 'PID';
|
|
137
|
-
case 'Status':
|
|
138
|
-
return 'STAT';
|
|
139
|
-
case 'WorkingSetSize':
|
|
140
|
-
return 'RSS';
|
|
141
|
-
default:
|
|
142
|
-
throw new Error(`Unknown process listing header: ${str}`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=ps-tree.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ps-tree.js","sourceRoot":"","sources":["../../../src/internals/systemInfoV2/ps-tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAe1C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,GAAoB,EAAE,WAAW,GAAG,KAAK;IAClE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC1B,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;QAED,IAAI,aAA2B,CAAC;QAChC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC/B,aAAa,GAAG,KAAK,CAAC,YAAY,EAAE;gBAChC,YAAY;gBACZ,UAAU;gBACV,4FAA4F;aAC/F,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,aAA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
|
-
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../../src/internals/typedefs.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,GACV,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CACxD;AAED,cAAc;AACd,wBAAgB,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,GACV,CAAC,MAAM,CAAC,CAAC,EAAE,CACzC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typedefs.js","sourceRoot":"","sources":["../../src/internals/typedefs.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,MAAM,UAAU,OAAO,CAAe,GAAM;IACxC,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAA4B,CAAC;AAC1D,CAAC;AAED,cAAc;AACd,MAAM,UAAU,IAAI,CAAe,GAAM;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAgB,CAAC;AAC3C,CAAC"}
|
package/internals/url.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/internals/url.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAEnH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,YAAY,GAAG,SAAS,GAAG,IAAI,CA4BxF"}
|
package/internals/url.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.js","sourceRoot":"","sources":["../../src/internals/url.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,U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