@helpers4/url 2.0.0-alpha.2 → 2.0.0-alpha.6
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 +6 -4
- package/api.json +135 -0
- package/examples.json +100 -0
- package/lib/index.d.ts +414 -8
- package/lib/index.js +180 -68
- package/lib/index.js.map +1 -0
- package/package.json +19 -10
package/README.md
CHANGED
|
@@ -12,13 +12,13 @@ A set of helpers for working with URLs.
|
|
|
12
12
|
[https://helpers4.js.org/url](https://helpers4.js.org/url)
|
|
13
13
|
|
|
14
14
|
<!-- AUTOMATIC-METHODS -->
|
|
15
|
-
- withTrailingSlash
|
|
16
|
-
- withoutLeadingSlash
|
|
17
15
|
- cleanPath
|
|
18
|
-
- relativeURLToAbsolute
|
|
19
|
-
- withLeadingSlash
|
|
20
16
|
- extractPureURI
|
|
21
17
|
- onlyPath
|
|
18
|
+
- relativeURLToAbsolute
|
|
19
|
+
- withLeadingSlash
|
|
20
|
+
- withTrailingSlash
|
|
21
|
+
- withoutLeadingSlash
|
|
22
22
|
- withoutTrailingSlash
|
|
23
23
|
<!-- /AUTOMATIC-METHODS -->
|
|
24
24
|
|
|
@@ -28,6 +28,7 @@ A set of helpers for working with URLs.
|
|
|
28
28
|
- [array](../array)
|
|
29
29
|
- [date](../date)
|
|
30
30
|
- [function](../function)
|
|
31
|
+
- [math](../math)
|
|
31
32
|
- [number](../number)
|
|
32
33
|
- [object](../object)
|
|
33
34
|
- [observable](../observable)
|
|
@@ -45,6 +46,7 @@ A set of helpers for working with URLs.
|
|
|
45
46
|
| array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
|
|
46
47
|
| date | [@helpers4/date](https://www.npmjs.com/package/@helpers4/date) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/date) | date utilities |
|
|
47
48
|
| function | [@helpers4/function](https://www.npmjs.com/package/@helpers4/function) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/function) | Function utilities and type guards |
|
|
49
|
+
| math | [@helpers4/math](https://www.npmjs.com/package/@helpers4/math) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/math) | math utilities |
|
|
48
50
|
| number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | number utilities |
|
|
49
51
|
| object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
|
|
50
52
|
| observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
|
package/api.json
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "url",
|
|
3
|
+
"members": [
|
|
4
|
+
{
|
|
5
|
+
"name": "cleanPath",
|
|
6
|
+
"kind": "function",
|
|
7
|
+
"description": "Clean an URL by removing duplicate slashes.\nThe protocol part of the URL is not modified.",
|
|
8
|
+
"signature": "cleanPath(url: string | null | undefined): string | null | undefined",
|
|
9
|
+
"params": [
|
|
10
|
+
{
|
|
11
|
+
"name": "url",
|
|
12
|
+
"type": "string | null | undefined",
|
|
13
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"returns": "string | null | undefined",
|
|
17
|
+
"examples": [
|
|
18
|
+
"```ts\ncleanPath('/path//to///resource') // => '/path/to/resource'\ncleanPath('http://example.com//path//to///resource') // => 'http://example.com/path/to/resource'\ncleanPath(undefined) // => undefined\ncleanPath(null) // => null\n```"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "extractPureURI",
|
|
23
|
+
"kind": "function",
|
|
24
|
+
"description": "Extracts the pure URI from a URL by removing query parameters and fragments.",
|
|
25
|
+
"signature": "extractPureURI(url: string): string",
|
|
26
|
+
"params": [
|
|
27
|
+
{
|
|
28
|
+
"name": "url",
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "The URL string to process"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"returns": "string"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "onlyPath",
|
|
37
|
+
"kind": "function",
|
|
38
|
+
"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`",
|
|
39
|
+
"signature": "onlyPath(url: string): string",
|
|
40
|
+
"params": [
|
|
41
|
+
{
|
|
42
|
+
"name": "url",
|
|
43
|
+
"type": "string",
|
|
44
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"returns": "string",
|
|
48
|
+
"examples": [
|
|
49
|
+
"```ts\nonlyPath('/path') // => '/path'\nonlyPath('/path?query=thing') // => '/path'\nonlyPath('/path#fragment') // => '/path'\nonlyPath('/path?query=thing#fragment') // => '/path'\nonlyPath(undefined) // => undefined\nonlyPath(null) // => null\n```"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "relativeURLToAbsolute",
|
|
54
|
+
"kind": "function",
|
|
55
|
+
"description": "",
|
|
56
|
+
"signature": "relativeURLToAbsolute(relativeUrl: string): string",
|
|
57
|
+
"params": [
|
|
58
|
+
{
|
|
59
|
+
"name": "relativeUrl",
|
|
60
|
+
"type": "string",
|
|
61
|
+
"description": ""
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"returns": "string"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "withLeadingSlash",
|
|
68
|
+
"kind": "function",
|
|
69
|
+
"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.",
|
|
70
|
+
"signature": "withLeadingSlash(url: string): string",
|
|
71
|
+
"params": [
|
|
72
|
+
{
|
|
73
|
+
"name": "url",
|
|
74
|
+
"type": "string",
|
|
75
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"returns": "string",
|
|
79
|
+
"examples": [
|
|
80
|
+
"```ts\nwithLeadingSlash('') // => '/'\nwithLeadingSlash('no/slash') // => '/no/slash'\nwithLeadingSlash('/already/has/slash') // => '/already/has/slash'\nwithLeadingSlash(undefined) // => undefined\nwithLeadingSlash(null) // => null\n```"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"name": "withoutLeadingSlash",
|
|
85
|
+
"kind": "function",
|
|
86
|
+
"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.",
|
|
87
|
+
"signature": "withoutLeadingSlash(url: string): string",
|
|
88
|
+
"params": [
|
|
89
|
+
{
|
|
90
|
+
"name": "url",
|
|
91
|
+
"type": "string",
|
|
92
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"returns": "string",
|
|
96
|
+
"examples": [
|
|
97
|
+
"```ts\nwithoutLeadingSlash('') // => ''\nwithoutLeadingSlash('/') // => ''\nwithoutLeadingSlash('/no/slash') // => 'no/slash'\nwithoutLeadingSlash('already/has/slash') // => 'already/has/slash'\nwithoutLeadingSlash(undefined) // => undefined\nwithoutLeadingSlash(null) // => null\n```"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "withoutTrailingSlash",
|
|
102
|
+
"kind": "function",
|
|
103
|
+
"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.",
|
|
104
|
+
"signature": "withoutTrailingSlash(url: string): string",
|
|
105
|
+
"params": [
|
|
106
|
+
{
|
|
107
|
+
"name": "url",
|
|
108
|
+
"type": "string",
|
|
109
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"returns": "string",
|
|
113
|
+
"examples": [
|
|
114
|
+
"```ts\nwithoutTrailingSlash('') // => ''\nwithoutTrailingSlash('/') // => ''\nwithoutTrailingSlash('no/slash/') // => 'no/slash'\nwithoutTrailingSlash('already/has/slash') // => 'already/has/slash'\nwithoutTrailingSlash(undefined) // => undefined\nwithoutTrailingSlash(null) // => null\n```"
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"name": "withTrailingSlash",
|
|
119
|
+
"kind": "function",
|
|
120
|
+
"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.",
|
|
121
|
+
"signature": "withTrailingSlash(url: string): string",
|
|
122
|
+
"params": [
|
|
123
|
+
{
|
|
124
|
+
"name": "url",
|
|
125
|
+
"type": "string",
|
|
126
|
+
"description": "The URL string to be processed. Can be `string`, `undefined`, or `null`."
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"returns": "string",
|
|
130
|
+
"examples": [
|
|
131
|
+
"```ts\nwithTrailingSlash('') // => '/'\nwithTrailingSlash('no/slash') // => 'no/slash/'\nwithTrailingSlash('already/has/slash/') // => 'already/has/slash/'\nwithTrailingSlash(undefined) // => undefined\nwithTrailingSlash(null) // => null\n```"
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
package/examples.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "url",
|
|
3
|
+
"helpers": [
|
|
4
|
+
{
|
|
5
|
+
"helper": "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
|
+
"helper": "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
|
+
"helper": "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
|
+
"helper": "relativeURLToAbsolute",
|
|
46
|
+
"examples": [
|
|
47
|
+
{
|
|
48
|
+
"title": "Convert a relative URL to absolute",
|
|
49
|
+
"description": "Prepends the base URI to a relative path, cleaning duplicate slashes.",
|
|
50
|
+
"code": "relativeURLToAbsolute('/api/data')\n// => 'http://localhost/api/data' (depends on document.baseURI)"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"helper": "withLeadingSlash",
|
|
56
|
+
"examples": [
|
|
57
|
+
{
|
|
58
|
+
"title": "Add a leading slash",
|
|
59
|
+
"description": "Ensures the URL starts with a forward slash.",
|
|
60
|
+
"code": "withLeadingSlash('path/to/resource')\n// => '/path/to/resource'"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"title": "Already has leading slash",
|
|
64
|
+
"description": "Does not add a duplicate slash.",
|
|
65
|
+
"code": "withLeadingSlash('/already/has/slash')\n// => '/already/has/slash'"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"helper": "withTrailingSlash",
|
|
71
|
+
"examples": [
|
|
72
|
+
{
|
|
73
|
+
"title": "Add a trailing slash",
|
|
74
|
+
"description": "Ensures the URL ends with a forward slash.",
|
|
75
|
+
"code": "withTrailingSlash('path/to/resource')\n// => 'path/to/resource/'"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"helper": "withoutLeadingSlash",
|
|
81
|
+
"examples": [
|
|
82
|
+
{
|
|
83
|
+
"title": "Remove leading slash",
|
|
84
|
+
"description": "Strips the leading slash from a URL path.",
|
|
85
|
+
"code": "withoutLeadingSlash('/path/to/resource')\n// => 'path/to/resource'"
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"helper": "withoutTrailingSlash",
|
|
91
|
+
"examples": [
|
|
92
|
+
{
|
|
93
|
+
"title": "Remove trailing slash",
|
|
94
|
+
"description": "Strips the trailing slash from a URL path.",
|
|
95
|
+
"code": "withoutTrailingSlash('path/to/resource/')\n// => 'path/to/resource'"
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
}
|