@robinpath/cli 1.73.0 → 1.75.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 +111 -111
- package/dist/cli.mjs +344 -301
- package/modules/_helpers.js +33 -33
- package/modules/assert.js +270 -270
- package/modules/buffer.js +245 -245
- package/modules/child.js +176 -176
- package/modules/crypto.js +352 -352
- package/modules/dns.js +146 -146
- package/modules/events.js +174 -174
- package/modules/file.js +361 -361
- package/modules/http.js +268 -268
- package/modules/index.js +76 -76
- package/modules/net.js +189 -189
- package/modules/os.js +219 -219
- package/modules/path.js +162 -162
- package/modules/process.js +214 -214
- package/modules/stream.js +322 -322
- package/modules/string_decoder.js +106 -106
- package/modules/timer.js +167 -167
- package/modules/tls.js +264 -264
- package/modules/tty.js +169 -169
- package/modules/url.js +189 -189
- package/modules/util.js +275 -275
- package/modules/zlib.js +126 -126
- package/package.json +1 -1
package/modules/url.js
CHANGED
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native URL module for RobinPath.
|
|
3
|
-
* URL parsing, formatting, and encoding utilities.
|
|
4
|
-
*/
|
|
5
|
-
import { toStr, requireArgs } from './_helpers.js';
|
|
6
|
-
|
|
7
|
-
export const UrlFunctions = {
|
|
8
|
-
|
|
9
|
-
parse: (args) => {
|
|
10
|
-
requireArgs('url.parse', args, 1);
|
|
11
|
-
const urlStr = toStr(args[0]);
|
|
12
|
-
const u = new URL(urlStr);
|
|
13
|
-
return {
|
|
14
|
-
href: u.href,
|
|
15
|
-
protocol: u.protocol,
|
|
16
|
-
hostname: u.hostname,
|
|
17
|
-
host: u.host,
|
|
18
|
-
port: u.port || null,
|
|
19
|
-
pathname: u.pathname,
|
|
20
|
-
search: u.search,
|
|
21
|
-
hash: u.hash,
|
|
22
|
-
origin: u.origin,
|
|
23
|
-
username: u.username,
|
|
24
|
-
password: u.password
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
format: (args) => {
|
|
29
|
-
requireArgs('url.format', args, 1);
|
|
30
|
-
const obj = args[0];
|
|
31
|
-
if (typeof obj === 'string') return obj;
|
|
32
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
33
|
-
throw new Error('url.format requires a URL object or string');
|
|
34
|
-
}
|
|
35
|
-
const u = new URL(obj.href || `${obj.protocol || 'https:'}//${obj.hostname || 'localhost'}`);
|
|
36
|
-
if (obj.port) u.port = String(obj.port);
|
|
37
|
-
if (obj.pathname) u.pathname = obj.pathname;
|
|
38
|
-
if (obj.search) u.search = obj.search;
|
|
39
|
-
if (obj.hash) u.hash = obj.hash;
|
|
40
|
-
if (obj.username) u.username = obj.username;
|
|
41
|
-
if (obj.password) u.password = obj.password;
|
|
42
|
-
return u.href;
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
resolve: (args) => {
|
|
46
|
-
requireArgs('url.resolve', args, 2);
|
|
47
|
-
const base = toStr(args[0]);
|
|
48
|
-
const relative = toStr(args[1]);
|
|
49
|
-
return new URL(relative, base).href;
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
searchParams: (args) => {
|
|
53
|
-
requireArgs('url.searchParams', args, 1);
|
|
54
|
-
const urlStr = toStr(args[0]);
|
|
55
|
-
const u = new URL(urlStr);
|
|
56
|
-
const result = {};
|
|
57
|
-
for (const [key, value] of u.searchParams) {
|
|
58
|
-
result[key] = value;
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
buildQuery: (args) => {
|
|
64
|
-
requireArgs('url.buildQuery', args, 1);
|
|
65
|
-
const obj = args[0];
|
|
66
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
67
|
-
throw new Error('url.buildQuery requires an object');
|
|
68
|
-
}
|
|
69
|
-
const params = new URLSearchParams();
|
|
70
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
71
|
-
params.append(key, String(value));
|
|
72
|
-
}
|
|
73
|
-
return params.toString();
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
encode: (args) => {
|
|
77
|
-
requireArgs('url.encode', args, 1);
|
|
78
|
-
return encodeURIComponent(toStr(args[0]));
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
decode: (args) => {
|
|
82
|
-
requireArgs('url.decode', args, 1);
|
|
83
|
-
return decodeURIComponent(toStr(args[0]));
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
encodeFull: (args) => {
|
|
87
|
-
requireArgs('url.encodeFull', args, 1);
|
|
88
|
-
return encodeURI(toStr(args[0]));
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
decodeFull: (args) => {
|
|
92
|
-
requireArgs('url.decodeFull', args, 1);
|
|
93
|
-
return decodeURI(toStr(args[0]));
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
isValid: (args) => {
|
|
97
|
-
requireArgs('url.isValid', args, 1);
|
|
98
|
-
try {
|
|
99
|
-
new URL(toStr(args[0]));
|
|
100
|
-
return true;
|
|
101
|
-
} catch {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
join: (args) => {
|
|
107
|
-
requireArgs('url.join', args, 2);
|
|
108
|
-
const base = toStr(args[0]).replace(/\/+$/, '');
|
|
109
|
-
const parts = args.slice(1).map(a => toStr(a).replace(/^\/+|\/+$/g, ''));
|
|
110
|
-
return base + '/' + parts.join('/');
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export const UrlFunctionMetadata = {
|
|
115
|
-
parse: {
|
|
116
|
-
description: 'Parse a URL into components',
|
|
117
|
-
parameters: [{ name: 'url', dataType: 'string', description: 'URL string', formInputType: 'text', required: true }],
|
|
118
|
-
returnType: 'object', returnDescription: 'Object with protocol, hostname, port, pathname, search, hash', example: 'url.parse "https://example.com/path?q=1"'
|
|
119
|
-
},
|
|
120
|
-
format: {
|
|
121
|
-
description: 'Format a URL object into a string',
|
|
122
|
-
parameters: [{ name: 'urlObject', dataType: 'object', description: 'URL components object', formInputType: 'json', required: true }],
|
|
123
|
-
returnType: 'string', returnDescription: 'Formatted URL string', example: 'url.format $urlObj'
|
|
124
|
-
},
|
|
125
|
-
resolve: {
|
|
126
|
-
description: 'Resolve a relative URL against a base',
|
|
127
|
-
parameters: [
|
|
128
|
-
{ name: 'base', dataType: 'string', description: 'Base URL', formInputType: 'text', required: true },
|
|
129
|
-
{ name: 'relative', dataType: 'string', description: 'Relative URL', formInputType: 'text', required: true }
|
|
130
|
-
],
|
|
131
|
-
returnType: 'string', returnDescription: 'Resolved URL', example: 'url.resolve "https://example.com" "/path"'
|
|
132
|
-
},
|
|
133
|
-
searchParams: {
|
|
134
|
-
description: 'Extract query parameters as an object',
|
|
135
|
-
parameters: [{ name: 'url', dataType: 'string', description: 'URL string', formInputType: 'text', required: true }],
|
|
136
|
-
returnType: 'object', returnDescription: 'Key-value object of query parameters', example: 'url.searchParams "https://example.com?a=1&b=2"'
|
|
137
|
-
},
|
|
138
|
-
buildQuery: {
|
|
139
|
-
description: 'Build a query string from an object',
|
|
140
|
-
parameters: [{ name: 'params', dataType: 'object', description: 'Key-value pairs', formInputType: 'json', required: true }],
|
|
141
|
-
returnType: 'string', returnDescription: 'Query string (without ?)', example: 'url.buildQuery {"a": 1, "b": 2}'
|
|
142
|
-
},
|
|
143
|
-
encode: {
|
|
144
|
-
description: 'URL-encode a string component',
|
|
145
|
-
parameters: [{ name: 'value', dataType: 'string', description: 'String to encode', formInputType: 'text', required: true }],
|
|
146
|
-
returnType: 'string', returnDescription: 'Encoded string', example: 'url.encode "hello world"'
|
|
147
|
-
},
|
|
148
|
-
decode: {
|
|
149
|
-
description: 'URL-decode a string component',
|
|
150
|
-
parameters: [{ name: 'value', dataType: 'string', description: 'String to decode', formInputType: 'text', required: true }],
|
|
151
|
-
returnType: 'string', returnDescription: 'Decoded string', example: 'url.decode "hello%20world"'
|
|
152
|
-
},
|
|
153
|
-
encodeFull: {
|
|
154
|
-
description: 'Encode a full URI',
|
|
155
|
-
parameters: [{ name: 'uri', dataType: 'string', description: 'URI to encode', formInputType: 'text', required: true }],
|
|
156
|
-
returnType: 'string', returnDescription: 'Encoded URI', example: 'url.encodeFull "https://example.com/path with spaces"'
|
|
157
|
-
},
|
|
158
|
-
decodeFull: {
|
|
159
|
-
description: 'Decode a full URI',
|
|
160
|
-
parameters: [{ name: 'uri', dataType: 'string', description: 'URI to decode', formInputType: 'text', required: true }],
|
|
161
|
-
returnType: 'string', returnDescription: 'Decoded URI', example: 'url.decodeFull "https://example.com/path%20with%20spaces"'
|
|
162
|
-
},
|
|
163
|
-
isValid: {
|
|
164
|
-
description: 'Check if a string is a valid URL',
|
|
165
|
-
parameters: [{ name: 'url', dataType: 'string', description: 'String to check', formInputType: 'text', required: true }],
|
|
166
|
-
returnType: 'boolean', returnDescription: 'true if valid URL', example: 'url.isValid "https://example.com"'
|
|
167
|
-
},
|
|
168
|
-
join: {
|
|
169
|
-
description: 'Join URL path segments',
|
|
170
|
-
parameters: [
|
|
171
|
-
{ name: 'base', dataType: 'string', description: 'Base URL', formInputType: 'text', required: true },
|
|
172
|
-
{ name: 'segments', dataType: 'string', description: 'Path segments', formInputType: 'text', required: true }
|
|
173
|
-
],
|
|
174
|
-
returnType: 'string', returnDescription: 'Joined URL', example: 'url.join "https://api.example.com" "v1" "users"'
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
export const UrlModuleMetadata = {
|
|
179
|
-
description: 'URL parsing, formatting, encoding, and query string utilities',
|
|
180
|
-
methods: Object.keys(UrlFunctions)
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export default {
|
|
184
|
-
name: 'url',
|
|
185
|
-
functions: UrlFunctions,
|
|
186
|
-
functionMetadata: UrlFunctionMetadata,
|
|
187
|
-
moduleMetadata: UrlModuleMetadata,
|
|
188
|
-
global: false
|
|
189
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Native URL module for RobinPath.
|
|
3
|
+
* URL parsing, formatting, and encoding utilities.
|
|
4
|
+
*/
|
|
5
|
+
import { toStr, requireArgs } from './_helpers.js';
|
|
6
|
+
|
|
7
|
+
export const UrlFunctions = {
|
|
8
|
+
|
|
9
|
+
parse: (args) => {
|
|
10
|
+
requireArgs('url.parse', args, 1);
|
|
11
|
+
const urlStr = toStr(args[0]);
|
|
12
|
+
const u = new URL(urlStr);
|
|
13
|
+
return {
|
|
14
|
+
href: u.href,
|
|
15
|
+
protocol: u.protocol,
|
|
16
|
+
hostname: u.hostname,
|
|
17
|
+
host: u.host,
|
|
18
|
+
port: u.port || null,
|
|
19
|
+
pathname: u.pathname,
|
|
20
|
+
search: u.search,
|
|
21
|
+
hash: u.hash,
|
|
22
|
+
origin: u.origin,
|
|
23
|
+
username: u.username,
|
|
24
|
+
password: u.password
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
format: (args) => {
|
|
29
|
+
requireArgs('url.format', args, 1);
|
|
30
|
+
const obj = args[0];
|
|
31
|
+
if (typeof obj === 'string') return obj;
|
|
32
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
33
|
+
throw new Error('url.format requires a URL object or string');
|
|
34
|
+
}
|
|
35
|
+
const u = new URL(obj.href || `${obj.protocol || 'https:'}//${obj.hostname || 'localhost'}`);
|
|
36
|
+
if (obj.port) u.port = String(obj.port);
|
|
37
|
+
if (obj.pathname) u.pathname = obj.pathname;
|
|
38
|
+
if (obj.search) u.search = obj.search;
|
|
39
|
+
if (obj.hash) u.hash = obj.hash;
|
|
40
|
+
if (obj.username) u.username = obj.username;
|
|
41
|
+
if (obj.password) u.password = obj.password;
|
|
42
|
+
return u.href;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
resolve: (args) => {
|
|
46
|
+
requireArgs('url.resolve', args, 2);
|
|
47
|
+
const base = toStr(args[0]);
|
|
48
|
+
const relative = toStr(args[1]);
|
|
49
|
+
return new URL(relative, base).href;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
searchParams: (args) => {
|
|
53
|
+
requireArgs('url.searchParams', args, 1);
|
|
54
|
+
const urlStr = toStr(args[0]);
|
|
55
|
+
const u = new URL(urlStr);
|
|
56
|
+
const result = {};
|
|
57
|
+
for (const [key, value] of u.searchParams) {
|
|
58
|
+
result[key] = value;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
buildQuery: (args) => {
|
|
64
|
+
requireArgs('url.buildQuery', args, 1);
|
|
65
|
+
const obj = args[0];
|
|
66
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
67
|
+
throw new Error('url.buildQuery requires an object');
|
|
68
|
+
}
|
|
69
|
+
const params = new URLSearchParams();
|
|
70
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
71
|
+
params.append(key, String(value));
|
|
72
|
+
}
|
|
73
|
+
return params.toString();
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
encode: (args) => {
|
|
77
|
+
requireArgs('url.encode', args, 1);
|
|
78
|
+
return encodeURIComponent(toStr(args[0]));
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
decode: (args) => {
|
|
82
|
+
requireArgs('url.decode', args, 1);
|
|
83
|
+
return decodeURIComponent(toStr(args[0]));
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
encodeFull: (args) => {
|
|
87
|
+
requireArgs('url.encodeFull', args, 1);
|
|
88
|
+
return encodeURI(toStr(args[0]));
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
decodeFull: (args) => {
|
|
92
|
+
requireArgs('url.decodeFull', args, 1);
|
|
93
|
+
return decodeURI(toStr(args[0]));
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
isValid: (args) => {
|
|
97
|
+
requireArgs('url.isValid', args, 1);
|
|
98
|
+
try {
|
|
99
|
+
new URL(toStr(args[0]));
|
|
100
|
+
return true;
|
|
101
|
+
} catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
join: (args) => {
|
|
107
|
+
requireArgs('url.join', args, 2);
|
|
108
|
+
const base = toStr(args[0]).replace(/\/+$/, '');
|
|
109
|
+
const parts = args.slice(1).map(a => toStr(a).replace(/^\/+|\/+$/g, ''));
|
|
110
|
+
return base + '/' + parts.join('/');
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const UrlFunctionMetadata = {
|
|
115
|
+
parse: {
|
|
116
|
+
description: 'Parse a URL into components',
|
|
117
|
+
parameters: [{ name: 'url', dataType: 'string', description: 'URL string', formInputType: 'text', required: true }],
|
|
118
|
+
returnType: 'object', returnDescription: 'Object with protocol, hostname, port, pathname, search, hash', example: 'url.parse "https://example.com/path?q=1"'
|
|
119
|
+
},
|
|
120
|
+
format: {
|
|
121
|
+
description: 'Format a URL object into a string',
|
|
122
|
+
parameters: [{ name: 'urlObject', dataType: 'object', description: 'URL components object', formInputType: 'json', required: true }],
|
|
123
|
+
returnType: 'string', returnDescription: 'Formatted URL string', example: 'url.format $urlObj'
|
|
124
|
+
},
|
|
125
|
+
resolve: {
|
|
126
|
+
description: 'Resolve a relative URL against a base',
|
|
127
|
+
parameters: [
|
|
128
|
+
{ name: 'base', dataType: 'string', description: 'Base URL', formInputType: 'text', required: true },
|
|
129
|
+
{ name: 'relative', dataType: 'string', description: 'Relative URL', formInputType: 'text', required: true }
|
|
130
|
+
],
|
|
131
|
+
returnType: 'string', returnDescription: 'Resolved URL', example: 'url.resolve "https://example.com" "/path"'
|
|
132
|
+
},
|
|
133
|
+
searchParams: {
|
|
134
|
+
description: 'Extract query parameters as an object',
|
|
135
|
+
parameters: [{ name: 'url', dataType: 'string', description: 'URL string', formInputType: 'text', required: true }],
|
|
136
|
+
returnType: 'object', returnDescription: 'Key-value object of query parameters', example: 'url.searchParams "https://example.com?a=1&b=2"'
|
|
137
|
+
},
|
|
138
|
+
buildQuery: {
|
|
139
|
+
description: 'Build a query string from an object',
|
|
140
|
+
parameters: [{ name: 'params', dataType: 'object', description: 'Key-value pairs', formInputType: 'json', required: true }],
|
|
141
|
+
returnType: 'string', returnDescription: 'Query string (without ?)', example: 'url.buildQuery {"a": 1, "b": 2}'
|
|
142
|
+
},
|
|
143
|
+
encode: {
|
|
144
|
+
description: 'URL-encode a string component',
|
|
145
|
+
parameters: [{ name: 'value', dataType: 'string', description: 'String to encode', formInputType: 'text', required: true }],
|
|
146
|
+
returnType: 'string', returnDescription: 'Encoded string', example: 'url.encode "hello world"'
|
|
147
|
+
},
|
|
148
|
+
decode: {
|
|
149
|
+
description: 'URL-decode a string component',
|
|
150
|
+
parameters: [{ name: 'value', dataType: 'string', description: 'String to decode', formInputType: 'text', required: true }],
|
|
151
|
+
returnType: 'string', returnDescription: 'Decoded string', example: 'url.decode "hello%20world"'
|
|
152
|
+
},
|
|
153
|
+
encodeFull: {
|
|
154
|
+
description: 'Encode a full URI',
|
|
155
|
+
parameters: [{ name: 'uri', dataType: 'string', description: 'URI to encode', formInputType: 'text', required: true }],
|
|
156
|
+
returnType: 'string', returnDescription: 'Encoded URI', example: 'url.encodeFull "https://example.com/path with spaces"'
|
|
157
|
+
},
|
|
158
|
+
decodeFull: {
|
|
159
|
+
description: 'Decode a full URI',
|
|
160
|
+
parameters: [{ name: 'uri', dataType: 'string', description: 'URI to decode', formInputType: 'text', required: true }],
|
|
161
|
+
returnType: 'string', returnDescription: 'Decoded URI', example: 'url.decodeFull "https://example.com/path%20with%20spaces"'
|
|
162
|
+
},
|
|
163
|
+
isValid: {
|
|
164
|
+
description: 'Check if a string is a valid URL',
|
|
165
|
+
parameters: [{ name: 'url', dataType: 'string', description: 'String to check', formInputType: 'text', required: true }],
|
|
166
|
+
returnType: 'boolean', returnDescription: 'true if valid URL', example: 'url.isValid "https://example.com"'
|
|
167
|
+
},
|
|
168
|
+
join: {
|
|
169
|
+
description: 'Join URL path segments',
|
|
170
|
+
parameters: [
|
|
171
|
+
{ name: 'base', dataType: 'string', description: 'Base URL', formInputType: 'text', required: true },
|
|
172
|
+
{ name: 'segments', dataType: 'string', description: 'Path segments', formInputType: 'text', required: true }
|
|
173
|
+
],
|
|
174
|
+
returnType: 'string', returnDescription: 'Joined URL', example: 'url.join "https://api.example.com" "v1" "users"'
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const UrlModuleMetadata = {
|
|
179
|
+
description: 'URL parsing, formatting, encoding, and query string utilities',
|
|
180
|
+
methods: Object.keys(UrlFunctions)
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export default {
|
|
184
|
+
name: 'url',
|
|
185
|
+
functions: UrlFunctions,
|
|
186
|
+
functionMetadata: UrlFunctionMetadata,
|
|
187
|
+
moduleMetadata: UrlModuleMetadata,
|
|
188
|
+
global: false
|
|
189
|
+
};
|