1.1.2 • Published 4 months ago

parse-cwd v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

>parse-cwd

Parse full current working directory from relative path or URL.

npm package License

Contents

Introduction

Parses the full path to current working directory.

Validates that directory actually exists.

Install

npm i parse-cwd

Example

import { parseCwd } from 'parse-cwd';

console.log(process.cwd()); // /path/to/cwd
console.log(import.meta.url); // file:///path/to/cwd/foo/bar/my-file.js

console.log(await parseCwd()); // /path/to/cwd
console.log(await parseCwd(process.cwd())); // /path/to/cwd
console.log(await parseCwd('foo/bar/my-file.js')); // /path/to/cwd/foo/bar
console.log(await parseCwd('./foo/bar/my-file.js')); // /path/to/cwd/foo/bar
console.log(await parseCwd(import.meta.url)); // /path/to/cwd/foo/bar
console.log(await parseCwd(new URL(import.meta.url))); // /path/to/cwd/foo/bar
console.log(await parseCwd({ cwd: 'foo/bar/my-file.js' })); // /path/to/cwd/foo/bar

// Error - Directory not found
await parseCwd('does/not/exist');

Usage

parse-cwd is an ESM module. That means it must be imported. To load from a CJS module, use dynamic import const { parseCwd } = await import('parse-cwd');.

API

parseCwd(cwd)

  • cwd
    • file path to resolve to URL
    • Type: string or URL or null
    • optional, defaults to process.cwd()
    • Optionally wrap as an object, e.g. { cwd: '/foo/bar' }
      • Convenient for directly passing higher level options object
1.1.1

5 months ago

1.1.0

5 months ago

1.1.2

4 months ago

1.0.13

7 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.9

10 months ago

1.0.10

10 months ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

0.0.0

3 years ago