1.0.8 • Published 2 years ago

parse-cwd v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

npm package License Quality

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.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

0.0.0

2 years ago