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

ascjs

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ascjs

ES2015 to CommonJS import/export transformer

  • 0.1.1
  • Source
  • npm
  • Socket score

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

ascjs

License: ISC Build Status Coverage Status donate

ES2015 to CommonJS import/export transformer


This module does one thing only: it loosely transpiles ES2015 import/export statements into valid CommonJS in order to fix the only part of Node that's incompatible with modern JS.

Features

  • extremely lightweight, based on cherow for performance and reliability, it transforms only imports/exports ignoring everything else
  • produces modern JavaScript, you are in charge of extra transformations if needed
  • indentation, spaces, semi or no-semi are preserved: beautiful source code remains beautiful
  • uses same Babel convention, resolving export default ... intent as exports.default
  • you can finally write .js code and transform it for Node only before publishing on npm
  • you could write .mjs modules and transform them into CommonJS for Browserify or other bundlers as target

Constrains

  • live bindings for exported values are not preserved. You need to delegate in scope eventual changes
  • dynamic import(...) is untouched. If you write that, let Webpack handle it for you later on
  • there is no magic whatsoever in module names resolution, what you write in ESM is what you get as CJS

Example

This module can transform the following ES2015+ code

import func, {a, b} from './module.js';
import * as tmp from 'other';

const val = 123;

export default function test() {
  console.log('ascjs');
};

export {func, val};

into the following one:

const func = (m => m.__esModule ? m : {default: m})(require('./module.js')).default;
const {a, b} = func;
const tmp = require('other');

const val = 123;

function test() {
  console.log('ascjs');
}
Object.defineProperty(exports, '__esModule', {value: true}).default = test;

exports.func = func;
exports.val = val;

Keywords

FAQs

Package last updated on 17 Oct 2017

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