New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

require-esmodule

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

require-esmodule

require a compiled es6 module and handle exports.default

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Build Status Coverage

require-esmodule

require a compiled es6 module and handle exports.default.

Install

$ npm i require-esmodule

Usage

// foo.js
Object.defineProperty(exports, '__esModule', {value: true})

exports.default = {
  foo: 'default-foo'
}

exports.foo = 'foo'
// bar.js
module.exports = {
  default: {
    bar: 'default-bar'
  },
  bar: 'bar'
}
// baz.js
module.exports = null
// qux.js
const {
  requireModule,
  getExports
} = require('require-esmodule')

console.log(requireModule('/path/to/foo').foo)         // 'default-foo'

console.log(requireModule('/path/to/foo', false).foo)  // 'foo'

console.log(requireModule('/path/to/bar').bar)         // 'bar'
// bar.js is not a es6 module

console.log(requireModule('/path/to/baz'))             // null

requireModule(id: string, requireDefault? : boolean = true)

  • id string ABSOLUTE path of the module
  • requireDefault? boolean=true whether should require export default. Defaults to true.

Returns any the module exports

requireDefault as false

const foo = requireModule('./foo', false)

is equivalent to:

import * as foo from './foo'

while

const foo = requireModule('./foo')

is equivalent to:

import foo from './foo'

The purpose of require-esmodule is to detect and make it easier to get the default exports of es modules, so the default value of requireDefault is set to true

getExports(exports: any, requireDefault?)

Detect and get the real exports from the return value of require(id)

License

MIT

Keywords

require-esmodule

FAQs

Package last updated on 07 Sep 2019

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