esm-path
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

esm-path

License CI Status Code Coverage NPM Version

Cross-platform ESM path helpers.

Why?

Because Node.js ESM path handling on Windows is messy with POSIX.

Install

npm i add -E esm-path

or:

yarn add -E esm-path

Usage

import { getAbsolutePath } from 'esm-path'

API

getAbsolutePath(importMetaUrl, ...relativePaths)

Definition

getAbsolutePath(importMetaUrl: string, ...relativePaths: string[]): string

Parameters

  • importMetaUrl: must always be import.meta.url.
  • ...relativePaths: list of paths, relative to the directory or file from which this function is called.

Return

Return the absolute path of the targetted directory or file.

Example

import { getAbsolutePath } from 'esm-path'

const currentDirectoryPath = getAbsolutePath(import.meta.url)
console.log(currentDirectoryPath)

const parentDirectoryPath = getAbsolutePath(import.meta.url, '..')
console.log(parentDirectoryPath)

// Adapt the relative path to your case
const packageJsonFilePath = getAbsolutePath(import.meta.url, '../package.json')
console.log(packageJsonFilePath)

// Adapt the relative path to your case
const packageJsonFilePath = getAbsolutePath(import.meta.url, '..' , 'package.json')
console.log(packageJsonFilePath)

Readme

Keywords

Package Sidebar

Install

npm i esm-path

Weekly Downloads

25

Version

1.0.1

License

MIT

Unpacked Size

6.47 kB

Total Files

6

Last publish

Collaborators

  • ivangabriele