mazey 4.9.3 → 4.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/url.d.ts DELETED
@@ -1,394 +0,0 @@
1
- import type { SingleValueUrlParams } from "./typing";
2
- /**
3
- * Get the query param's value of the current Web URL(`location.search`).
4
- *
5
- * Usage:
6
- *
7
- * ```javascript
8
- * import { getQueryParam } from "mazey";
9
- *
10
- * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
11
- * // ?t1=1&t2=2&t3=3&t4=4
12
- * const p1 = getQueryParam("t3");
13
- * const p2 = getQueryParam("t4");
14
- * console.log(p1, p2);
15
- * ```
16
- *
17
- * Output:
18
- *
19
- * ```text
20
- * 3 4
21
- * ```
22
- *
23
- * @param {string} param Query param.
24
- * @returns {string} value
25
- * @category URL
26
- */
27
- export declare function getQueryParam(param: string): string;
28
- /**
29
- * Get the all query params of the current Web URL(`location.search`).
30
- *
31
- * Usage:
32
- *
33
- * ```javascript
34
- * import { getAllQueryParams } from "mazey";
35
- *
36
- * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
37
- * // ?t1=1&t2=2&t3=3&t4=4
38
- * const ret = getAllQueryParams();
39
- * console.log(ret);
40
- * ```
41
- *
42
- * Output:
43
- *
44
- * ```text
45
- * { t1: "1", t2: "2", t3: "3", t4: "4" }
46
- * ```
47
- *
48
- * @param {string} url Optional, The URL string.
49
- * @returns {object} The query params object.
50
- * @category URL
51
- */
52
- export declare function getAllQueryParams(url?: string): SingleValueUrlParams;
53
- /**
54
- * Returns the value of the specified query parameter in the input URL.
55
- *
56
- * Usage:
57
- *
58
- * ```javascript
59
- * import { getUrlParam } from "mazey";
60
- *
61
- * const p1 = getUrlParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t3");
62
- * const p2 = getUrlParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t4");
63
- * console.log(p1, p2);
64
- * ```
65
- *
66
- * Output:
67
- *
68
- * ```text
69
- * 3 4
70
- * ```
71
- *
72
- * @param {string} url The URL string.
73
- * @param {string} param The query parameter to retrieve the value for.
74
- * @param {object} options The options object.
75
- * @param {boolean} options.returnArray Whether to return an array of values for the specified query parameter. Default is false.
76
- * @returns {string|string[]} The value of the specified query parameter, or an empty string if the parameter is not found.
77
- * @category URL
78
- */
79
- export declare function getUrlParam(url: string, param: string, options?: {
80
- returnArray?: boolean;
81
- }): string | string[] | null;
82
- /**
83
- * Update the query param's value of the input URL.
84
- *
85
- * Usage:
86
- *
87
- * ```javascript
88
- * import { updateQueryParam } from "mazey";
89
- *
90
- * const ret1 = updateQueryParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t3", "three");
91
- * const ret2 = updateQueryParam("http://example.com/?t1=1&t2=2&t3=3&t4=4", "t4", "four");
92
- * console.log(ret1);
93
- * console.log(ret2);
94
- * ```
95
- *
96
- * Output:
97
- *
98
- * ```text
99
- * http://example.com/?t1=1&t2=2&t3=three&t4=4
100
- * http://example.com/?t1=1&t2=2&t3=3&t4=four
101
- * ```
102
- *
103
- * @param {string} url URL string.
104
- * @param {string} param Query param.
105
- * @param {string} value Param's value.
106
- * @returns {string} URL.
107
- * @category URL
108
- */
109
- export declare function updateQueryParam(url: string, param: string, value: string): string;
110
- /**
111
- * Get the hash query param's value of the current Web URL(`location.hash`).
112
- *
113
- * Usage:
114
- *
115
- * ```javascript
116
- * import { getHashQueryParam } from "mazey";
117
- *
118
- * // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
119
- * // #2333?t1=1&t2=2&t3=3&t4=4
120
- * const p1 = getHashQueryParam("t3");
121
- * const p2 = getHashQueryParam("t4");
122
- * console.log(p1, p2);
123
- * ```
124
- *
125
- * Output:
126
- *
127
- * ```text
128
- * 3 4
129
- * ```
130
- *
131
- * @param {string} param Query param.
132
- * @returns {string} value
133
- * @category URL
134
- */
135
- export declare function getHashQueryParam(param: string): string;
136
- /**
137
- * Get the domain of URL, and other params.
138
- *
139
- * Usage:
140
- *
141
- * ```javascript
142
- * import { getDomain } from "mazey";
143
- *
144
- * const ret1 = getDomain("http://example.com/?t1=1&t2=2&t3=3&t4=4");
145
- * const ret2 = getDomain("http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4", ["hostname", "pathname"]);
146
- * const ret3 = getDomain("http://example.com:7890/test/thanks", ["hostname"]);
147
- * const ret4 = getDomain("http://example.com:7890/test/thanks", ["host"]); // With Port
148
- * const ret5 = getDomain("http://example.com:7890/test/thanks", ["origin"]);
149
- * const ret6 = getDomain("http://example.com:7890/test/thanks?id=1", ["origin", "pathname", "search"]);
150
- * console.log(ret1);
151
- * console.log(ret2);
152
- * console.log(ret3);
153
- * console.log(ret4);
154
- * console.log(ret5);
155
- * console.log(ret6);
156
- * ```
157
- *
158
- * Output:
159
- *
160
- * ```text
161
- * example.com
162
- * example.com/test/thanks
163
- * example.com
164
- * example.com:7890
165
- * http://example.com:7890
166
- * http://example.com:7890/test/thanks?id=1
167
- * ```
168
- *
169
- * @param {string} url
170
- * @param {array} rules Object.keys(location), ["href", "origin", "protocol", "host", "hostname", "port", "pathname", "search", "hash"], ["hostname", "pathname"] = "km.mazey.net/plugins/servlet/mobile"
171
- * @category URL
172
- */
173
- export declare function getDomain(url: string, rules?: string[]): string;
174
- /**
175
- * Checks if the given string is a valid URL, including **scheme URLs**.
176
- *
177
- * Usage:
178
- *
179
- * ```javascript
180
- * import { isValidUrl } from "mazey";
181
- *
182
- * const ret1 = isValidUrl("https://www.example.com");
183
- * const ret2 = isValidUrl("http://example.com/path/exx/ss");
184
- * const ret3 = isValidUrl("https://www.example.com/?q=hello&age=24#world");
185
- * const ret4 = isValidUrl("http://www.example.com/#world?id=9");
186
- * const ret5 = isValidUrl("ftp://example.com");
187
- * console.log(ret1, ret2, ret3, ret4, ret5);
188
- * ```
189
- *
190
- * Output:
191
- *
192
- * ```text
193
- * true true true true true
194
- * ```
195
- *
196
- * @remarks
197
- * If you are specifically checking for HTTP/HTTPS URLs, it is recommended to use the `isValidHttpUrl` function instead.
198
- * The `isValidUrl` function matches all scheme URLs, including FTP and other non-HTTP schemes.
199
- *
200
- * @param url - The URL to check.
201
- * @returns Returns `true` if the given string is a valid URL, else `false`.
202
- * @category URL
203
- */
204
- export declare function isValidUrl(url: string): boolean;
205
- /**
206
- * Check if the given string is a valid HTTP/HTTPS URL.
207
- *
208
- * Usage:
209
- *
210
- * ```javascript
211
- * import { isValidHttpUrl } from "mazey";
212
- *
213
- * const ret1 = isValidHttpUrl("https://www.example.com");
214
- * const ret2 = isValidHttpUrl("http://example.com/path/exx/ss");
215
- * const ret3 = isValidHttpUrl("https://www.example.com/?q=hello&age=24#world");
216
- * const ret4 = isValidHttpUrl("http://www.example.com/#world?id=9");
217
- * const ret5 = isValidHttpUrl("//example.com/a/b/c?q=1", { strict: false });
218
- * const ret6 = isValidHttpUrl("ftp://example.com");
219
- * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
220
- * ```
221
- *
222
- * Output:
223
- *
224
- * ```text
225
- * true true true true true false
226
- * ```
227
- *
228
- * @param url
229
- * @param options.strict - If `true`, the function only matches standard HTTP/HTTPS URLs. Default is `true`. If `false`, the function also matches protocol-relative URLs, such as `//example.com`.
230
- * @returns {boolean} Return true if the given string is a valid HTTP/HTTPS URL.
231
- * @category URL
232
- */
233
- export declare function isValidHttpUrl(url: string, options?: {
234
- strict: boolean;
235
- }): boolean;
236
- /**
237
- * EN: Get the file type of the url.
238
- *
239
- * ZH: 获取文件后缀名。
240
- *
241
- * Usage:
242
- *
243
- * ```javascript
244
- * import { getUrlFileType } from "mazey";
245
- *
246
- * const ret1 = getUrlFileType("https://example.com/a/b/c.png");
247
- * const ret2 = getUrlFileType("https://example.com/a/b/c.jpg");
248
- * const ret3 = getUrlFileType("https://example.com/a/b/c.jpeg");
249
- * const ret4 = getUrlFileType("/a/b/c.jpeg");
250
- * const ret5 = getUrlFileType("https://example.com/a/b/c.v/a");
251
- * console.log(ret1, ret2, ret3, ret4, ret5);
252
- * ```
253
- *
254
- * Output:
255
- *
256
- * ```text
257
- * png jpg jpeg jpeg ""
258
- * ```
259
- *
260
- * @param url
261
- * @returns
262
- * @category URL
263
- */
264
- export declare function getUrlFileType(url: string): boolean | string;
265
- /**
266
- * Retrieve a query parameter from a script URL in the browser.
267
- *
268
- * Usage:
269
- *
270
- * ```html
271
- * <script src="https://example.com/example.js?test=hello&name=mazey"></script>
272
- * ```
273
- *
274
- * ```javascript
275
- * import { getScriptQueryParam } from "mazey";
276
- *
277
- * const ret = getScriptQueryParam("test", "https://example.com/example.js");
278
- * console.log(ret);
279
- * ```
280
- *
281
- * Output:
282
- *
283
- * ```text
284
- * hello
285
- * ```
286
- *
287
- * @param param - The name of the query parameter to retrieve.
288
- * @param matchString - An optional substring to match in the script URL.
289
- * If not provided, defaults to matching the ".js" substring.
290
- * @returns The decoded value of the specified query parameter, or an empty string if no matching parameter is found.
291
- * @category URL
292
- */
293
- export declare function getScriptQueryParam(param: string, matchString?: string): string;
294
- /**
295
- * Convert an object to a query string.
296
- *
297
- * Usage:
298
- *
299
- * ```javascript
300
- * import { convertObjectToQuery } from "mazey";
301
- *
302
- * const ret = convertObjectToQuery({ t1: "1", t2: "2", t3: "3", t4: "4" });
303
- * console.log(ret);
304
- * ```
305
- *
306
- * Output:
307
- *
308
- * ```text
309
- * ?t1=1&t2=2&t3=3&t4=4
310
- * ```
311
- *
312
- * @param obj - The object to convert to a query string.
313
- * @returns The query string.
314
- * @category URL
315
- */
316
- export declare function convertObjectToQuery(obj: {
317
- [key: string]: string;
318
- }): string;
319
- /**
320
- * Convert an HTTP URL to an HTTPS URL.
321
- *
322
- * Usage:
323
- *
324
- * ```javascript
325
- * import { convertHttpToHttps } from "mazey";
326
- *
327
- * const ret = convertHttpToHttps("http://example.com");
328
- * console.log(ret);
329
- * ```
330
- *
331
- * Output:
332
- *
333
- * ```text
334
- * https://example.com
335
- * ```
336
- *
337
- * @param url - The HTTP URL to convert to HTTPS.
338
- * @returns The HTTPS URL.
339
- * @category URL
340
- */
341
- export declare function convertHttpToHttps(url: string): string;
342
- /**
343
- * Alias of `convertHttpToHttps`.
344
- *
345
- * @hidden
346
- */
347
- export declare function replaceHttp(url: string): string;
348
- /**
349
- * Get the host of the URL.
350
- *
351
- * Usage:
352
- *
353
- * ```javascript
354
- * import { getUrlHost } from "mazey";
355
- *
356
- * const ret = getUrlHost("https://example.com/path/to/page");
357
- * console.log(ret);
358
- * ```
359
- *
360
- * Output:
361
- *
362
- * ```text
363
- * example.com
364
- * ```
365
- *
366
- * @param url - The URL to get the host from.
367
- * @returns The host of the URL.
368
- * @category URL
369
- */
370
- export declare function getUrlHost(url: string): string;
371
- /**
372
- * Get the path of the URL.
373
- *
374
- * Usage:
375
- *
376
- * ```javascript
377
- * import { getUrlPath } from "mazey";
378
- *
379
- * const ret = getUrlPath("https://example.com/path/to/page");
380
- * console.log(ret);
381
- * ```
382
- *
383
- * Output:
384
- *
385
- * ```text
386
- * /path/to/page
387
- * ```
388
- *
389
- * @param url - The URL to get the path from.
390
- * @returns The path of the URL.
391
- * @category URL
392
- */
393
- export declare function getUrlPath(url: string): string;
394
- //# sourceMappingURL=url.d.ts.map
package/lib/url.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOnD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAW,GAAG,oBAAoB,CAYxE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,WAAW,CAAC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