@welshman/lib 0.0.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.
Files changed (47) hide show
  1. package/README.md +11 -0
  2. package/build/Deferred.cjs +13 -0
  3. package/build/Deferred.cjs.map +1 -0
  4. package/build/Deferred.d.ts +5 -0
  5. package/build/Deferred.mjs +9 -0
  6. package/build/Deferred.mjs.map +1 -0
  7. package/build/Emitter.cjs +13 -0
  8. package/build/Emitter.cjs.map +1 -0
  9. package/build/Emitter.d.ts +4 -0
  10. package/build/Emitter.mjs +9 -0
  11. package/build/Emitter.mjs.map +1 -0
  12. package/build/Fluent.cjs +47 -0
  13. package/build/Fluent.cjs.map +1 -0
  14. package/build/Fluent.d.ts +34 -0
  15. package/build/Fluent.mjs +43 -0
  16. package/build/Fluent.mjs.map +1 -0
  17. package/build/LRUCache.cjs +49 -0
  18. package/build/LRUCache.cjs.map +1 -0
  19. package/build/LRUCache.d.ts +19 -0
  20. package/build/LRUCache.mjs +44 -0
  21. package/build/LRUCache.mjs.map +1 -0
  22. package/build/Store.cjs +220 -0
  23. package/build/Store.cjs.map +1 -0
  24. package/build/Store.d.ts +105 -0
  25. package/build/Store.mjs +205 -0
  26. package/build/Store.mjs.map +1 -0
  27. package/build/Tools.cjs +189 -0
  28. package/build/Tools.cjs.map +1 -0
  29. package/build/Tools.d.ts +61 -0
  30. package/build/Tools.mjs +141 -0
  31. package/build/Tools.mjs.map +1 -0
  32. package/build/Worker.cjs +67 -0
  33. package/build/Worker.cjs.map +1 -0
  34. package/build/Worker.d.ts +17 -0
  35. package/build/Worker.mjs +63 -0
  36. package/build/Worker.mjs.map +1 -0
  37. package/build/index.cjs +30 -0
  38. package/build/index.cjs.map +1 -0
  39. package/build/index.d.ts +8 -0
  40. package/build/index.mjs +9 -0
  41. package/build/index.mjs.map +1 -0
  42. package/build/normalize-url/index.cjs +254 -0
  43. package/build/normalize-url/index.cjs.map +1 -0
  44. package/build/normalize-url/index.d.ts +285 -0
  45. package/build/normalize-url/index.mjs +251 -0
  46. package/build/normalize-url/index.mjs.map +1 -0
  47. package/package.json +40 -0
@@ -0,0 +1,285 @@
1
+ export type Options = {
2
+ /**
3
+ @default 'http'
4
+ */
5
+ readonly defaultProtocol?: 'https' | 'http';
6
+ /**
7
+ Prepends `defaultProtocol` to the URL if it's protocol-relative.
8
+
9
+ @default true
10
+
11
+ @example
12
+ ```
13
+ normalizeUrl('//sindresorhus.com');
14
+ //=> 'http://sindresorhus.com'
15
+
16
+ normalizeUrl('//sindresorhus.com', {normalizeProtocol: false});
17
+ //=> '//sindresorhus.com'
18
+ ```
19
+ */
20
+ readonly normalizeProtocol?: boolean;
21
+ /**
22
+ Normalizes HTTPS URLs to HTTP.
23
+
24
+ @default false
25
+
26
+ @example
27
+ ```
28
+ normalizeUrl('https://sindresorhus.com');
29
+ //=> 'https://sindresorhus.com'
30
+
31
+ normalizeUrl('https://sindresorhus.com', {forceHttp: true});
32
+ //=> 'http://sindresorhus.com'
33
+ ```
34
+ */
35
+ readonly forceHttp?: boolean;
36
+ /**
37
+ Normalizes HTTP URLs to HTTPS.
38
+
39
+ This option cannot be used with the `forceHttp` option at the same time.
40
+
41
+ @default false
42
+
43
+ @example
44
+ ```
45
+ normalizeUrl('http://sindresorhus.com');
46
+ //=> 'http://sindresorhus.com'
47
+
48
+ normalizeUrl('http://sindresorhus.com', {forceHttps: true});
49
+ //=> 'https://sindresorhus.com'
50
+ ```
51
+ */
52
+ readonly forceHttps?: boolean;
53
+ /**
54
+ Strip the [authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) part of a URL.
55
+
56
+ @default true
57
+
58
+ @example
59
+ ```
60
+ normalizeUrl('user:password@sindresorhus.com');
61
+ //=> 'https://sindresorhus.com'
62
+
63
+ normalizeUrl('user:password@sindresorhus.com', {stripAuthentication: false});
64
+ //=> 'https://user:password@sindresorhus.com'
65
+ ```
66
+ */
67
+ readonly stripAuthentication?: boolean;
68
+ /**
69
+ Removes hash from the URL.
70
+
71
+ @default false
72
+
73
+ @example
74
+ ```
75
+ normalizeUrl('sindresorhus.com/about.html#contact');
76
+ //=> 'http://sindresorhus.com/about.html#contact'
77
+
78
+ normalizeUrl('sindresorhus.com/about.html#contact', {stripHash: true});
79
+ //=> 'http://sindresorhus.com/about.html'
80
+ ```
81
+ */
82
+ readonly stripHash?: boolean;
83
+ /**
84
+ Remove the protocol from the URL: `http://sindresorhus.com` → `sindresorhus.com`.
85
+
86
+ It will only remove `https://` and `http://` protocols.
87
+
88
+ @default false
89
+
90
+ @example
91
+ ```
92
+ normalizeUrl('https://sindresorhus.com');
93
+ //=> 'https://sindresorhus.com'
94
+
95
+ normalizeUrl('sindresorhus.com', {stripProtocol: true});
96
+ //=> 'sindresorhus.com'
97
+ ```
98
+ */
99
+ readonly stripProtocol?: boolean;
100
+ /**
101
+ Strip the [text fragment](https://web.dev/text-fragments/) part of the URL
102
+
103
+ __Note:__ The text fragment will always be removed if the `stripHash` option is set to `true`, as the hash contains the text fragment.
104
+
105
+ @default true
106
+
107
+ @example
108
+ ```
109
+ normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello');
110
+ //=> 'http://sindresorhus.com/about.html#'
111
+
112
+ normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello');
113
+ //=> 'http://sindresorhus.com/about.html#section'
114
+
115
+ normalizeUrl('http://sindresorhus.com/about.html#:~:text=hello', {stripTextFragment: false});
116
+ //=> 'http://sindresorhus.com/about.html#:~:text=hello'
117
+
118
+ normalizeUrl('http://sindresorhus.com/about.html#section:~:text=hello', {stripTextFragment: false});
119
+ //=> 'http://sindresorhus.com/about.html#section:~:text=hello'
120
+ ```
121
+ */
122
+ readonly stripTextFragment?: boolean;
123
+ /**
124
+ Removes `www.` from the URL.
125
+
126
+ @default true
127
+
128
+ @example
129
+ ```
130
+ normalizeUrl('http://www.sindresorhus.com');
131
+ //=> 'http://sindresorhus.com'
132
+
133
+ normalizeUrl('http://www.sindresorhus.com', {stripWWW: false});
134
+ //=> 'http://www.sindresorhus.com'
135
+ ```
136
+ */
137
+ readonly stripWWW?: boolean;
138
+ /**
139
+ Removes query parameters that matches any of the provided strings or regexes.
140
+
141
+ @default [/^utm_\w+/i]
142
+
143
+ @example
144
+ ```
145
+ normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', {
146
+ removeQueryParameters: ['ref']
147
+ });
148
+ //=> 'http://sindresorhus.com/?foo=bar'
149
+ ```
150
+
151
+ If a boolean is provided, `true` will remove all the query parameters.
152
+
153
+ ```
154
+ normalizeUrl('www.sindresorhus.com?foo=bar', {
155
+ removeQueryParameters: true
156
+ });
157
+ //=> 'http://sindresorhus.com'
158
+ ```
159
+
160
+ `false` will not remove any query parameter.
161
+
162
+ ```
163
+ normalizeUrl('www.sindresorhus.com?foo=bar&utm_medium=test&ref=test_ref', {
164
+ removeQueryParameters: false
165
+ });
166
+ //=> 'http://www.sindresorhus.com/?foo=bar&ref=test_ref&utm_medium=test'
167
+ ```
168
+ */
169
+ readonly removeQueryParameters?: ReadonlyArray<RegExp | string> | boolean;
170
+ /**
171
+ Keeps only query parameters that matches any of the provided strings or regexes.
172
+
173
+ __Note__: It overrides the `removeQueryParameters` option.
174
+
175
+ @default undefined
176
+
177
+ @example
178
+ ```
179
+ normalizeUrl('https://sindresorhus.com?foo=bar&ref=unicorn', {
180
+ keepQueryParameters: ['ref']
181
+ });
182
+ //=> 'https://sindresorhus.com/?ref=unicorn'
183
+ ```
184
+ */
185
+ readonly keepQueryParameters?: ReadonlyArray<RegExp | string>;
186
+ /**
187
+ Removes trailing slash.
188
+
189
+ __Note__: Trailing slash is always removed if the URL doesn't have a pathname unless the `removeSingleSlash` option is set to `false`.
190
+
191
+ @default true
192
+
193
+ @example
194
+ ```
195
+ normalizeUrl('http://sindresorhus.com/redirect/');
196
+ //=> 'http://sindresorhus.com/redirect'
197
+
198
+ normalizeUrl('http://sindresorhus.com/redirect/', {removeTrailingSlash: false});
199
+ //=> 'http://sindresorhus.com/redirect/'
200
+
201
+ normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false});
202
+ //=> 'http://sindresorhus.com'
203
+ ```
204
+ */
205
+ readonly removeTrailingSlash?: boolean;
206
+ /**
207
+ Remove a sole `/` pathname in the output. This option is independent of `removeTrailingSlash`.
208
+
209
+ @default true
210
+
211
+ @example
212
+ ```
213
+ normalizeUrl('https://sindresorhus.com/');
214
+ //=> 'https://sindresorhus.com'
215
+
216
+ normalizeUrl('https://sindresorhus.com/', {removeSingleSlash: false});
217
+ //=> 'https://sindresorhus.com/'
218
+ ```
219
+ */
220
+ readonly removeSingleSlash?: boolean;
221
+ /**
222
+ Removes the default directory index file from path that matches any of the provided strings or regexes.
223
+ When `true`, the regex `/^index\.[a-z]+$/` is used.
224
+
225
+ @default false
226
+
227
+ @example
228
+ ```
229
+ normalizeUrl('www.sindresorhus.com/foo/default.php', {
230
+ removeDirectoryIndex: [/^default\.[a-z]+$/]
231
+ });
232
+ //=> 'http://sindresorhus.com/foo'
233
+ ```
234
+ */
235
+ readonly removeDirectoryIndex?: boolean | ReadonlyArray<RegExp | string>;
236
+ /**
237
+ Removes an explicit port number from the URL.
238
+
239
+ Port 443 is always removed from HTTPS URLs and 80 is always removed from HTTP URLs regardless of this option.
240
+
241
+ @default false
242
+
243
+ @example
244
+ ```
245
+ normalizeUrl('sindresorhus.com:123', {
246
+ removeExplicitPort: true
247
+ });
248
+ //=> 'http://sindresorhus.com'
249
+ ```
250
+ */
251
+ readonly removeExplicitPort?: boolean;
252
+ /**
253
+ Sorts the query parameters alphabetically by key.
254
+
255
+ @default true
256
+
257
+ @example
258
+ ```
259
+ normalizeUrl('www.sindresorhus.com?b=two&a=one&c=three', {
260
+ sortQueryParameters: false
261
+ });
262
+ //=> 'http://sindresorhus.com/?b=two&a=one&c=three'
263
+ ```
264
+ */
265
+ readonly sortQueryParameters?: boolean;
266
+ };
267
+ /**
268
+ [Normalize](https://en.wikipedia.org/wiki/URL_normalization) a URL.
269
+
270
+ URLs with custom protocols are not normalized and just passed through by default. Supported protocols are: `https`, `http`, `file`, and `data`.
271
+
272
+ @param url - URL to normalize, including [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs).
273
+
274
+ @example
275
+ ```
276
+ import normalizeUrl from 'normalize-url';
277
+
278
+ normalizeUrl('sindresorhus.com');
279
+ //=> 'http://sindresorhus.com'
280
+
281
+ normalizeUrl('//www.sindresorhus.com:80/../baz?b=bar&a=foo');
282
+ //=> 'http://sindresorhus.com/baz?a=foo&b=bar'
283
+ ```
284
+ */
285
+ export default function normalizeUrl(urlString: string, opts?: Options): string;
@@ -0,0 +1,251 @@
1
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
2
+ const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';
3
+ const DATA_URL_DEFAULT_CHARSET = 'us-ascii';
4
+ const testParameter = (name, filters) => filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
5
+ const supportedProtocols = new Set([
6
+ 'https:',
7
+ 'http:',
8
+ 'file:',
9
+ ]);
10
+ const hasCustomProtocol = (urlString) => {
11
+ try {
12
+ const { protocol } = new URL(urlString);
13
+ return protocol.endsWith(':') && !supportedProtocols.has(protocol);
14
+ }
15
+ catch (_a) {
16
+ return false;
17
+ }
18
+ };
19
+ const normalizeDataURL = (urlString, { stripHash }) => {
20
+ var _a, _b;
21
+ const match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(urlString);
22
+ if (!match) {
23
+ throw new Error(`Invalid URL: ${urlString}`);
24
+ }
25
+ let { type, data, hash } = match.groups;
26
+ const mediaType = type.split(';');
27
+ hash = stripHash ? '' : hash;
28
+ let isBase64 = false;
29
+ if (mediaType[mediaType.length - 1] === 'base64') {
30
+ mediaType.pop();
31
+ isBase64 = true;
32
+ }
33
+ // Lowercase MIME type
34
+ const mimeType = (_b = (_a = mediaType.shift()) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : '';
35
+ const attributes = mediaType
36
+ .map((attribute) => {
37
+ let [key, value = ''] = attribute.split('=').map((s) => s.trim());
38
+ // Lowercase `charset`
39
+ if (key === 'charset') {
40
+ value = value.toLowerCase();
41
+ if (value === DATA_URL_DEFAULT_CHARSET) {
42
+ return '';
43
+ }
44
+ }
45
+ return `${key}${value ? `=${value}` : ''}`;
46
+ })
47
+ .filter(Boolean);
48
+ const normalizedMediaType = [
49
+ ...attributes,
50
+ ];
51
+ if (isBase64) {
52
+ normalizedMediaType.push('base64');
53
+ }
54
+ if (normalizedMediaType.length > 0 || (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)) {
55
+ normalizedMediaType.unshift(mimeType);
56
+ }
57
+ return `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ''}`;
58
+ };
59
+ /**
60
+ [Normalize](https://en.wikipedia.org/wiki/URL_normalization) a URL.
61
+
62
+ URLs with custom protocols are not normalized and just passed through by default. Supported protocols are: `https`, `http`, `file`, and `data`.
63
+
64
+ @param url - URL to normalize, including [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs).
65
+
66
+ @example
67
+ ```
68
+ import normalizeUrl from 'normalize-url';
69
+
70
+ normalizeUrl('sindresorhus.com');
71
+ //=> 'http://sindresorhus.com'
72
+
73
+ normalizeUrl('//www.sindresorhus.com:80/../baz?b=bar&a=foo');
74
+ //=> 'http://sindresorhus.com/baz?a=foo&b=bar'
75
+ ```
76
+ */
77
+ export default function normalizeUrl(urlString, opts) {
78
+ const options = {
79
+ defaultProtocol: 'http',
80
+ normalizeProtocol: true,
81
+ forceHttp: false,
82
+ forceHttps: false,
83
+ stripAuthentication: true,
84
+ stripHash: false,
85
+ stripTextFragment: true,
86
+ stripWWW: true,
87
+ removeQueryParameters: [/^utm_\w+/i],
88
+ removeTrailingSlash: true,
89
+ removeSingleSlash: true,
90
+ removeDirectoryIndex: false,
91
+ removeExplicitPort: false,
92
+ sortQueryParameters: true,
93
+ ...opts,
94
+ };
95
+ // Legacy: Append `:` to the protocol if missing.
96
+ if (typeof options.defaultProtocol === 'string' && !options.defaultProtocol.endsWith(':')) {
97
+ options.defaultProtocol = `${options.defaultProtocol}:`;
98
+ }
99
+ urlString = urlString.trim();
100
+ // Data URL
101
+ if (/^data:/i.test(urlString)) {
102
+ return normalizeDataURL(urlString, options);
103
+ }
104
+ if (hasCustomProtocol(urlString)) {
105
+ return urlString;
106
+ }
107
+ const hasRelativeProtocol = urlString.startsWith('//');
108
+ const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
109
+ // Prepend protocol
110
+ if (!isRelativeUrl) {
111
+ urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
112
+ }
113
+ const urlObject = new URL(urlString);
114
+ if (options.forceHttp && options.forceHttps) {
115
+ throw new Error('The `forceHttp` and `forceHttps` options cannot be used together');
116
+ }
117
+ if (options.forceHttp && urlObject.protocol === 'https:') {
118
+ urlObject.protocol = 'http:';
119
+ }
120
+ if (options.forceHttps && urlObject.protocol === 'http:') {
121
+ urlObject.protocol = 'https:';
122
+ }
123
+ // Remove auth
124
+ if (options.stripAuthentication) {
125
+ urlObject.username = '';
126
+ urlObject.password = '';
127
+ }
128
+ // Remove hash
129
+ if (options.stripHash) {
130
+ urlObject.hash = '';
131
+ }
132
+ else if (options.stripTextFragment) {
133
+ urlObject.hash = urlObject.hash.replace(/#?:~:text.*?$/i, '');
134
+ }
135
+ // Remove duplicate slashes if not preceded by a protocol
136
+ // NOTE: This could be implemented using a single negative lookbehind
137
+ // regex, but we avoid that to maintain compatibility with older js engines
138
+ // which do not have support for that feature.
139
+ if (urlObject.pathname) {
140
+ // TODO: Replace everything below with `urlObject.pathname = urlObject.pathname.replace(/(?<!\b[a-z][a-z\d+\-.]{1,50}:)\/{2,}/g, '/');` when Safari supports negative lookbehind.
141
+ // Split the string by occurrences of this protocol regex, and perform
142
+ // duplicate-slash replacement on the strings between those occurrences
143
+ // (if any).
144
+ const protocolRegex = /\b[a-z][a-z\d+\-.]{1,50}:\/\//g;
145
+ let lastIndex = 0;
146
+ let result = '';
147
+ for (;;) {
148
+ const match = protocolRegex.exec(urlObject.pathname);
149
+ if (!match) {
150
+ break;
151
+ }
152
+ const protocol = match[0];
153
+ const protocolAtIndex = match.index;
154
+ const intermediate = urlObject.pathname.slice(lastIndex, protocolAtIndex);
155
+ result += intermediate.replace(/\/{2,}/g, '/');
156
+ result += protocol;
157
+ lastIndex = protocolAtIndex + protocol.length;
158
+ }
159
+ const remnant = urlObject.pathname.slice(lastIndex, urlObject.pathname.length);
160
+ result += remnant.replace(/\/{2,}/g, '/');
161
+ urlObject.pathname = result;
162
+ }
163
+ // Decode URI octets
164
+ if (urlObject.pathname) {
165
+ try {
166
+ urlObject.pathname = decodeURI(urlObject.pathname);
167
+ }
168
+ catch (_a) { }
169
+ }
170
+ // Remove directory index
171
+ if (options.removeDirectoryIndex === true) {
172
+ options.removeDirectoryIndex = [/^index\.[a-z]+$/];
173
+ }
174
+ if (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {
175
+ let pathComponents = urlObject.pathname.split('/');
176
+ const lastComponent = pathComponents[pathComponents.length - 1];
177
+ if (testParameter(lastComponent, options.removeDirectoryIndex)) {
178
+ pathComponents = pathComponents.slice(0, -1);
179
+ urlObject.pathname = pathComponents.slice(1).join('/') + '/';
180
+ }
181
+ }
182
+ if (urlObject.hostname) {
183
+ // Remove trailing dot
184
+ urlObject.hostname = urlObject.hostname.replace(/\.$/, '');
185
+ // Remove `www.`
186
+ if (options.stripWWW && /^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(urlObject.hostname)) {
187
+ // Each label should be max 63 at length (min: 1).
188
+ // Source: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
189
+ // Each TLD should be up to 63 characters long (min: 2).
190
+ // It is technically possible to have a single character TLD, but none currently exist.
191
+ urlObject.hostname = urlObject.hostname.replace(/^www\./, '');
192
+ }
193
+ }
194
+ // Remove query unwanted parameters
195
+ if (Array.isArray(options.removeQueryParameters)) {
196
+ // eslint-disable-next-line unicorn/no-useless-spread -- We are intentionally spreading to get a copy.
197
+ for (const key of [...urlObject.searchParams.keys()]) {
198
+ if (testParameter(key, options.removeQueryParameters)) {
199
+ urlObject.searchParams.delete(key);
200
+ }
201
+ }
202
+ }
203
+ if (!Array.isArray(options.keepQueryParameters) && options.removeQueryParameters === true) {
204
+ urlObject.search = '';
205
+ }
206
+ // Keep wanted query parameters
207
+ if (Array.isArray(options.keepQueryParameters) && options.keepQueryParameters.length > 0) {
208
+ // eslint-disable-next-line unicorn/no-useless-spread -- We are intentionally spreading to get a copy.
209
+ for (const key of [...urlObject.searchParams.keys()]) {
210
+ if (!testParameter(key, options.keepQueryParameters)) {
211
+ urlObject.searchParams.delete(key);
212
+ }
213
+ }
214
+ }
215
+ // Sort query parameters
216
+ if (options.sortQueryParameters) {
217
+ urlObject.searchParams.sort();
218
+ // Calling `.sort()` encodes the search parameters, so we need to decode them again.
219
+ try {
220
+ urlObject.search = decodeURIComponent(urlObject.search);
221
+ }
222
+ catch (_b) { }
223
+ }
224
+ if (options.removeTrailingSlash) {
225
+ urlObject.pathname = urlObject.pathname.replace(/\/$/, '');
226
+ }
227
+ // Remove an explicit port number, excluding a default port number, if applicable
228
+ if (options.removeExplicitPort && urlObject.port) {
229
+ urlObject.port = '';
230
+ }
231
+ const oldUrlString = urlString;
232
+ // Take advantage of many of the Node `url` normalizations
233
+ urlString = urlObject.toString();
234
+ if (!options.removeSingleSlash && urlObject.pathname === '/' && !oldUrlString.endsWith('/') && urlObject.hash === '') {
235
+ urlString = urlString.replace(/\/$/, '');
236
+ }
237
+ // Remove ending `/` unless removeSingleSlash is false
238
+ if ((options.removeTrailingSlash || urlObject.pathname === '/') && urlObject.hash === '' && options.removeSingleSlash) {
239
+ urlString = urlString.replace(/\/$/, '');
240
+ }
241
+ // Restore relative protocol, if applicable
242
+ if (hasRelativeProtocol && !options.normalizeProtocol) {
243
+ urlString = urlString.replace(/^http:\/\//, '//');
244
+ }
245
+ // Remove http/https
246
+ if (options.stripProtocol) {
247
+ urlString = urlString.replace(/^(?:https?:)?\/\//, '');
248
+ }
249
+ return urlString;
250
+ }
251
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../normalize-url/index.ts"],"names":[],"mappings":"AA0RA,6EAA6E;AAC7E,MAAM,0BAA0B,GAAG,YAAY,CAAA;AAC/C,MAAM,wBAAwB,GAAG,UAAU,CAAA;AAE3C,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,OAAc,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,CAAA;AAE9I,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IAClC,QAAQ;IACR,OAAO;IACP,OAAO;CACP,CAAC,CAAA;AAEF,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAE,EAAE;IAC/C,IAAI;QACH,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;QACrC,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;KAClE;IAAC,WAAM;QACP,OAAO,KAAK,CAAA;KACZ;AACF,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,CAAC,SAAiB,EAAE,EAAC,SAAS,EAAuB,EAAE,EAAE;;IACjF,MAAM,KAAK,GAAG,yDAAyD,CAAC,IAAI,CAAC,SAAS,CAAC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F,IAAI,OAAO,CAAC,kBAAkB,IAAI,SAAS,CAAC,IAAI,EAAE;QACjD,SAAS,CAAC,IAAI,GAAG,EAAE,CAAA;KACnB;IAED,MAAM,YAAY,GAAG,SAAS,CAAA;IAE9B,0DAA0D;IAC1D,SAAS,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAA;IAEhC,IAAI,CAAC,OAAO,CAAC,iBAAiB,IAAI,SAAS,CAAC,QAAQ,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,IAAI,KAAK,EAAE,EAAE;QACrH,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;KACxC;IAED,sDAAsD;IACtD,IAAI,CAAC,OAAO,CAAC,mBAAmB,IAAI,SAAS,CAAC,QAAQ,KAAK,GAAG,CAAC,IAAI,SAAS,CAAC,IAAI,KAAK,EAAE,IAAI,OAAO,CAAC,iBAAiB,EAAE;QACtH,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;KACxC;IAED,2CAA2C;IAC3C,IAAI,mBAAmB,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE;QACtD,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;KACjD;IAED,oBAAoB;IACpB,IAAI,OAAO,CAAC,aAAa,EAAE;QAC1B,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAA;KACtD;IAED,OAAO,SAAS,CAAA;AACjB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@welshman/lib",
3
+ "version": "0.0.1",
4
+ "author": "hodlbod",
5
+ "license": "MIT",
6
+ "description": "A collection of utilities.",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "type": "module",
11
+ "files": [
12
+ "build"
13
+ ],
14
+ "types": "./build/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./build/index.d.ts",
18
+ "import": "./build/index.mjs",
19
+ "require": "./build/index.cjs"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "pub": "npm run lint && npm run build && npm publish",
24
+ "build": "gts clean && tsc-multi",
25
+ "lint": "gts lint",
26
+ "fix": "gts fix"
27
+ },
28
+ "devDependencies": {
29
+ "@types/events": "^3.0.3",
30
+ "@types/throttle-debounce": "^5.0.2",
31
+ "gts": "^5.0.1",
32
+ "tsc-multi": "^1.1.0",
33
+ "typescript": "~5.1.6"
34
+ },
35
+ "dependencies": {
36
+ "@scure/base": "^1.1.6",
37
+ "events": "^3.3.0",
38
+ "throttle-debounce": "^5.0.0"
39
+ }
40
+ }