@guanghechen/path 1.0.0-alpha.6 → 1.0.0-alpha.7

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 CHANGED
@@ -3,6 +3,17 @@
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
+ # [1.0.0-alpha.7](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.6...@guanghechen/path@1.0.0-alpha.7) (2023-10-16)
7
+
8
+
9
+ ### Performance Improvements
10
+
11
+ * 🎨 support 'preferSlash' option for 'relativexx' funcs ([e59d415](https://github.com/guanghechen/sora/commit/e59d415df8272f6a5b8afed1f57152e4b44c89b8))
12
+
13
+
14
+
15
+
16
+
6
17
  # [1.0.0-alpha.6](https://github.com/guanghechen/sora/compare/@guanghechen/path@1.0.0-alpha.5...@guanghechen/path@1.0.0-alpha.6) (2023-10-16)
7
18
 
8
19
 
package/lib/cjs/index.cjs CHANGED
@@ -54,14 +54,16 @@ class PathResolver {
54
54
  this.ensureAbsolute(filepath);
55
55
  return this._internalNormalize(filepath);
56
56
  }
57
- relative(from, to) {
57
+ relative(from, to, preferSlash = false) {
58
58
  this.ensureAbsolute(from, `[${clazz$1}.relative] from is not an absolute path: ${from}`);
59
59
  this.ensureAbsolute(to, `[${clazz$1}.relative] to is not an absolute path: ${to}`);
60
- return this._internalRelative(from, to);
60
+ const relativePath = this._internalRelative(from, to);
61
+ return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
61
62
  }
62
- safeRelative(root, filepath) {
63
+ safeRelative(root, filepath, preferSlash = false) {
63
64
  this.ensureSafeRelative(root, filepath);
64
- return this._internalSafeRelative(root, filepath);
65
+ const relativePath = this._internalSafeRelative(root, filepath);
66
+ return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
65
67
  }
66
68
  safeResolve(root, filepath) {
67
69
  this.ensureSafeRelative(root, filepath);
@@ -240,9 +242,9 @@ class WorkspacePathResolver {
240
242
  const { root, pathResolver } = this;
241
243
  return pathResolver.isSafeRelative(root, filepath);
242
244
  }
243
- relative(filepath) {
245
+ relative(filepath, preferSlash) {
244
246
  const { root, pathResolver } = this;
245
- return pathResolver.safeRelative(root, filepath);
247
+ return pathResolver.safeRelative(root, filepath, preferSlash);
246
248
  }
247
249
  resolve(filepath) {
248
250
  const { root, pathResolver } = this;
package/lib/esm/index.mjs CHANGED
@@ -48,14 +48,16 @@ class PathResolver {
48
48
  this.ensureAbsolute(filepath);
49
49
  return this._internalNormalize(filepath);
50
50
  }
51
- relative(from, to) {
51
+ relative(from, to, preferSlash = false) {
52
52
  this.ensureAbsolute(from, `[${clazz$1}.relative] from is not an absolute path: ${from}`);
53
53
  this.ensureAbsolute(to, `[${clazz$1}.relative] to is not an absolute path: ${to}`);
54
- return this._internalRelative(from, to);
54
+ const relativePath = this._internalRelative(from, to);
55
+ return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
55
56
  }
56
- safeRelative(root, filepath) {
57
+ safeRelative(root, filepath, preferSlash = false) {
57
58
  this.ensureSafeRelative(root, filepath);
58
- return this._internalSafeRelative(root, filepath);
59
+ const relativePath = this._internalSafeRelative(root, filepath);
60
+ return preferSlash ? relativePath.replaceAll('\\', '/') : relativePath;
59
61
  }
60
62
  safeResolve(root, filepath) {
61
63
  this.ensureSafeRelative(root, filepath);
@@ -234,9 +236,9 @@ class WorkspacePathResolver {
234
236
  const { root, pathResolver } = this;
235
237
  return pathResolver.isSafeRelative(root, filepath);
236
238
  }
237
- relative(filepath) {
239
+ relative(filepath, preferSlash) {
238
240
  const { root, pathResolver } = this;
239
- return pathResolver.safeRelative(root, filepath);
241
+ return pathResolver.safeRelative(root, filepath, preferSlash);
240
242
  }
241
243
  resolve(filepath) {
242
244
  const { root, pathResolver } = this;
@@ -27,8 +27,8 @@ declare class PathResolver implements IPathResolver {
27
27
  isSafeRelative(root: string, filepath: string): boolean;
28
28
  join(filepath: string, ...pathPieces: string[]): string | never;
29
29
  normalize(filepath: string): string | never;
30
- relative(from: string, to: string): string | never;
31
- safeRelative(root: string, filepath: string): string;
30
+ relative(from: string, to: string, preferSlash?: boolean): string | never;
31
+ safeRelative(root: string, filepath: string, preferSlash?: boolean): string;
32
32
  safeResolve(root: string, filepath: string): string;
33
33
  protected _internalNormalize(filepath: string): string;
34
34
  protected _internalRelative(from_: string, to_: string): string;
@@ -61,7 +61,7 @@ declare class WorkspacePathResolver implements IWorkspacePathResolver {
61
61
  constructor(root: string, pathResolver: IPathResolver);
62
62
  ensureSafePath(filepath: string, message?: string | undefined): void | never;
63
63
  isSafePath(filepath: string): boolean;
64
- relative(filepath: string): string | never;
64
+ relative(filepath: string, preferSlash?: boolean): string | never;
65
65
  resolve(filepath: string): string | never;
66
66
  }
67
67
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanghechen/path",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.7",
4
4
  "description": "Path utils.",
5
5
  "author": {
6
6
  "name": "guanghechen",
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.5",
11
+ "url": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.6",
12
12
  "directory": "packages/path"
13
13
  },
14
- "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.5/packages/path#readme",
14
+ "homepage": "https://github.com/guanghechen/sora/tree/@guanghechen/path@1.0.0-alpha.6/packages/path#readme",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -43,7 +43,7 @@
43
43
  "test": "node --experimental-vm-modules ../../node_modules/.bin/jest --config ../../jest.config.mjs --rootDir ."
44
44
  },
45
45
  "dependencies": {
46
- "@guanghechen/path.types": "^1.0.0-alpha.4"
46
+ "@guanghechen/path.types": "^1.0.0-alpha.5"
47
47
  },
48
- "gitHead": "e42cabded60b75856018c6f216d08b3d830a29b2"
48
+ "gitHead": "38989b3735fe6981d74cadb63568657247b77e14"
49
49
  }