Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivangabriele/esm-path
Cross-platform ESM path helpers.
https://github.com/ivangabriele/esm-path
Last synced: 17 days ago
JSON representation
Cross-platform ESM path helpers.
- Host: GitHub
- URL: https://github.com/ivangabriele/esm-path
- Owner: ivangabriele
- License: mit
- Created: 2022-02-28T13:16:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-05T10:27:42.000Z (5 months ago)
- Last Synced: 2024-10-13T05:08:29.446Z (about 1 month ago)
- Language: TypeScript
- Size: 240 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# esm-path
[![License][img-license]][lnk-license]
[![CI Status][img-github]][lnk-github]
[![Code Coverage][img-codecov]][lnk-codecov]
[![NPM Version][img-npm]][lnk-npm]Cross-platform ESM path helpers.
## Why?
Because Node.js ESM path handling on Windows is messy with POSIX.
## Install
```sh
npm i add -E esm-path
```or:
```sh
yarn add -E esm-path
```## Usage
```ts
import { getAbsolutePath } from 'esm-path'```
## API
### getAbsolutePath(importMetaUrl, ...relativePaths)
#### Definition
```ts
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
```ts
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)
```---
[img-codecov]: https://img.shields.io/codecov/c/github/ivangabriele/esm-path/main?style=flat-square
[img-github]: https://img.shields.io/github/workflow/status/ivangabriele/esm-path/Check/main?style=flat-square
[img-license]: https://img.shields.io/github/license/ivangabriele/esm-path?style=flat-square
[img-npm]: https://img.shields.io/npm/v/esm-path?style=flat-square
[lnk-codecov]: https://codecov.io/gh/ivangabriele/esm-path/branch/main
[lnk-github]: https://github.com/ivangabriele/esm-path/actions?query=branch%3Amain++
[lnk-license]: https://github.com/ivangabriele/esm-path/blob/main/LICENSE
[lnk-npm]: https://www.npmjs.com/package/esm-path