shelving 1.193.0 → 1.193.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.193.0",
3
+ "version": "1.193.2",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,4 @@
1
- import { isPathActive, isPathProud, requireAbsolutePath } from "../util/path.js";
1
+ import { isPathActive, isPathProud, requirePath } from "../util/path.js";
2
2
  import { BusyStore } from "./BusyStore.js";
3
3
  /**
4
4
  * Store an absolute path, e.g. `/a/b/c`
@@ -10,12 +10,12 @@ export class PathStore extends BusyStore {
10
10
  base;
11
11
  // Override to set default path to `.` and base to `/`
12
12
  constructor(path = ".", base = "/") {
13
- super(requireAbsolutePath(path, base, PathStore));
13
+ super(requirePath(path, base, PathStore));
14
14
  this.base = base;
15
15
  }
16
16
  // Override to convert a possible path to an absolute path (relative to `this.base`).
17
17
  _convert(possible, caller) {
18
- return requireAbsolutePath(possible, this.base, caller);
18
+ return requirePath(possible, this.base, caller);
19
19
  }
20
20
  // Override for fast equality.
21
21
  _equal(a, b) {
@@ -31,7 +31,7 @@ export class PathStore extends BusyStore {
31
31
  }
32
32
  /** Get an absolute path from a path relative to the current store path. */
33
33
  getPath(path) {
34
- return requireAbsolutePath(path, this.value);
34
+ return requirePath(path, this.value);
35
35
  }
36
36
  toString() {
37
37
  return this.value;
package/util/path.d.ts CHANGED
@@ -3,12 +3,10 @@ import type { AnyCaller } from "./function.js";
3
3
  import type { Nullish } from "./null.js";
4
4
  /** Absolute path string starts with `/` slash. */
5
5
  export type AbsolutePath = `/` | `/${string}`;
6
- /** Base path string starts with `/` slash and ends with `/` */
7
- export type BasePath = `/` | `/${string}`;
8
6
  /** Relative path string is `.` dot, or starts with `./` dot slash. */
9
7
  export type RelativePath = `.` | `./` | `./${string}`;
10
- /** Simple path string like `a/b/c` */
11
- export type SimplePath = string;
8
+ /** Either an absolute or relative path. */
9
+ export type Path = AbsolutePath | RelativePath;
12
10
  /** Things that can be converted to a path. */
13
11
  export type PossiblePath = string;
14
12
  /** List of non-empty path segments. */
@@ -44,7 +42,7 @@ export declare function joinPath(...segments: PathSegments): AbsolutePath;
44
42
  * @param base Absolute path used for resolving relative paths in `possible`
45
43
  * @return Absolute path with a leading slash but no trailing slash, e.g. `/a/c/b`
46
44
  */
47
- export declare function getAbsolutePath(path: Nullish<PossiblePath>, base?: AbsolutePath): AbsolutePath | undefined;
45
+ export declare function getPath(path: Nullish<PossiblePath>, base?: AbsolutePath): AbsolutePath | undefined;
48
46
  /**
49
47
  * Resolve a relative or absolute path and return the path, or throw `RequiredError` if not a valid path.
50
48
  * - Internally uses `new URL` to do path processing but shouldn't ever reveal that fact.
@@ -54,13 +52,13 @@ export declare function getAbsolutePath(path: Nullish<PossiblePath>, base?: Abso
54
52
  * @param base Absolute path used for resolving relative paths in `possible`
55
53
  * @return Absolute path with a leading trailing slash, e.g. `/a/c/b`
56
54
  */
57
- export declare function requireAbsolutePath(path: AbsolutePath | RelativePath, base?: AbsolutePath, caller?: AnyCaller): AbsolutePath;
55
+ export declare function requirePath(path: PossiblePath, base?: AbsolutePath, caller?: AnyCaller): AbsolutePath;
58
56
  /**
59
57
  * Match and strip a base path prefix from a path using segment-aware pathname rules.
60
58
  * - Both inputs must be absolute paths that begin with `/`.
61
59
  * - Returns `/` when the paths are an exact match.
62
60
  */
63
- export declare function matchPathPrefix(target: AbsolutePath | RelativePath, base: AbsolutePath, caller?: AnyCaller): AbsolutePath | undefined;
61
+ export declare function matchPathPrefix(target: PossiblePath, base: PossiblePath, caller?: AnyCaller): AbsolutePath | undefined;
64
62
  /** Is a target path active? */
65
63
  export declare function isPathActive(target: AbsolutePath, current: AbsolutePath): boolean;
66
64
  /** Is a target path proud (i.e. is the current path, or is a child of the current path)? */
package/util/path.js CHANGED
@@ -48,7 +48,7 @@ export function joinPath(...segments) {
48
48
  * @param base Absolute path used for resolving relative paths in `possible`
49
49
  * @return Absolute path with a leading slash but no trailing slash, e.g. `/a/c/b`
50
50
  */
51
- export function getAbsolutePath(path, base = "/") {
51
+ export function getPath(path, base = "/") {
52
52
  if (!path)
53
53
  return;
54
54
  if (path === "/")
@@ -66,8 +66,8 @@ export function getAbsolutePath(path, base = "/") {
66
66
  * @param base Absolute path used for resolving relative paths in `possible`
67
67
  * @return Absolute path with a leading trailing slash, e.g. `/a/c/b`
68
68
  */
69
- export function requireAbsolutePath(path, base, caller = requireAbsolutePath) {
70
- const output = getAbsolutePath(path, base);
69
+ export function requirePath(path, base, caller = requirePath) {
70
+ const output = getPath(path, base);
71
71
  if (!output)
72
72
  throw new RequiredError("Invalid path", { received: path, caller });
73
73
  return output;
@@ -78,8 +78,8 @@ export function requireAbsolutePath(path, base, caller = requireAbsolutePath) {
78
78
  * - Returns `/` when the paths are an exact match.
79
79
  */
80
80
  export function matchPathPrefix(target, base, caller = matchPathPrefix) {
81
- const basePath = requireAbsolutePath(base, undefined, caller);
82
- const targetPath = requireAbsolutePath(target, basePath, caller);
81
+ const basePath = requirePath(base, undefined, caller);
82
+ const targetPath = requirePath(target, basePath, caller);
83
83
  if (basePath === "/")
84
84
  return targetPath;
85
85
  if (targetPath === basePath)