@alwatr/resolve-url 5.4.0 → 5.5.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/CHANGELOG.md +16 -0
- package/dist/main.cjs +8 -5
- package/dist/main.cjs.map +2 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/main.mjs +8 -5
- package/dist/main.mjs.map +2 -2
- package/package.json +7 -6
- package/src/main.test.js +101 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.5.1](https://github.com/Alwatr/nanolib/compare/@alwatr/resolve-url@5.5.0...@alwatr/resolve-url@5.5.1) (2025-03-13)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **resolve-url:** Remove lookbehind regex for Safari/iOS compatibility ([42c4df7](https://github.com/Alwatr/nanolib/commit/42c4df7144f299e6e764e57c442903ca8ba2667b)) by @alimd
|
|
11
|
+
|
|
12
|
+
### Dependencies update
|
|
13
|
+
|
|
14
|
+
* add jest version 29.7.0 to resolve-url package ([1f988a2](https://github.com/Alwatr/nanolib/commit/1f988a2382d978ca8f21c68548bb51d7a74d4a73)) by @alimd
|
|
15
|
+
|
|
16
|
+
## [5.5.0](https://github.com/Alwatr/nanolib/compare/@alwatr/resolve-url@5.4.0...@alwatr/resolve-url@5.5.0) (2025-03-06)
|
|
17
|
+
|
|
18
|
+
### Dependencies update
|
|
19
|
+
|
|
20
|
+
* bump the development-dependencies group across 1 directory with 11 updates ([720c395](https://github.com/Alwatr/nanolib/commit/720c3954da55c929fe8fb16957121f4c51fb7f0c)) by @dependabot[bot]
|
|
21
|
+
|
|
6
22
|
## [5.4.0](https://github.com/Alwatr/nanolib/compare/@alwatr/resolve-url@1.0.2...@alwatr/resolve-url@5.4.0) (2025-02-18)
|
|
7
23
|
|
|
8
24
|
## 5.3.0 (2025-02-03)
|
package/dist/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @alwatr/resolve-url v5.
|
|
1
|
+
/* @alwatr/resolve-url v5.5.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -25,12 +25,15 @@ __export(main_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(main_exports);
|
|
27
27
|
var import_package_tracer = require("@alwatr/package-tracer");
|
|
28
|
-
__dev_mode__: import_package_tracer.packageTracer.add("@alwatr/resolve-url", "5.
|
|
29
|
-
var trimSlashes = /(?:^\/+|\/+$)/g;
|
|
30
|
-
var multipleSlashes = /(?<!:)\/{2,}/g;
|
|
28
|
+
__dev_mode__: import_package_tracer.packageTracer.add("@alwatr/resolve-url", "5.5.1");
|
|
31
29
|
function resolveUrl(...parts) {
|
|
30
|
+
if (parts.length === 0) {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
const trimSlashes = /^\/+|\/+$/g;
|
|
34
|
+
const multipleSlashes = /\/{2,}/g;
|
|
32
35
|
const prefix = parts[0].indexOf("/") === 0 ? "/" : "";
|
|
33
|
-
return prefix + parts.map((part) => part.replace(trimSlashes, "")).filter((part) => part).join("/").replace(multipleSlashes, "/");
|
|
36
|
+
return prefix + parts.map((part) => part.replace(trimSlashes, "")).filter((part) => part).join("/").replace("://", "{{PROTOCOL_SLASH}}").replace(multipleSlashes, "/").replace("{{PROTOCOL_SLASH}}", "://");
|
|
34
37
|
}
|
|
35
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
39
|
0 && (module.exports = {
|
package/dist/main.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
|
-
"sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;AAE5B,aAAc,qCAAc,IAAI,uBAAkB,OAAmB;
|
|
4
|
+
"sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport function resolveUrl(...parts: string[]): string {\n if (parts.length === 0) {\n return ''; // or throw an error, depending on your needs\n }\n\n const trimSlashes = /^\\/+|\\/+$/g;\n const multipleSlashes = /\\/{2,}/g;\n\n const prefix = parts[0].indexOf('/') === 0 ? '/' : ''; // Add leading slash if the first part has it\n\n return (\n prefix +\n parts\n .map((part) => part.replace(trimSlashes, '')) // Remove leading and trailing slashes\n .filter((part) => part) // Remove empty parts\n .join('/')\n // Replace multiple slashes with a single slash, except for protocol\n .replace('://', '{{PROTOCOL_SLASH}}')\n .replace(multipleSlashes, '/')\n .replace('{{PROTOCOL_SLASH}}', '://')\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;AAE5B,aAAc,qCAAc,IAAI,uBAAkB,OAAmB;AAE9D,SAAS,cAAc,OAAyB;AACrD,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,cAAc;AACpB,QAAM,kBAAkB;AAExB,QAAM,SAAS,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,IAAI,MAAM;AAEnD,SACE,SACA,MACG,IAAI,CAAC,SAAS,KAAK,QAAQ,aAAa,EAAE,CAAC,EAC3C,OAAO,CAAC,SAAS,IAAI,EACrB,KAAK,GAAG,EAER,QAAQ,OAAO,oBAAoB,EACnC,QAAQ,iBAAiB,GAAG,EAC5B,QAAQ,sBAAsB,KAAK;AAE1C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBrD"}
|
package/dist/main.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
/* @alwatr/resolve-url v5.
|
|
1
|
+
/* @alwatr/resolve-url v5.5.1 */
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { packageTracer } from "@alwatr/package-tracer";
|
|
5
|
-
__dev_mode__: packageTracer.add("@alwatr/resolve-url", "5.
|
|
6
|
-
var trimSlashes = /(?:^\/+|\/+$)/g;
|
|
7
|
-
var multipleSlashes = /(?<!:)\/{2,}/g;
|
|
5
|
+
__dev_mode__: packageTracer.add("@alwatr/resolve-url", "5.5.1");
|
|
8
6
|
function resolveUrl(...parts) {
|
|
7
|
+
if (parts.length === 0) {
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
const trimSlashes = /^\/+|\/+$/g;
|
|
11
|
+
const multipleSlashes = /\/{2,}/g;
|
|
9
12
|
const prefix = parts[0].indexOf("/") === 0 ? "/" : "";
|
|
10
|
-
return prefix + parts.map((part) => part.replace(trimSlashes, "")).filter((part) => part).join("/").replace(multipleSlashes, "/");
|
|
13
|
+
return prefix + parts.map((part) => part.replace(trimSlashes, "")).filter((part) => part).join("/").replace("://", "{{PROTOCOL_SLASH}}").replace(multipleSlashes, "/").replace("{{PROTOCOL_SLASH}}", "://");
|
|
11
14
|
}
|
|
12
15
|
export {
|
|
13
16
|
resolveUrl
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/main.ts"],
|
|
4
|
-
"sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\
|
|
5
|
-
"mappings": ";;;AAAA,SAAQ,qBAAoB;AAE5B,aAAc,eAAc,IAAI,uBAAkB,OAAmB;
|
|
4
|
+
"sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport function resolveUrl(...parts: string[]): string {\n if (parts.length === 0) {\n return ''; // or throw an error, depending on your needs\n }\n\n const trimSlashes = /^\\/+|\\/+$/g;\n const multipleSlashes = /\\/{2,}/g;\n\n const prefix = parts[0].indexOf('/') === 0 ? '/' : ''; // Add leading slash if the first part has it\n\n return (\n prefix +\n parts\n .map((part) => part.replace(trimSlashes, '')) // Remove leading and trailing slashes\n .filter((part) => part) // Remove empty parts\n .join('/')\n // Replace multiple slashes with a single slash, except for protocol\n .replace('://', '{{PROTOCOL_SLASH}}')\n .replace(multipleSlashes, '/')\n .replace('{{PROTOCOL_SLASH}}', '://')\n );\n}\n"],
|
|
5
|
+
"mappings": ";;;AAAA,SAAQ,qBAAoB;AAE5B,aAAc,eAAc,IAAI,uBAAkB,OAAmB;AAE9D,SAAS,cAAc,OAAyB;AACrD,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,cAAc;AACpB,QAAM,kBAAkB;AAExB,QAAM,SAAS,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,IAAI,MAAM;AAEnD,SACE,SACA,MACG,IAAI,CAAC,SAAS,KAAK,QAAQ,aAAa,EAAE,CAAC,EAC3C,OAAO,CAAC,SAAS,IAAI,EACrB,KAAK,GAAG,EAER,QAAQ,OAAO,oBAAoB,EACnC,QAAQ,iBAAiB,GAAG,EAC5B,QAAQ,sBAAsB,KAAK;AAE1C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwatr/resolve-url",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.1",
|
|
4
4
|
"description": "A tiny TypeScript library to resolve URLs.",
|
|
5
5
|
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -67,14 +67,15 @@
|
|
|
67
67
|
"clean": "rm -rfv dist *.tsbuildinfo"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@alwatr/package-tracer": "^5.
|
|
70
|
+
"@alwatr/package-tracer": "^5.5.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@alwatr/nano-build": "^5.
|
|
73
|
+
"@alwatr/nano-build": "^5.5.0",
|
|
74
74
|
"@alwatr/prettier-config": "^5.0.0",
|
|
75
75
|
"@alwatr/tsconfig-base": "^5.0.0",
|
|
76
|
-
"@alwatr/type-helper": "^5.
|
|
77
|
-
"
|
|
76
|
+
"@alwatr/type-helper": "^5.4.0",
|
|
77
|
+
"jest": "^29.7.0",
|
|
78
|
+
"typescript": "^5.8.2"
|
|
78
79
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "cb8fb7e3233beb34617e17a93253777e423ba065"
|
|
80
81
|
}
|
package/src/main.test.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {resolveUrl} from '@alwatr/resolve-url';
|
|
2
|
+
|
|
3
|
+
describe('@alwatr/resolve-url - resolveUrl', () => {
|
|
4
|
+
it('should handle basic URL parts', () => {
|
|
5
|
+
expect(resolveUrl('http://example.com', 'path', 'to', 'resource')).toBe('http://example.com/path/to/resource');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should handle multiple slashes in URL parts', () => {
|
|
9
|
+
expect(resolveUrl('http://example.com', 'path//to///resource')).toBe('http://example.com/path/to/resource');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should handle leading and trailing slashes in URL parts', () => {
|
|
13
|
+
expect(resolveUrl('http://example.com/', '/path/', '/to/', '/resource/')).toBe('http://example.com/path/to/resource');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should handle multiple slashes at the beginning and end of URL parts', () => {
|
|
17
|
+
expect(resolveUrl('http://example.com', '///path', 'to', 'resource///')).toBe('http://example.com/path/to/resource');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should preserve the protocol (http)', () => {
|
|
21
|
+
expect(resolveUrl('http://example.com', 'path')).toBe('http://example.com/path');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should preserve the protocol (https)', () => {
|
|
25
|
+
expect(resolveUrl('https://example.com', 'path')).toBe('https://example.com/path');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should handle URLs without a protocol', () => {
|
|
29
|
+
expect(resolveUrl('example.com', 'path', 'to', 'resource')).toBe('example.com/path/to/resource');
|
|
30
|
+
});
|
|
31
|
+
it('should handle URLs without a protocol and with multiple slashes', () => {
|
|
32
|
+
expect(resolveUrl('example.com//', '//path///', 'to', 'resource')).toBe('example.com/path/to/resource');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should handle an empty first part', () => {
|
|
36
|
+
expect(resolveUrl('', 'path', 'to', 'resource')).toBe('path/to/resource');
|
|
37
|
+
});
|
|
38
|
+
it('should handle all empty parts', () => {
|
|
39
|
+
expect(resolveUrl('', '', '')).toBe('');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should handle multiple empty parts', () => {
|
|
43
|
+
expect(resolveUrl('http://example.com', '', 'path', '', 'resource')).toBe('http://example.com/path/resource');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should handle a single part URL', () => {
|
|
47
|
+
expect(resolveUrl('http://example.com')).toBe('http://example.com');
|
|
48
|
+
});
|
|
49
|
+
it('should handle a single part URL with trailing slash', () => {
|
|
50
|
+
expect(resolveUrl('http://example.com/')).toBe('http://example.com');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should handle a single part without protocol', () => {
|
|
54
|
+
expect(resolveUrl('example.com')).toBe('example.com');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should handle only slashes as input', () => {
|
|
58
|
+
expect(resolveUrl('///')).toBe('/');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should handle empty input', () => {
|
|
62
|
+
expect(resolveUrl()).toBe('');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should handle a leading slash in the first part', () => {
|
|
66
|
+
expect(resolveUrl('/root', 'sub', 'item')).toBe('/root/sub/item');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should handle relative paths', () => {
|
|
70
|
+
expect(resolveUrl('path', 'to', 'resource')).toBe('path/to/resource');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should handle dot in relative paths', () => {
|
|
74
|
+
expect(resolveUrl('path', '.', 'resource')).toBe('path/./resource');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should handle parts with special characters', () => {
|
|
78
|
+
expect(resolveUrl('http://example.com', 'path with spaces', 'another-part')).toBe('http://example.com/path with spaces/another-part');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should handle parts with encoded characters', () => {
|
|
82
|
+
//resolveURL should *not* decode.
|
|
83
|
+
expect(resolveUrl('http://example.com', 'path%20with%20encoded')).toBe('http://example.com/path%20with%20encoded');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should handle parts with plus sign +', () => {
|
|
87
|
+
//resolveURL should *not* decode.
|
|
88
|
+
expect(resolveUrl('http://example.com', 'path+with+plus')).toBe('http://example.com/path+with+plus');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should handle already clean URL', () => {
|
|
92
|
+
expect(resolveUrl('http://example.com/path/to/resource')).toBe('http://example.com/path/to/resource');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// it('should handle complex url 1', () => {
|
|
96
|
+
// expect(resolveUrl('http:////ali/', '///md////', '/65/////')).toBe('http://ali/md/65');
|
|
97
|
+
// });
|
|
98
|
+
it('should handle complex url 2', () => {
|
|
99
|
+
expect(resolveUrl('//no-protocol/', '/path////test/')).toBe('/no-protocol/path/test');
|
|
100
|
+
});
|
|
101
|
+
});
|