@zokugun/fs-path 0.1.0

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 (67) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +153 -0
  3. package/lib/cjs/absolute.cjs +6 -0
  4. package/lib/cjs/absolute.d.cts +3 -0
  5. package/lib/cjs/dir.cjs +6 -0
  6. package/lib/cjs/dir.d.cts +3 -0
  7. package/lib/cjs/index.cjs +50 -0
  8. package/lib/cjs/index.d.cts +47 -0
  9. package/lib/cjs/is-in-dir.cjs +18 -0
  10. package/lib/cjs/is-in-dir.d.cts +3 -0
  11. package/lib/cjs/is-in-dirs.cjs +38 -0
  12. package/lib/cjs/is-in-dirs.d.cts +3 -0
  13. package/lib/cjs/is-safe-path.cjs +42 -0
  14. package/lib/cjs/is-safe-path.d.cts +8 -0
  15. package/lib/cjs/is-safe-segment.cjs +27 -0
  16. package/lib/cjs/is-safe-segment.d.cts +4 -0
  17. package/lib/cjs/join.cjs +14 -0
  18. package/lib/cjs/join.d.cts +3 -0
  19. package/lib/cjs/parent.cjs +14 -0
  20. package/lib/cjs/parent.d.cts +3 -0
  21. package/lib/cjs/platform.cjs +67 -0
  22. package/lib/cjs/platform.d.cts +2 -0
  23. package/lib/cjs/resolve.cjs +42 -0
  24. package/lib/cjs/resolve.d.cts +3 -0
  25. package/lib/cjs/sanitize.cjs +62 -0
  26. package/lib/cjs/sanitize.d.cts +10 -0
  27. package/lib/cjs/types.cjs +2 -0
  28. package/lib/cjs/types.d.cts +34 -0
  29. package/lib/cjs/untildify.cjs +25 -0
  30. package/lib/cjs/untildify.d.cts +3 -0
  31. package/lib/cjs/utils/get-home.cjs +12 -0
  32. package/lib/cjs/utils/get-home.d.cts +1 -0
  33. package/lib/cjs/utils/get-user-home.cjs +18 -0
  34. package/lib/cjs/utils/get-user-home.d.cts +1 -0
  35. package/lib/esm/absolute.d.mts +3 -0
  36. package/lib/esm/absolute.mjs +3 -0
  37. package/lib/esm/dir.d.mts +3 -0
  38. package/lib/esm/dir.mjs +3 -0
  39. package/lib/esm/index.d.mts +47 -0
  40. package/lib/esm/index.mjs +29 -0
  41. package/lib/esm/is-in-dir.d.mts +3 -0
  42. package/lib/esm/is-in-dir.mjs +15 -0
  43. package/lib/esm/is-in-dirs.d.mts +3 -0
  44. package/lib/esm/is-in-dirs.mjs +35 -0
  45. package/lib/esm/is-safe-path.d.mts +8 -0
  46. package/lib/esm/is-safe-path.mjs +36 -0
  47. package/lib/esm/is-safe-segment.d.mts +4 -0
  48. package/lib/esm/is-safe-segment.mjs +21 -0
  49. package/lib/esm/join.d.mts +3 -0
  50. package/lib/esm/join.mjs +11 -0
  51. package/lib/esm/parent.d.mts +3 -0
  52. package/lib/esm/parent.mjs +11 -0
  53. package/lib/esm/platform.d.mts +2 -0
  54. package/lib/esm/platform.mjs +61 -0
  55. package/lib/esm/resolve.d.mts +3 -0
  56. package/lib/esm/resolve.mjs +36 -0
  57. package/lib/esm/sanitize.d.mts +10 -0
  58. package/lib/esm/sanitize.mjs +56 -0
  59. package/lib/esm/types.d.mts +34 -0
  60. package/lib/esm/types.mjs +1 -0
  61. package/lib/esm/untildify.d.mts +3 -0
  62. package/lib/esm/untildify.mjs +22 -0
  63. package/lib/esm/utils/get-home.d.mts +1 -0
  64. package/lib/esm/utils/get-home.mjs +6 -0
  65. package/lib/esm/utils/get-user-home.d.mts +1 -0
  66. package/lib/esm/utils/get-user-home.mjs +12 -0
  67. package/package.json +83 -0
@@ -0,0 +1,34 @@
1
+ import { type Target } from '@zokugun/fs-path-sanitize';
2
+ import { type DResult } from '@zokugun/xtry';
3
+ export type PlatformPath = {
4
+ readonly delimiter: ';' | ':';
5
+ readonly separator: '\\' | '/';
6
+ readonly posix: PlatformPath;
7
+ readonly win32: PlatformPath;
8
+ absolute: (...paths: string[]) => string;
9
+ dir: (path: string) => string;
10
+ extension: (path: string) => string;
11
+ isAbsolute: (path: string) => boolean;
12
+ isInDir: (file: string, dir: string) => boolean;
13
+ isInDirs: (file: string, directories: string[]) => boolean;
14
+ isSafePath: (path: string, options?: {
15
+ parent?: string | null;
16
+ parents?: string | string[] | null;
17
+ target?: Target | 'auto';
18
+ }) => boolean;
19
+ isSafeSegment: (segment: string, target?: Target | 'auto') => boolean;
20
+ join: (...paths: string[]) => string;
21
+ leaf: (path: string, suffix?: string) => string;
22
+ matchesGlob?: (path: string, pattern: string) => boolean;
23
+ normalize: (path: string) => string;
24
+ parent: (file: string) => string;
25
+ relative: (from: string, to: string) => string;
26
+ resolve: (...paths: string[]) => string;
27
+ sanitize: (path: string, options?: {
28
+ parent?: string | null;
29
+ parents?: string | string[] | null;
30
+ replacement?: string | null;
31
+ target?: Target | 'auto';
32
+ }) => DResult<string>;
33
+ untildify: (path: string) => string;
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type path from 'node:path';
2
+ import { type PlatformPath } from './types.mjs';
3
+ export declare function untildify(_nodePath: path.PlatformPath, _localPath: PlatformPath): (path: string) => string;
@@ -0,0 +1,22 @@
1
+ import { isString } from '@zokugun/is-it-type';
2
+ import { getHome } from './utils/get-home.mjs';
3
+ import { getUserHome } from './utils/get-user-home.mjs';
4
+ const TILDE_REGEX = /^~(?=$|\/|\\)/;
5
+ const USER_REGEX = /^~([^/\\]+)(.*)$/;
6
+ export function untildify(_nodePath, _localPath) {
7
+ return (path) => {
8
+ const homedir = getHome();
9
+ if (isString(homedir) && TILDE_REGEX.test(path)) {
10
+ return homedir + path.slice(1);
11
+ }
12
+ const match = USER_REGEX.exec(path);
13
+ if (match) {
14
+ const [, username, rest] = match;
15
+ const userHome = getUserHome(username);
16
+ if (isString(userHome)) {
17
+ return userHome + rest;
18
+ }
19
+ }
20
+ return path;
21
+ };
22
+ }
@@ -0,0 +1 @@
1
+ export declare function getHome(): string;
@@ -0,0 +1,6 @@
1
+ import os from 'node:os';
2
+ let $home;
3
+ export function getHome() {
4
+ $home ??= os.homedir();
5
+ return $home;
6
+ }
@@ -0,0 +1 @@
1
+ export declare function getUserHome(username: string): string | null;
@@ -0,0 +1,12 @@
1
+ import os from 'node:os';
2
+ import { getHome } from './get-home.mjs';
3
+ let $username;
4
+ export function getUserHome(username) {
5
+ $username ??= os.userInfo().username;
6
+ if (username === $username) {
7
+ return getHome();
8
+ }
9
+ else {
10
+ return null;
11
+ }
12
+ }
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@zokugun/fs-path",
3
+ "description": "Path utilities complementing the builtin path module",
4
+ "version": "0.1.0",
5
+ "author": {
6
+ "name": "Baptiste Augrain",
7
+ "email": "daiyam@zokugun.org"
8
+ },
9
+ "license": "MIT",
10
+ "homepage": "https://github.com/zokugun/node-fs-path",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/zokugun/node-fs-path.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/zokugun/node-fs-path/discussions/categories/issue-triage"
17
+ },
18
+ "type": "module",
19
+ "main": "lib/cjs/index.cjs",
20
+ "module": "lib/esm/index.mjs",
21
+ "scripts": {
22
+ "audit:fix": "npm audit fix --min-release-age=0",
23
+ "build": "npm run clean && npm run build:lib",
24
+ "build:lib": "tsc-leda generate",
25
+ "build:package": "tsc-leda update-package && npm run lint:package",
26
+ "ci:lint": "zizmor .",
27
+ "ci:lint:fix": "zizmor . --fix=all",
28
+ "clean": "rimraf lib; rimraf .src; rimraf .test",
29
+ "compile:src": "tsc -p src",
30
+ "compile:test": "tsc -p test",
31
+ "lint": "xo",
32
+ "lint:all": "npm audit && npm run lint:package && npm run ci:lint && npm run lint",
33
+ "lint:fix": "xo --fix",
34
+ "lint:package": "fixpack || true",
35
+ "prepack": "npm run build",
36
+ "prepare": "husky; npm run lint:package",
37
+ "release": "release-it",
38
+ "test": "vitest run --reporter tree",
39
+ "test:coverage": "vitest run --reporter tree --coverage --coverage.reporter text",
40
+ "test:ui": "vitest --ui --coverage",
41
+ "test:watch": "vitest",
42
+ "update:artifacts": "artifact update",
43
+ "update:ci": "PINACT_MIN_AGE=7 pinact run --update",
44
+ "update:deps": "taze --all",
45
+ "watch:build": "tsc-watch -p src --onSuccess 'npm run build'",
46
+ "watch:src": "tsc-watch -p src",
47
+ "watch:test": "tsc-watch -p test"
48
+ },
49
+ "dependencies": {
50
+ "@zokugun/fs-path-sanitize": "0.1.0",
51
+ "@zokugun/is-it-type": "0.8.1",
52
+ "@zokugun/xtry": "0.11.6"
53
+ },
54
+ "devDependencies": {
55
+ "@commitlint/cli": "20.5.3",
56
+ "@commitlint/config-conventional": "20.5.3",
57
+ "@types/node": "20.19.39",
58
+ "@vitest/coverage-v8": "4.1.5",
59
+ "@vitest/ui": "4.1.5",
60
+ "@zokugun/fs-extra-plus": "0.4.1",
61
+ "@zokugun/tsc-leda": "0.4.1",
62
+ "fixpack": "4.0.0",
63
+ "globby": "16.2.0",
64
+ "husky": "9.1.7",
65
+ "lint-staged": "16.4.0",
66
+ "release-it": "20.0.1",
67
+ "rimraf": "6.1.3",
68
+ "taze": "19.14.1",
69
+ "tsc-watch": "7.2.0",
70
+ "typescript": "5.9.3",
71
+ "vitest": "4.1.5",
72
+ "xo": "0.60.0"
73
+ },
74
+ "overrides": {
75
+ "ajv": {
76
+ "fast-uri": "3.1.2"
77
+ },
78
+ "@inquirer/core": {
79
+ "mute-stream": "3.0.0"
80
+ }
81
+ },
82
+ "keywords": []
83
+ }