0.2.0 • Published 3 years ago

@suns-echoes/transform-esm-into-cjs v0.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

Transform ES modules into CommonJS

The transform-esm-into-cjs utility transforms ES6 modules into CommonJS without adding any unnecessary code.

Warning: If module exports default and named members, default member will be named "default".

Warning: If default and named members are imported from the same module, default member will be named "default".

Installation

npm i --save-dev @suns-echoes/transform-esm-into-cjs

Import

// Import utility distribution file
import { transformESMIntoCJS } from '@suns-echoes/transform-esm-into-cjs';
// Import utility from source
import { transformESMIntoCJS } from '@suns-echoes/transform-esm-into-cjs/src';
// or
import { transformESMIntoCJS } from '@suns-echoes/transform-esm-into-cjs/src/transform-esm-into-cjs';

Usage

const cjsCode = transformESMIntoCJS(esmCode, silent);

Arguments

  • <string> source - original source code (ESM);
  • <boolean> [silent=false] - Optional, mute warnings (def.: false).

Returns

  • <string> - transformed source code (CJS).

Examples

Transform ESM code into CJS code and mute warnings:

input string:

import { MyModule } from 'my-module';

transformation script:

const output = transformESMIntoCJS(input, true);

output string:

const { MyModule } = require('my-module');

License

Licensed under MIT

Copyright (c) 2021 Aneta Suns

0.2.0

3 years ago

0.1.2

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago