New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@a-la/import

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@a-la/import

A La Regex to transpile an import statement into require.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@a-la/import

npm version

@a-la/import is a a set of rules for alamode to transpile an import statement into require in Node.js.

À La Mode is a RegExp-based transpiler which works faster than AST-based transpilers such as @babel, and occupies only 100KB of disk space.

yarn add -E @a-la/import

Table Of Contents

API

The ALaImport is the default export and an array containing a sequence of rules for Replaceable.

import ALaImport from '@a-la/import'

ALaImport Sequence

The rule set exported as an array by ALaImport has multiple regexes and replacer functions to match all possible cases.

/* yarn example/ */
import { Replaceable } from 'restream'
import ALaImport from '@a-la/import'

const STRING = `import aLaMode from 'alamode'
import ALaImport from "@a-la/import"
import App from 'koa'
`

;(async () => {
  const stream = new Replaceable([
    ...ALaImport,
  ])
  await new Promise((r, j) => {
    stream.end(STRING, r)
    stream.on('error', j)
  })
  stream.pipe(process.stdout)
})()
const aLaMode = require('alamode')
const ALaImport = require("@a-la/import")
const App = require('koa')

Rules

The replacement sequence consists of a number of rules, which produce the most reliable result when put together. See Rule Type in documentary for more info about how rules work.

Default Rule

Allows to import the default export.

import helloWorld from 'hello-world'
Click to Show Details.

Example

import examplePackage from 'examplePackage'

RegExp

/^\s*import ([\w\d]+) from (["'])(.+?)\2/gm

Rule

const ImportDefaultRule = {
  re: /^\s*import ([\w\d]+) from (["'])(.+?)\2/gm,
  replacement(match, name, src) {
    const s = `const ${name} = require('${src}')`
    return s
  },
}

Output

const examplePackage = require('examplePackage')

(c) A La Mode 2018

Keywords

FAQs

Package last updated on 25 Jul 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