Socket
Socket
Sign inDemoInstall

this-file

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

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.


Version published
Weekly downloads
61K
increased by3.24%
Maintainers
1
Install size
4.86 kB
Created
Weekly downloads
 

Readme

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

Last updated on 09 Jun 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc