Skip to content

tbranyen/js-module-formats

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Javascript Module Formats

Build Status Dependency Status npm Version

Microlibrary to detect different types of javascript modules formats from a javascript file.

Goals, Overview & Features

With the new ES Module syntax arrival, projects will comence the transition to write modules in ES format, and in some cases, rewrite/adjust modules to be ES module. As a result, complex applications might ended up having multiple module formats in their application, while the proper transpile process will be necessary. This microlibrary will help you to detect what type of module does a javascript file defines, and take the appropiate steps based on that information.

Installation

Install using npm:

$ npm install js-module-formats

Usage

By calling detect() with a filesystem path, it returns one of the following values:

  • yui Modules
  • amd Modules
  • cjs CommonJS modules (including nodejs modules)
  • es Modules
  • undefined if the detection fails

To detect the module format of a file called file.js:

var detect = require('js-module-formats').detect,

console.log(detect(__dirname + '/file.js'));

Note: ES modules without import or export statements will not be detected.

License

This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.

About

Detect different types of javascript modules formats

Resources

License

Stars

Watchers

Forks

Packages

No packages published