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

cjs-esm

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cjs-esm

Another CommonJs transform ESModule lib.

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

cjs-esm

Another CommonJs transform ESModule lib.

NPM version NPM Downloads

English | 简体中文

Usage

import cjs2esm from 'cjs-esm'
// or
// const cjs2esm = require('cjs-esm').default

const { code, map } = cjs2esm(`const fs = require('fs')`)

TODO

❌ Nested scope(function-scope)

❌ Dynamic require id

✅ require statement

// Top-level scope
const foo = require('foo').defaultimport foo from 'foo';

const foo = require('foo')
↓
import * as foo from 'foo';

const foo = require('foo').barimport * as __CJS_import__0__ from 'foo'; const { bar: foo } = __CJS_import__0__;

// Non top-level scope
const foo = [{ bar: require('foo').bar }]
↓
import * as __CJS_import__0__ from 'foo'; const foo = [{ bar: __CJS_import__0__.bar }]

✅ exports statement

module.exports = fn() { };
↓
const __CJS__export_default__ = module.exports = fn() { };
export { __CJS__export_default__ as default }

exports.foo = 'foo';
↓
const __CJS__export_foo__ = (module.exports == null ? {} : module.exports).foo;
export { __CJS__export_foo__ as foo }

FAQs

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