@helpers4/url 2.0.0-alpha.2 → 2.0.0-alpha.21
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/LICENSE.md +150 -650
- package/README.md +13 -8
- package/lib/index.d.ts +513 -8
- package/lib/index.js +302 -68
- package/lib/index.js.map +1 -0
- package/llms.txt +519 -0
- package/meta/api.json +492 -0
- package/meta/category.json +6 -0
- package/meta/examples.json +115 -0
- package/meta/licenses.json +4 -0
- package/package.json +22 -9
package/meta/api.json
ADDED
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "url",
|
|
3
|
+
"version": "2.0.0-alpha.21",
|
|
4
|
+
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "cleanPath",
|
|
7
|
+
"kind": "function",
|
|
8
|
+
"description": "Clean an URL by removing duplicate slashes.\nThe protocol part of the URL is not modified.",
|
|
9
|
+
"since": "1.0.0",
|
|
10
|
+
"signatures": [
|
|
11
|
+
{
|
|
12
|
+
"signature": "cleanPath(url: string | null | undefined): string | null | undefined",
|
|
13
|
+
"description": "Clean an URL by removing duplicate slashes.\nThe protocol part of the URL is not modified.",
|
|
14
|
+
"params": [
|
|
15
|
+
{
|
|
16
|
+
"name": "url",
|
|
17
|
+
"type": "string | null | undefined",
|
|
18
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"returns": {
|
|
22
|
+
"type": "string | null | undefined",
|
|
23
|
+
"description": "The cleaned URL string, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"examples": [
|
|
28
|
+
{
|
|
29
|
+
"title": "Remove duplicate slashes",
|
|
30
|
+
"description": "Cleans an URL by removing duplicate slashes while preserving the protocol.",
|
|
31
|
+
"code": "cleanPath('/path//to///resource')\n// => '/path/to/resource'"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"title": "Preserve protocol",
|
|
35
|
+
"description": "The double slash after the protocol (http://) is not modified.",
|
|
36
|
+
"code": "cleanPath('http://example.com//path')\n// => 'http://example.com/path'"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"title": "Handle null and undefined",
|
|
40
|
+
"description": "Returns null for null input and undefined for undefined input.",
|
|
41
|
+
"code": "cleanPath(null) // => null\ncleanPath(undefined) // => undefined"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"sourceFile": "cleanPath.ts"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "extractPureURI",
|
|
48
|
+
"kind": "function",
|
|
49
|
+
"description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
|
|
50
|
+
"since": "1.9.0",
|
|
51
|
+
"signatures": [
|
|
52
|
+
{
|
|
53
|
+
"signature": "extractPureURI(url: string): string",
|
|
54
|
+
"description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
|
|
55
|
+
"params": [
|
|
56
|
+
{
|
|
57
|
+
"name": "url",
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "The URL string to process"
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
"returns": {
|
|
63
|
+
"type": "string",
|
|
64
|
+
"description": "The URI without query parameters and fragments, or the original value if undefined/null"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"signature": "extractPureURI(url: undefined): undefined",
|
|
69
|
+
"description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
|
|
70
|
+
"params": [
|
|
71
|
+
{
|
|
72
|
+
"name": "url",
|
|
73
|
+
"type": "undefined",
|
|
74
|
+
"description": "The URL string to process"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"returns": {
|
|
78
|
+
"type": "undefined",
|
|
79
|
+
"description": "The URI without query parameters and fragments, or the original value if undefined/null"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"signature": "extractPureURI(url: null): null",
|
|
84
|
+
"description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
|
|
85
|
+
"params": [
|
|
86
|
+
{
|
|
87
|
+
"name": "url",
|
|
88
|
+
"type": "null",
|
|
89
|
+
"description": "The URL string to process"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"returns": {
|
|
93
|
+
"type": "null",
|
|
94
|
+
"description": "The URI without query parameters and fragments, or the original value if undefined/null"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"examples": [
|
|
99
|
+
{
|
|
100
|
+
"title": "Remove query parameters and fragments",
|
|
101
|
+
"description": "Strips everything after ? or # from the URL.",
|
|
102
|
+
"code": "extractPureURI('https://example.com/path?query=1#section')\n// => 'https://example.com/path'"
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
"sourceFile": "extractPureURI.ts"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": "onlyPath",
|
|
109
|
+
"kind": "function",
|
|
110
|
+
"description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
|
|
111
|
+
"since": "1.0.0",
|
|
112
|
+
"signatures": [
|
|
113
|
+
{
|
|
114
|
+
"signature": "onlyPath(url: string): string",
|
|
115
|
+
"description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
|
|
116
|
+
"params": [
|
|
117
|
+
{
|
|
118
|
+
"name": "url",
|
|
119
|
+
"type": "string",
|
|
120
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"returns": {
|
|
124
|
+
"type": "string",
|
|
125
|
+
"description": "The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"signature": "onlyPath(url: null): null",
|
|
130
|
+
"description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
|
|
131
|
+
"params": [
|
|
132
|
+
{
|
|
133
|
+
"name": "url",
|
|
134
|
+
"type": "null",
|
|
135
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
"returns": {
|
|
139
|
+
"type": "null",
|
|
140
|
+
"description": "The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"signature": "onlyPath(url: undefined): undefined",
|
|
145
|
+
"description": "Extract only the path from an URI with optional query and fragments.\n\nFor example, all these parameters will return `/path`:\n - `/path`\n - `/path?query=thing`\n - `/path#fragment`\n - `/path?query=thing#fragment`",
|
|
146
|
+
"params": [
|
|
147
|
+
{
|
|
148
|
+
"name": "url",
|
|
149
|
+
"type": "undefined",
|
|
150
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
"returns": {
|
|
154
|
+
"type": "undefined",
|
|
155
|
+
"description": "The URL string without query and fragment, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"examples": [
|
|
160
|
+
{
|
|
161
|
+
"title": "Extract the path from a URL",
|
|
162
|
+
"description": "Strips query parameters and fragments from a URL path.",
|
|
163
|
+
"code": "onlyPath('/path?query=thing#fragment')\n// => '/path'"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"sourceFile": "onlyPath.ts"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"name": "parsePackageRepository",
|
|
170
|
+
"kind": "function",
|
|
171
|
+
"description": "Parse the `repository` field from `package.json` into a structured object.\n\nSupports all npm-specified formats:\n- **Object form**: `{ \"type\": \"git\", \"url\": \"...\", \"directory\": \"...\" }`\n- **GitHub shorthand**: `\"owner/repo\"` or `\"github:owner/repo\"`\n- **Platform shorthands**: `\"gitlab:owner/repo\"`, `\"bitbucket:owner/repo\"`\n- **Gist shorthand**: `\"gist:<id>\"`\n- **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`\n\nReturns `undefined` for `null`, `undefined`, arrays, or values that cannot\nbe matched to any recognised format.",
|
|
172
|
+
"since": "next",
|
|
173
|
+
"signatures": [
|
|
174
|
+
{
|
|
175
|
+
"signature": "parsePackageRepository(repository: unknown): PackageRepository | undefined",
|
|
176
|
+
"description": "Parse the `repository` field from `package.json` into a structured object.\n\nSupports all npm-specified formats:\n- **Object form**: `{ \"type\": \"git\", \"url\": \"...\", \"directory\": \"...\" }`\n- **GitHub shorthand**: `\"owner/repo\"` or `\"github:owner/repo\"`\n- **Platform shorthands**: `\"gitlab:owner/repo\"`, `\"bitbucket:owner/repo\"`\n- **Gist shorthand**: `\"gist:<id>\"`\n- **URL forms**: `git+https://`, `https://`, `git://`, `git@` SSH, `git+ssh://`\n\nReturns `undefined` for `null`, `undefined`, arrays, or values that cannot\nbe matched to any recognised format.",
|
|
177
|
+
"params": [
|
|
178
|
+
{
|
|
179
|
+
"name": "repository",
|
|
180
|
+
"type": "unknown",
|
|
181
|
+
"description": "The `repository` field value from `package.json`."
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"returns": {
|
|
185
|
+
"type": "PackageRepository | undefined",
|
|
186
|
+
"description": "A parsed PackageRepository object, or `undefined` if the\n input cannot be parsed."
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
"examples": [
|
|
191
|
+
{
|
|
192
|
+
"title": "Parse the npm canonical object form",
|
|
193
|
+
"description": "Parses the full object form written by npm publish.",
|
|
194
|
+
"code": "parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })\n// => { type: 'git', host: 'github', slug: 'helpers4/typescript',\n// owner: 'helpers4', repo: 'typescript', gistId: undefined, directory: undefined }"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"title": "Parse npm shorthand forms",
|
|
198
|
+
"description": "npm accepts \"owner/repo\", \"github:owner/repo\", \"gitlab:owner/repo\" etc. as shorthand.",
|
|
199
|
+
"code": "parsePackageRepository('helpers4/typescript')\n// => { host: 'github', slug: 'helpers4/typescript', owner: 'helpers4', repo: 'typescript', ... }\n\nparsePackageRepository('gitlab:myorg/myproject')\n// => { host: 'gitlab', slug: 'myorg/myproject', owner: 'myorg', repo: 'myproject', ... }\n\nparsePackageRepository('gist:11081aaa281')\n// => { host: 'gist', gistId: '11081aaa281', slug: undefined, owner: undefined, ... }"
|
|
200
|
+
}
|
|
201
|
+
],
|
|
202
|
+
"sourceFile": "parsePackageRepository.ts",
|
|
203
|
+
"relatedTypes": [
|
|
204
|
+
{
|
|
205
|
+
"name": "PackageRepository",
|
|
206
|
+
"description": "Structured representation of a parsed `repository` field from `package.json`.",
|
|
207
|
+
"typeDefinition": "interface PackageRepository {\n directory: string | undefined;\n gistId: string | undefined;\n host: string & object | \"github\" | \"gitlab\" | \"bitbucket\" | \"gist\";\n owner: string | undefined;\n repo: string | undefined;\n slug: string | undefined;\n type: string;\n}"
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"name": "relativeURLToAbsolute",
|
|
213
|
+
"kind": "function",
|
|
214
|
+
"description": "Converts a relative URL to an absolute URL using the current document base URI.",
|
|
215
|
+
"since": "1.0.0",
|
|
216
|
+
"signatures": [
|
|
217
|
+
{
|
|
218
|
+
"signature": "relativeURLToAbsolute(relativeUrl: string): string",
|
|
219
|
+
"description": "Converts a relative URL to an absolute URL using the current document base URI.",
|
|
220
|
+
"params": [
|
|
221
|
+
{
|
|
222
|
+
"name": "relativeUrl",
|
|
223
|
+
"type": "string",
|
|
224
|
+
"description": "The relative URL to convert"
|
|
225
|
+
}
|
|
226
|
+
],
|
|
227
|
+
"returns": {
|
|
228
|
+
"type": "string",
|
|
229
|
+
"description": "The absolute URL"
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
"examples": [
|
|
234
|
+
{
|
|
235
|
+
"title": "Convert a relative URL to absolute",
|
|
236
|
+
"description": "Prepends the base URI to a relative path, cleaning duplicate slashes.",
|
|
237
|
+
"code": "relativeURLToAbsolute('/api/data')\n// => 'http://localhost/api/data' (depends on document.baseURI)"
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"sourceFile": "relativeURLToAbsolute.ts"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"name": "withLeadingSlash",
|
|
244
|
+
"kind": "function",
|
|
245
|
+
"description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
246
|
+
"since": "1.0.0",
|
|
247
|
+
"signatures": [
|
|
248
|
+
{
|
|
249
|
+
"signature": "withLeadingSlash(url: string): string",
|
|
250
|
+
"description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
251
|
+
"params": [
|
|
252
|
+
{
|
|
253
|
+
"name": "url",
|
|
254
|
+
"type": "string",
|
|
255
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
"returns": {
|
|
259
|
+
"type": "string",
|
|
260
|
+
"description": "The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"signature": "withLeadingSlash(url: undefined): undefined",
|
|
265
|
+
"description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
266
|
+
"params": [
|
|
267
|
+
{
|
|
268
|
+
"name": "url",
|
|
269
|
+
"type": "undefined",
|
|
270
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
271
|
+
}
|
|
272
|
+
],
|
|
273
|
+
"returns": {
|
|
274
|
+
"type": "undefined",
|
|
275
|
+
"description": "The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"signature": "withLeadingSlash(url: null): null",
|
|
280
|
+
"description": "Adds a leading slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
281
|
+
"params": [
|
|
282
|
+
{
|
|
283
|
+
"name": "url",
|
|
284
|
+
"type": "null",
|
|
285
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
"returns": {
|
|
289
|
+
"type": "null",
|
|
290
|
+
"description": "The URL string with a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
],
|
|
294
|
+
"examples": [
|
|
295
|
+
{
|
|
296
|
+
"title": "Add a leading slash",
|
|
297
|
+
"description": "Ensures the URL starts with a forward slash.",
|
|
298
|
+
"code": "withLeadingSlash('path/to/resource')\n// => '/path/to/resource'"
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
"title": "Already has leading slash",
|
|
302
|
+
"description": "Does not add a duplicate slash.",
|
|
303
|
+
"code": "withLeadingSlash('/already/has/slash')\n// => '/already/has/slash'"
|
|
304
|
+
}
|
|
305
|
+
],
|
|
306
|
+
"sourceFile": "withLeadingSlash.ts"
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
"name": "withoutLeadingSlash",
|
|
310
|
+
"kind": "function",
|
|
311
|
+
"description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
312
|
+
"since": "1.0.0",
|
|
313
|
+
"signatures": [
|
|
314
|
+
{
|
|
315
|
+
"signature": "withoutLeadingSlash(url: string): string",
|
|
316
|
+
"description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
317
|
+
"params": [
|
|
318
|
+
{
|
|
319
|
+
"name": "url",
|
|
320
|
+
"type": "string",
|
|
321
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
322
|
+
}
|
|
323
|
+
],
|
|
324
|
+
"returns": {
|
|
325
|
+
"type": "string",
|
|
326
|
+
"description": "The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"signature": "withoutLeadingSlash(url: undefined): undefined",
|
|
331
|
+
"description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
332
|
+
"params": [
|
|
333
|
+
{
|
|
334
|
+
"name": "url",
|
|
335
|
+
"type": "undefined",
|
|
336
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
337
|
+
}
|
|
338
|
+
],
|
|
339
|
+
"returns": {
|
|
340
|
+
"type": "undefined",
|
|
341
|
+
"description": "The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"signature": "withoutLeadingSlash(url: null): null",
|
|
346
|
+
"description": "Removes the leading slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a leading slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
347
|
+
"params": [
|
|
348
|
+
{
|
|
349
|
+
"name": "url",
|
|
350
|
+
"type": "null",
|
|
351
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
"returns": {
|
|
355
|
+
"type": "null",
|
|
356
|
+
"description": "The URL string without a leading slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
],
|
|
360
|
+
"examples": [
|
|
361
|
+
{
|
|
362
|
+
"title": "Remove leading slash",
|
|
363
|
+
"description": "Strips the leading slash from a URL path.",
|
|
364
|
+
"code": "withoutLeadingSlash('/path/to/resource')\n// => 'path/to/resource'"
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
"sourceFile": "withoutLeadingSlash.ts"
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
"name": "withoutTrailingSlash",
|
|
371
|
+
"kind": "function",
|
|
372
|
+
"description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
373
|
+
"since": "1.0.0",
|
|
374
|
+
"signatures": [
|
|
375
|
+
{
|
|
376
|
+
"signature": "withoutTrailingSlash(url: string): string",
|
|
377
|
+
"description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
378
|
+
"params": [
|
|
379
|
+
{
|
|
380
|
+
"name": "url",
|
|
381
|
+
"type": "string",
|
|
382
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
383
|
+
}
|
|
384
|
+
],
|
|
385
|
+
"returns": {
|
|
386
|
+
"type": "string",
|
|
387
|
+
"description": "The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
"signature": "withoutTrailingSlash(url: undefined): undefined",
|
|
392
|
+
"description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
393
|
+
"params": [
|
|
394
|
+
{
|
|
395
|
+
"name": "url",
|
|
396
|
+
"type": "undefined",
|
|
397
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
398
|
+
}
|
|
399
|
+
],
|
|
400
|
+
"returns": {
|
|
401
|
+
"type": "undefined",
|
|
402
|
+
"description": "The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
"signature": "withoutTrailingSlash(url: null): null",
|
|
407
|
+
"description": "Removes the trailing slash `/` from the given URL if it is present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwithout a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
408
|
+
"params": [
|
|
409
|
+
{
|
|
410
|
+
"name": "url",
|
|
411
|
+
"type": "null",
|
|
412
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
413
|
+
}
|
|
414
|
+
],
|
|
415
|
+
"returns": {
|
|
416
|
+
"type": "null",
|
|
417
|
+
"description": "The URL string without a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
],
|
|
421
|
+
"examples": [
|
|
422
|
+
{
|
|
423
|
+
"title": "Remove trailing slash",
|
|
424
|
+
"description": "Strips the trailing slash from a URL path.",
|
|
425
|
+
"code": "withoutTrailingSlash('path/to/resource/')\n// => 'path/to/resource'"
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
"sourceFile": "withoutTrailingSlash.ts"
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
"name": "withTrailingSlash",
|
|
432
|
+
"kind": "function",
|
|
433
|
+
"description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
434
|
+
"since": "1.0.0",
|
|
435
|
+
"signatures": [
|
|
436
|
+
{
|
|
437
|
+
"signature": "withTrailingSlash(url: string): string",
|
|
438
|
+
"description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
439
|
+
"params": [
|
|
440
|
+
{
|
|
441
|
+
"name": "url",
|
|
442
|
+
"type": "string",
|
|
443
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
444
|
+
}
|
|
445
|
+
],
|
|
446
|
+
"returns": {
|
|
447
|
+
"type": "string",
|
|
448
|
+
"description": "The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
"signature": "withTrailingSlash(url: undefined): undefined",
|
|
453
|
+
"description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
454
|
+
"params": [
|
|
455
|
+
{
|
|
456
|
+
"name": "url",
|
|
457
|
+
"type": "undefined",
|
|
458
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
459
|
+
}
|
|
460
|
+
],
|
|
461
|
+
"returns": {
|
|
462
|
+
"type": "undefined",
|
|
463
|
+
"description": "The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
"signature": "withTrailingSlash(url: null): null",
|
|
468
|
+
"description": "Adds a trailing slash `/` to the given URL if it is not already present.\n\nThis function is useful for ensuring that URLs are properly formatted\nwith a trailing slash, which is often required in web development for\nconsistency and to avoid issues with relative paths.",
|
|
469
|
+
"params": [
|
|
470
|
+
{
|
|
471
|
+
"name": "url",
|
|
472
|
+
"type": "null",
|
|
473
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
474
|
+
}
|
|
475
|
+
],
|
|
476
|
+
"returns": {
|
|
477
|
+
"type": "null",
|
|
478
|
+
"description": "The URL string with a trailing slash, or `undefined` if the input is `undefined`, or `null` if the input is `null`."
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
],
|
|
482
|
+
"examples": [
|
|
483
|
+
{
|
|
484
|
+
"title": "Add a trailing slash",
|
|
485
|
+
"description": "Ensures the URL ends with a forward slash.",
|
|
486
|
+
"code": "withTrailingSlash('path/to/resource')\n// => 'path/to/resource/'"
|
|
487
|
+
}
|
|
488
|
+
],
|
|
489
|
+
"sourceFile": "withTrailingSlash.ts"
|
|
490
|
+
}
|
|
491
|
+
]
|
|
492
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "url",
|
|
3
|
+
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "cleanPath",
|
|
6
|
+
"examples": [
|
|
7
|
+
{
|
|
8
|
+
"title": "Remove duplicate slashes",
|
|
9
|
+
"description": "Cleans an URL by removing duplicate slashes while preserving the protocol.",
|
|
10
|
+
"code": "cleanPath('/path//to///resource')\n// => '/path/to/resource'"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"title": "Preserve protocol",
|
|
14
|
+
"description": "The double slash after the protocol (http://) is not modified.",
|
|
15
|
+
"code": "cleanPath('http://example.com//path')\n// => 'http://example.com/path'"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"title": "Handle null and undefined",
|
|
19
|
+
"description": "Returns null for null input and undefined for undefined input.",
|
|
20
|
+
"code": "cleanPath(null) // => null\ncleanPath(undefined) // => undefined"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "extractPureURI",
|
|
26
|
+
"examples": [
|
|
27
|
+
{
|
|
28
|
+
"title": "Remove query parameters and fragments",
|
|
29
|
+
"description": "Strips everything after ? or # from the URL.",
|
|
30
|
+
"code": "extractPureURI('https://example.com/path?query=1#section')\n// => 'https://example.com/path'"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "onlyPath",
|
|
36
|
+
"examples": [
|
|
37
|
+
{
|
|
38
|
+
"title": "Extract the path from a URL",
|
|
39
|
+
"description": "Strips query parameters and fragments from a URL path.",
|
|
40
|
+
"code": "onlyPath('/path?query=thing#fragment')\n// => '/path'"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "parsePackageRepository",
|
|
46
|
+
"examples": [
|
|
47
|
+
{
|
|
48
|
+
"title": "Parse the npm canonical object form",
|
|
49
|
+
"description": "Parses the full object form written by npm publish.",
|
|
50
|
+
"code": "parsePackageRepository({ type: 'git', url: 'git+https://github.com/helpers4/typescript.git' })\n// => { type: 'git', host: 'github', slug: 'helpers4/typescript',\n// owner: 'helpers4', repo: 'typescript', gistId: undefined, directory: undefined }"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"title": "Parse npm shorthand forms",
|
|
54
|
+
"description": "npm accepts \"owner/repo\", \"github:owner/repo\", \"gitlab:owner/repo\" etc. as shorthand.",
|
|
55
|
+
"code": "parsePackageRepository('helpers4/typescript')\n// => { host: 'github', slug: 'helpers4/typescript', owner: 'helpers4', repo: 'typescript', ... }\n\nparsePackageRepository('gitlab:myorg/myproject')\n// => { host: 'gitlab', slug: 'myorg/myproject', owner: 'myorg', repo: 'myproject', ... }\n\nparsePackageRepository('gist:11081aaa281')\n// => { host: 'gist', gistId: '11081aaa281', slug: undefined, owner: undefined, ... }"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "relativeURLToAbsolute",
|
|
61
|
+
"examples": [
|
|
62
|
+
{
|
|
63
|
+
"title": "Convert a relative URL to absolute",
|
|
64
|
+
"description": "Prepends the base URI to a relative path, cleaning duplicate slashes.",
|
|
65
|
+
"code": "relativeURLToAbsolute('/api/data')\n// => 'http://localhost/api/data' (depends on document.baseURI)"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "withLeadingSlash",
|
|
71
|
+
"examples": [
|
|
72
|
+
{
|
|
73
|
+
"title": "Add a leading slash",
|
|
74
|
+
"description": "Ensures the URL starts with a forward slash.",
|
|
75
|
+
"code": "withLeadingSlash('path/to/resource')\n// => '/path/to/resource'"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"title": "Already has leading slash",
|
|
79
|
+
"description": "Does not add a duplicate slash.",
|
|
80
|
+
"code": "withLeadingSlash('/already/has/slash')\n// => '/already/has/slash'"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"name": "withoutLeadingSlash",
|
|
86
|
+
"examples": [
|
|
87
|
+
{
|
|
88
|
+
"title": "Remove leading slash",
|
|
89
|
+
"description": "Strips the leading slash from a URL path.",
|
|
90
|
+
"code": "withoutLeadingSlash('/path/to/resource')\n// => 'path/to/resource'"
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"name": "withoutTrailingSlash",
|
|
96
|
+
"examples": [
|
|
97
|
+
{
|
|
98
|
+
"title": "Remove trailing slash",
|
|
99
|
+
"description": "Strips the trailing slash from a URL path.",
|
|
100
|
+
"code": "withoutTrailingSlash('path/to/resource/')\n// => 'path/to/resource'"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "withTrailingSlash",
|
|
106
|
+
"examples": [
|
|
107
|
+
{
|
|
108
|
+
"title": "Add a trailing slash",
|
|
109
|
+
"description": "Ensures the URL ends with a forward slash.",
|
|
110
|
+
"code": "withTrailingSlash('path/to/resource')\n// => 'path/to/resource/'"
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|