mazey 4.0.7 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/url.d.ts ADDED
@@ -0,0 +1,246 @@
1
+ /**
2
+ * Get the query param's value of the current Web URL(`location.search`).
3
+ *
4
+ * Usage:
5
+ *
6
+ * ```javascript
7
+ * // http://example.com/?t1=1&t2=2&t3=3&t4=4#2333
8
+ * // ?t1=1&t2=2&t3=3&t4=4
9
+ * const p1 = getQueryParam('t3');
10
+ * const p2 = getQueryParam('t4');
11
+ * console.log(p1, p2);
12
+ * ```
13
+ *
14
+ * Output:
15
+ *
16
+ * ```text
17
+ * 3 4
18
+ * ```
19
+ *
20
+ * @param {string} param Query param.
21
+ * @returns {string} value
22
+ * @category URL
23
+ */
24
+ export declare function getQueryParam(param: string): string;
25
+ /**
26
+ * Returns the value of the specified query parameter in the input URL.
27
+ *
28
+ * Usage:
29
+ *
30
+ * ```javascript
31
+ * const p1 = getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3');
32
+ * const p2 = getUrlParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4');
33
+ * console.log(p1, p2);
34
+ * ```
35
+ *
36
+ * Output:
37
+ *
38
+ * ```text
39
+ * 3 4
40
+ * ```
41
+ *
42
+ * @param {string} url The URL string.
43
+ * @param {string} param The query parameter to retrieve the value for.
44
+ * @param {object} options The options object.
45
+ * @param {boolean} options.returnArray Whether to return an array of values for the specified query parameter. Default is false.
46
+ * @returns {string|string[]} The value of the specified query parameter, or an empty string if the parameter is not found.
47
+ * @category URL
48
+ */
49
+ export declare function getUrlParam(url: string, param: string, options?: {
50
+ returnArray?: boolean;
51
+ }): string | string[] | null;
52
+ /**
53
+ * Update the query param's value of the input URL.
54
+ *
55
+ * Usage:
56
+ *
57
+ * ```javascript
58
+ * const ret1 = updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't3', 'three');
59
+ * const ret2 = updateQueryParam('http://example.com/?t1=1&t2=2&t3=3&t4=4', 't4', 'four');
60
+ * console.log(ret1);
61
+ * console.log(ret2);
62
+ * ```
63
+ *
64
+ * Output:
65
+ *
66
+ * ```text
67
+ * http://example.com/?t1=1&t2=2&t3=three&t4=4
68
+ * http://example.com/?t1=1&t2=2&t3=3&t4=four
69
+ * ```
70
+ *
71
+ * @param {string} url URL string.
72
+ * @param {string} param Query param.
73
+ * @param {string} value Param's value.
74
+ * @returns {string} URL.
75
+ * @category URL
76
+ */
77
+ export declare function updateQueryParam(url: string, param: string, value: string): string;
78
+ /**
79
+ * Get the hash query param's value of the current Web URL(`location.hash`).
80
+ *
81
+ * Usage:
82
+ *
83
+ * ```javascript
84
+ * // http://example.com/?#2333?t1=1&t2=2&t3=3&t4=4
85
+ * // #2333?t1=1&t2=2&t3=3&t4=4
86
+ * const p1 = getHashQueryParam('t3');
87
+ * const p2 = getHashQueryParam('t4');
88
+ * console.log(p1, p2);
89
+ * ```
90
+ *
91
+ * Output:
92
+ *
93
+ * ```text
94
+ * 3 4
95
+ * ```
96
+ *
97
+ * @param {string} param Query param.
98
+ * @returns {string} value
99
+ * @category URL
100
+ */
101
+ export declare function getHashQueryParam(param: string): string;
102
+ /**
103
+ * Get the domain of URL, and other params.
104
+ *
105
+ * Usage:
106
+ *
107
+ * ```javascript
108
+ * const ret1 = getDomain('http://example.com/?t1=1&t2=2&t3=3&t4=4');
109
+ * const ret2 = getDomain('http://example.com/test/thanks?t1=1&t2=2&t3=3&t4=4', ['hostname', 'pathname']);
110
+ * const ret3 = getDomain('http://example.com:7890/test/thanks', ['hostname']);
111
+ * const ret4 = getDomain('http://example.com:7890/test/thanks', ['host']); // With Port
112
+ * const ret5 = getDomain('http://example.com:7890/test/thanks', ['origin']);
113
+ * const ret6 = getDomain('http://example.com:7890/test/thanks?id=1', ['origin', 'pathname', 'search']);
114
+ * console.log(ret1);
115
+ * console.log(ret2);
116
+ * console.log(ret3);
117
+ * console.log(ret4);
118
+ * console.log(ret5);
119
+ * console.log(ret6);
120
+ * ```
121
+ *
122
+ * Output:
123
+ *
124
+ * ```text
125
+ * example.com
126
+ * example.com/test/thanks
127
+ * example.com
128
+ * example.com:7890
129
+ * http://example.com:7890
130
+ * http://example.com:7890/test/thanks?id=1
131
+ * ```
132
+ *
133
+ * @param {string} url
134
+ * @param {array} rules Object.keys(location), ['href', 'origin', 'protocol', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'], ['hostname', 'pathname'] = 'km.mazey.net/plugins/servlet/mobile'
135
+ * @category URL
136
+ */
137
+ export declare function getDomain(url: string, rules?: string[]): string;
138
+ /**
139
+ * Checks if the given string is a valid URL, including **scheme URLs**.
140
+ *
141
+ * Usage:
142
+ *
143
+ * ```javascript
144
+ * const ret1 = isValidUrl('https://www.example.com');
145
+ * const ret2 = isValidUrl('http://example.com/path/exx/ss');
146
+ * const ret3 = isValidUrl('https://www.example.com/?q=hello&age=24#world');
147
+ * const ret4 = isValidUrl('http://www.example.com/#world?id=9');
148
+ * const ret5 = isValidUrl('ftp://example.com');
149
+ * console.log(ret1, ret2, ret3, ret4, ret5);
150
+ * ```
151
+ *
152
+ * Output:
153
+ *
154
+ * ```text
155
+ * true true true true true
156
+ * ```
157
+ *
158
+ * @remarks
159
+ * If you are specifically checking for HTTP/HTTPS URLs, it is recommended to use the `isValidHttpUrl` function instead.
160
+ * The `isValidUrl` function matches all scheme URLs, including FTP and other non-HTTP schemes.
161
+ *
162
+ * @param url - The URL to check.
163
+ * @returns Returns `true` if the given string is a valid URL, else `false`.
164
+ * @category URL
165
+ */
166
+ export declare function isValidUrl(url: string): boolean;
167
+ /**
168
+ * Check if the given string is a valid HTTP/HTTPS URL.
169
+ *
170
+ * Usage:
171
+ *
172
+ * ```javascript
173
+ * const ret1 = isValidHttpUrl('https://www.example.com');
174
+ * const ret2 = isValidHttpUrl('http://example.com/path/exx/ss');
175
+ * const ret3 = isValidHttpUrl('https://www.example.com/?q=hello&age=24#world');
176
+ * const ret4 = isValidHttpUrl('http://www.example.com/#world?id=9');
177
+ * const ret5 = isValidHttpUrl('//example.com/a/b/c?q=1', { strict: false });
178
+ * const ret6 = isValidHttpUrl('ftp://example.com');
179
+ * console.log(ret1, ret2, ret3, ret4, ret5, ret6);
180
+ * ```
181
+ *
182
+ * Output:
183
+ *
184
+ * ```text
185
+ * true true true true true false
186
+ * ```
187
+ *
188
+ * @param url
189
+ * @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`.
190
+ * @returns {boolean} Return true if the given string is a valid HTTP/HTTPS URL.
191
+ * @category URL
192
+ */
193
+ export declare function isValidHttpUrl(url: string, options?: {
194
+ strict: boolean;
195
+ }): boolean;
196
+ /**
197
+ * EN: Get the file type of the url.
198
+ *
199
+ * ZH: 获取文件后缀名
200
+ *
201
+ * Usage:
202
+ *
203
+ * ```javascript
204
+ * const ret1 = getUrlFileType('https://example.com/a/b/c.png');
205
+ * const ret2 = getUrlFileType('https://example.com/a/b/c.jpg');
206
+ * const ret3 = getUrlFileType('https://example.com/a/b/c.jpeg');
207
+ * const ret4 = getUrlFileType('/a/b/c.jpeg');
208
+ * const ret5 = getUrlFileType('https://example.com/a/b/c.v/a');
209
+ * console.log(ret1, ret2, ret3, ret4, ret5);
210
+ * ```
211
+ *
212
+ * Output:
213
+ *
214
+ * ```text
215
+ * png jpg jpeg jpeg ''
216
+ * ```
217
+ *
218
+ * @param url
219
+ * @returns
220
+ * @category URL
221
+ */
222
+ export declare function getUrlFileType(url: string): boolean | string;
223
+ /**
224
+ * Retrieve a query parameter from a script URL in the browser.
225
+ *
226
+ * Usage:
227
+ *
228
+ * ```javascript
229
+ * const ret = getScriptQueryParam('test', 'https://example.com/example.js');
230
+ * console.log(ret);
231
+ * ```
232
+ *
233
+ * Output:
234
+ *
235
+ * ```text
236
+ * hello
237
+ * ```
238
+ *
239
+ * @param param - The name of the query parameter to retrieve.
240
+ * @param matchString - An optional substring to match in the script URL.
241
+ * If not provided, defaults to matching the ".js" substring.
242
+ * @returns The decoded value of the specified query parameter, or an empty string if no matching parameter is found.
243
+ * @category URL
244
+ */
245
+ export declare function getScriptQueryParam(param: string, matchString?: string): string;
246
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQnD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CA0BzH;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAclF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,WAAiB,GAAG,MAAM,CAOrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,MAAM,EAAE,OAAO,CAAA;CAAqB,GAAG,OAAO,CAMpG;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAa5D;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,SAAK,GAAG,MAAM,CAgB3E"}