You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

this-file

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

this-file

If you are an author of open source repository, you may want to support both CJS and ESM for users since it's a confused period. It's hard to use `__dirname` and `import.meta.url` in one file specially for typescript project.

2.0.3
latest
Source
npmnpm
Version published
Weekly downloads
235K
1.82%
Maintainers
1
Weekly downloads
 
Created
Source

this-file

If you are an author of open source repository, you may want to support both CJS and ESM for users since it's a confused period. It's hard to use __dirname and import.meta.url in one file specially for typescript project.

Installation

yarn add this-file

Usage

// In per file
import { createContext } from 'this-file';

const context = createContext();

// CJS
context.filename IS __filename
context.dirname IS __dirname
context.require IS require

// ESM
context.filename IS url.fileURLToPath(import.meta.url)
context.dirname IS path.dirname(context.filename)
context.require IS module.createContext(import.meta.url)

FAQs

Package last updated on 09 Jun 2021

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.