Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esm-path

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esm-path

Cross-platform ESM path helpers.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
60
increased by757.14%
Maintainers
1
Weekly downloads
 
Created
Source

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)

Keywords

FAQs

Package last updated on 28 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc