@cratis/arc 22.27.1 → 22.27.2
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/dist/cjs/joinPaths.d.ts +1 -1
- package/dist/cjs/joinPaths.d.ts.map +1 -1
- package/dist/cjs/joinPaths.js +21 -2
- package/dist/cjs/joinPaths.js.map +1 -1
- package/dist/esm/for_joinPaths/when_joining_paths.d.ts +2 -0
- package/dist/esm/for_joinPaths/when_joining_paths.d.ts.map +1 -0
- package/dist/esm/for_joinPaths/when_joining_paths.js +17 -0
- package/dist/esm/for_joinPaths/when_joining_paths.js.map +1 -0
- package/dist/esm/joinPaths.d.ts +1 -1
- package/dist/esm/joinPaths.d.ts.map +1 -1
- package/dist/esm/joinPaths.js +21 -2
- package/dist/esm/joinPaths.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/for_joinPaths/when_joining_paths.ts +20 -0
- package/joinPaths.ts +25 -4
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { joinPaths } from '../joinPaths.js';
|
|
5
|
+
|
|
6
|
+
describe('when joining paths', () => {
|
|
7
|
+
it('should join ordinary segments', () => joinPaths('api', 'orders').should.equal('api/orders'));
|
|
8
|
+
it('should preserve a leading slash', () => joinPaths('/workbench', 'api').should.equal('/workbench/api'));
|
|
9
|
+
it('should collapse repeated slashes at each boundary', () => joinPaths('/workbench//', '///api//', '//orders').should.equal('/workbench/api/orders'));
|
|
10
|
+
it('should leave slashes within a segment alone', () => joinPaths('/a//b', 'c//d').should.equal('/a//b/c//d'));
|
|
11
|
+
it('should preserve an https scheme', () => joinPaths('https://example.com/', '/api').should.equal('https://example.com/api'));
|
|
12
|
+
it('should preserve an http scheme', () => joinPaths('http://example.com', '/api').should.equal('http://example.com/api'));
|
|
13
|
+
it('should preserve a scheme supplied as its own segment', () => joinPaths('https://', 'example.com', '/api').should.equal('https://example.com/api'));
|
|
14
|
+
it('should handle an empty first segment', () => joinPaths('', '/api').should.equal('/api'));
|
|
15
|
+
it('should handle empty middle segments', () => joinPaths('/api', '', 'orders').should.equal('/api/orders'));
|
|
16
|
+
it('should preserve the separator between two empty segments', () => joinPaths('', '').should.equal('/'));
|
|
17
|
+
it('should handle no segments', () => joinPaths().should.equal(''));
|
|
18
|
+
it('should preserve a trailing slash', () => joinPaths('/api/', 'orders/').should.equal('/api/orders/'));
|
|
19
|
+
it('should preserve a trailing slash for an empty final segment', () => joinPaths('/api', '').should.equal('/api/'));
|
|
20
|
+
});
|
package/joinPaths.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
// Copyright (c) Cratis. All rights reserved.
|
|
2
2
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
function trimTrailingSlashes(path: string): string {
|
|
5
|
+
let end = path.length;
|
|
6
|
+
while (end > 0 && path[end - 1] === '/') {
|
|
7
|
+
end--;
|
|
8
|
+
}
|
|
9
|
+
return path.slice(0, end);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function trimLeadingSlashes(path: string): string {
|
|
13
|
+
let start = 0;
|
|
14
|
+
while (start < path.length && path[start] === '/') {
|
|
15
|
+
start++;
|
|
16
|
+
}
|
|
17
|
+
return path.slice(start);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function joinPaths(...paths: string[]): string {
|
|
21
|
+
let joined = paths[0] ?? '';
|
|
22
|
+
for (const path of paths.slice(1)) {
|
|
23
|
+
const base = joined.endsWith('://') ? joined : trimTrailingSlashes(joined);
|
|
24
|
+
const segment = trimLeadingSlashes(path);
|
|
25
|
+
joined = `${base}${base.endsWith('://') ? '' : '/'}${segment}`;
|
|
26
|
+
}
|
|
27
|
+
return joined;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@cratis/arc",
|
|
4
|
-
"version": "22.27.
|
|
4
|
+
"version": "22.27.2",
|
|
5
5
|
"description": "TypeScript command, query, validation, identity, and messaging runtime for Cratis Arc — the CQRS application framework for ASP.NET Core — used by generated proxies.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"cratis",
|