Socket
Book a DemoInstallSign in
Socket

@esmbly/core

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esmbly/core

A composable transpiler infrastructure for working with statically typed JavaScript and WebAssembly

0.0.6
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

@esmbly/core

The core of Esmbly.

This package is used by @esmbly/cli to parse the input files into AST representations and to run each provided transformer. It can also be used to run Esmbly programmatically.

Installation

Note: If you want to run the CLI you should install @esmbly/cli instead.

# Using Yarn:
yarn add @esmbly/core

# Or, using NPM:
npm install @esmbly/core --save

Usage

const esmbly = require('@esmbly/core');
const Flow = require('@esmbly/transformer-flow');
const Wasm = require('@esmbly/transformer-wasm');

const compile = content => {
  return esmbly.run({
    input: [
      {
        content,
        dir: '/',
        name: 'input',
        type: '.js',
      },
    ],
    output: [{ format: 'WebAssembly' }],
    transformers: [
      Flow.createTransformer(),
      Wasm.createTransformer()
    ],
  });
};

const program = `
  // @flow

  export function add(a: number, b: number): number {
    return a + b;
  }
`;

compile(program)
  .then(([{ content }]) => WebAssembly.instantiate(content, {}))
  .then(({ instance }) => console.log('2 + 3 = ' + instance.exports.add(2, 3))) // => 2 + 3 = 5
  .catch(err => console.log(err));

Configuration

The @esmbly/core API is very minimal. It exposes a single function called run which accepts a config object (see the RunConfig interface) where the following properties must be provided.

OptionDescriptionType
inputAn array of files that should be transformedFile[]
transformersAn array of transformer instances (created using the createTransformer() method, or any object/class that implements the Transformer interface). The transformers will run in the order that they are specified.Transformer[]
outputAn array of output objects. In other words - what kind of files do you want to output?Output[]
interface File {
  name: string;
  content: string | Buffer;
  dir: string;
  type: FileType;
}

interface Output {
  format: Format;
  outDir?: string;
  outFile?: string;
  rootDir?: string;
}

Contributing

All types of contributions are very much welcome. Check out our Contributing Guide for instructions on how to get started.

Keywords

esmbly

FAQs

Package last updated on 24 May 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.