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

esm-utils

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esm-utils

Utilities you need when migrating to ESModule.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

esm-utils

Utilities you need when migrating to ESModule.

Install

yarn add esm-utils

Usage

import createEsmUtils from 'esm-utils'

const {dirname, filename, json} = createEsmUtils(import.meta)

API

createEsmUtils(importMeta)

Returns a object with the properties

  • dirname (alias __dirname)
  • filename (alias __filename)
  • json
  • require

json.load(string | URL)

Returns Promise<jsonObject>.

json.loadSync(string | URL)

Sync version of json.load.

Import json file

With Import Assertions

import json from './path/to/you-json-file.json' assert {type: 'json'}

With require

import createEsmUtils from 'esm-utils'

const {require} = createEsmUtils(import.meta)
const json = require('./path/to/you-json-file.json')

With json.load

import createEsmUtils from 'esm-utils'

const {json} = createEsmUtils(import.meta)
const json = await json.load('./path/to/you-json-file.json')

FAQs

Package last updated on 13 May 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

  • 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