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

ast-module-types

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-module-types

Collection of useful helper functions when trying to determine module type (CommonJS or AMD) properties of an AST node.

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
698K
decreased by-59.47%
Maintainers
1
Weekly downloads
 
Created
Source

Collection of useful helper functions when trying to determine module type (CommonJS or AMD) properties of an AST node.

Assumes that you used Esprima to get the AST nodes.

npm install ast-module-types

API

Each of these takes in a single AST node argument and returns a boolean.

  • isDefine: if node matches an AMD define function call (defining a module)
  • isRequire: if node matches a require function all (declaring a dependency)
  • isTopLevelRequire: if node matches a require at the very top of the file.
  • isAMDDriverScriptRequire: if node matches an AMD driver script's require call require([deps], function)
  • isExports: if the node matches CommonJS module.exports or exports (defining a module)

Detecting the various forms of defining an AMD module

  • isNamedForm: if the node is a define call of the form: define('name', [deps], func)
  • isDependencyForm: if the node is a define call of the form: define([deps], func)
  • isFactoryForm: if the node is a define call of the form: define(func(require))
  • isNoDependencyForm: if the node is a define call of the form: define({})
  • isREMForm: if the node matches the form: define(function(require, exports, module){});

ES6 Types

  • isES6Import: if the node is of the form: import 'mylib' or import {something} from 'mylib'

Usage

var types = require('ast-module-types');

// Assume node is some node of an AST that you parsed using esprima or esprima-fb
// ...

console.log(types.isDefine(node));

Keywords

FAQs

Package last updated on 28 Oct 2014

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