Socket
Socket
Sign inDemoInstall

rewrite-imports

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rewrite-imports

Rewrite `import` statements as `require()`s; via RegExp


Version published
Weekly downloads
37K
decreased by-4.87%
Maintainers
1
Weekly downloads
 
Created
Source

rewrite-imports Build Status

Rewrite import statements as require()s; via RegExp

Quickly transforms various import statements into ES5-compatible require() statements.

Note: This module returns a String and does not provide a runtime nor does it evaluate the output.

:bulb: For this behavior, visit rewrite-module or check out @taskr/esnext for an example!

Install

$ npm install --save rewrite-imports

Usage

const rewriteImports = require('rewrite-imports');

rewriteImports(`import foo from '../bar'`);
//=> const foo = require('../bar');

rewriteImports(`import { foo } from 'bar'`);
//=> const bar$1 = require('bar');
//=> const foo = bar$1.foo;

rewriteImports(`import * as path from 'path';`);
//=> const path = require('path');

rewriteImports(`import { foo as bar, baz as bat, lol } from 'quz';`);
//=> const quz$1 = require('quz');
//=> const bar = quz$1.foo;
//=> const bat = quz$1.baz;
//=> const lol = quz$1.lol;

API

rewriteImports(input)

input

Type: String

An import statement. See MDN for valid Syntax.

License

MIT © Luke Edwards

Keywords

FAQs

Package last updated on 10 Aug 2018

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