@dephub/path 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2025 Estarlin R
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # @dephub/path πŸ—ΊοΈ
2
+
3
+ > Path resolution utilities for Node.js with ESM support - cwd and dirname helpers.
4
+
5
+ [![NPM version](https://img.shields.io/npm/v/@dephub/path.svg?style=flat)](https://npmjs.org/package/@dephub/path)
6
+ [![ESM-only](https://img.shields.io/badge/ESM-only-brightgreen?style=flat)](https://nodejs.org/)
7
+ [![Node.js version](https://img.shields.io/badge/node-%3E%3D22.5.0-brightgreen.svg)](https://nodejs.org/)
8
+
9
+ ---
10
+
11
+ ## Features ✨
12
+
13
+ - πŸ“ **Current Working Directory** - Resolve paths relative to current working directory
14
+ - πŸ“„ **Module Directory** - ESM-friendly replacement for `__dirname`
15
+ - 🎯 **TypeScript Ready** - Full type safety with zero configuration
16
+ - ⚑ **Lightweight** - Minimal utilities focused on path resolution
17
+
18
+ ---
19
+
20
+ ## Installation πŸ“¦
21
+
22
+ ```bash
23
+ npm install @dephub/path
24
+ # or
25
+ pnpm add @dephub/path
26
+ # or
27
+ yarn add @dephub/path
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Usage 🎯
33
+
34
+ ### Resolve Paths from Current Directory
35
+
36
+ ```typescript
37
+ import { cwd } from '@dephub/path';
38
+
39
+ // Get current working directory
40
+ console.log(cwd()); // /Users/user/project
41
+
42
+ // Resolve relative paths
43
+ const configPath = cwd('config', 'app.json');
44
+ // -> /Users/user/project/config/app.json
45
+ ```
46
+
47
+ ### Resolve Paths from Module Directory
48
+
49
+ ```typescript
50
+ import { dirname } from '@dephub/path';
51
+
52
+ // In file: /project/src/utils/helpers.ts
53
+ const utilsDir = dirname(import.meta);
54
+ // -> /project/src/utils
55
+
56
+ const dataPath = dirname(import.meta, 'data.json');
57
+ // -> /project/src/utils/data.json
58
+ ```
59
+
60
+ ### Real-world Example
61
+
62
+ ```typescript
63
+ import { cwd, dirname } from '@dephub/path';
64
+ import { readFile } from '@dephub/read';
65
+ import { writeFile } from '@dephub/write';
66
+
67
+ // Read config from project root
68
+ const config = await readFile(cwd('config.json'));
69
+
70
+ // Write output relative to current module
71
+ await writeFile(
72
+ dirname(import.meta, 'output', 'result.json'),
73
+ JSON.stringify(result, null, 2),
74
+ );
75
+ ```
76
+
77
+ ---
78
+
79
+ ## API Reference πŸ“š
80
+
81
+ ### `cwd(...paths)`
82
+
83
+ Resolves paths relative to current working directory.
84
+
85
+ **Parameters:**
86
+
87
+ - `...paths` (string[]) - Path segments to join
88
+
89
+ **Returns:** `string` - Absolute path
90
+
91
+ ### `dirname(meta, ...paths)`
92
+
93
+ ESM replacement for `__dirname` - resolves paths relative to module.
94
+
95
+ **Parameters:**
96
+
97
+ - `meta` (ImportMeta) - `import.meta` from calling module
98
+ - `...paths` (string[]) - Path segments to join
99
+
100
+ **Returns:** `string` - Absolute path
101
+
102
+ **Throws:** `Error` - If `import.meta` is not provided
103
+
104
+ ---
105
+
106
+ ## License πŸ“„
107
+
108
+ MIT License – see [LICENSE](LICENSE) for details.
109
+
110
+ **Author:** Estarlin R ([estarlincito.com](https://estarlincito.com))
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Resolves paths relative to the current working directory
3
+ * @param paths - Path segments to join with current working directory
4
+ * @returns Absolute path resolved from current working directory
5
+ * @example
6
+ * ```typescript
7
+ * import { cwd } from '@dephub/path';
8
+ *
9
+ * cwd(); // -> /Users/user/project
10
+ * cwd('src', 'index.ts'); // -> /Users/user/project/src/index.ts
11
+ * ```
12
+ */
13
+ export declare const cwd: (...paths: string[]) => string;
@@ -0,0 +1,6 @@
1
+ import r from "node:path";
2
+ import p from "node:process";
3
+ const e = (...o) => r.resolve(p.cwd(), ...o);
4
+ export {
5
+ e as cwd
6
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * ESM-friendly replacement for __dirname - resolves paths relative to current module
3
+ * @param meta - import.meta object from calling module
4
+ * @param paths - Path segments to join with module directory
5
+ * @returns Absolute path resolved from module directory
6
+ * @throws {Error} When import.meta is not provided or invalid
7
+ * @example
8
+ * ```typescript
9
+ * import { dirname } from '@dephub/path';
10
+ *
11
+ * // In file: /project/src/utils/helpers.ts
12
+ * dirname(import.meta); // -> /project/src/utils
13
+ * dirname(import.meta, 'data.json'); // -> /project/src/utils/data.json
14
+ * ```
15
+ */
16
+ export declare const dirname: (meta: ImportMeta, ...paths: string[]) => string;
@@ -0,0 +1,11 @@
1
+ import e from "node:path";
2
+ import { fileURLToPath as i } from "node:url";
3
+ const n = (r, ...t) => {
4
+ if (!r?.url)
5
+ throw new Error("dirname() requires import.meta as first argument");
6
+ const o = i(r.url);
7
+ return e.resolve(e.dirname(o), ...t);
8
+ };
9
+ export {
10
+ n as dirname
11
+ };
@@ -0,0 +1,2 @@
1
+ export { cwd } from './core/cwd.js';
2
+ export { dirname } from './core/dirname.js';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { cwd as e } from "./core/cwd.js";
2
+ import { dirname as d } from "./core/dirname.js";
3
+ export {
4
+ e as cwd,
5
+ d as dirname
6
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@dephub/path",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "Path resolution utilities for Node.js with ESM support - cwd and dirname helpers",
6
+ "types": "./dist/index.d.ts",
7
+ "main": "./dist/index.js",
8
+ "keywords": [
9
+ "path",
10
+ "resolution",
11
+ "esm",
12
+ "dirname",
13
+ "cwd",
14
+ "node",
15
+ "typescript",
16
+ "dephub",
17
+ "utilities"
18
+ ],
19
+ "author": {
20
+ "name": "Estarlin R",
21
+ "email": "dev@estarlincito.com",
22
+ "url": "https://estarlincito.com"
23
+ },
24
+ "engines": {
25
+ "node": ">=22.5.0"
26
+ },
27
+ "files": [
28
+ "LICENSE",
29
+ "README.md",
30
+ "dist"
31
+ ],
32
+ "license": "MIT",
33
+ "homepage": "https://github.com/dephubjs/path#readme",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/dephubjs/path.git",
37
+ "directory": "packages/path"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/dephubjs/path/issues"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "release": "pnpm publish",
47
+ "check-types": "tsc --noEmit --skipLibCheck",
48
+ "lint": "lint . --max-warnings 0",
49
+ "lint:fix": "lint . --fix",
50
+ "clean": "rm -rf dist",
51
+ "build": "vite build",
52
+ "dev": "vite build -w --mode development"
53
+ }
54
+ }