# js-module-formats

> Detect different types of JavaScript modules formats

Latest version **0.1.2** (published 2014-04-21) · BSD license · 0 weekly downloads

## Install

```sh
npm install js-module-formats
pnpm add js-module-formats
yarn add js-module-formats
bun add js-module-formats
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2014-04-21 |
| First published | 2014-03-05 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Caridy Patino |
| Maintainers | caridy |
| Keywords | JavaScript, module, es6, amd, yui, cjs |

## Links

- npm: https://www.npmjs.com/package/js-module-formats
- Repository: https://github.com/yahoo/js-module-formats
- Issues: https://github.com/yahoo/js-module-formats/issues
- npm.io page: https://npm.io/package/js-module-formats

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.1.2 (latest) — 2014-04-21
- 0.1.1 — 2014-03-31
- 0.1.0 — 2014-03-17
- 0.0.2 — 2014-03-05
- 0.0.1 — 2014-03-05

## README

JavaScript Module Formats
=========================

[![Build Status](https://travis-ci.org/yahoo/js-module-formats.png?branch=master)](https://travis-ci.org/yahoo/js-module-formats)
[![Dependency Status](https://gemnasium.com/yahoo/js-module-formats.png)](https://gemnasium.com/yahoo/js-module-formats)
[![npm Version](https://badge.fury.io/js/js-module-formats.png)](https://npmjs.org/package/js-module-formats)

Micro library to detect different types of JavaScript modules formats given some JavaScript source code.


Goals, Overview & Features
--------------------------

With the new ES Module syntax arrival, projects will commence 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 micro library will help you to detect what type of module does a JavaScript file defines, and take the appropriate steps based on that information.


Installation
------------

Install using npm:

```shell
$ npm install js-module-formats
```


Usage
-----

By calling `detect()` with JavaScript source code, 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`:

```javascript
var fs            = require('fs'),
    moduleFormats = require('js-module-formats').detect;

var source = fs.readFileSync(__dirname + '/file.js', 'utf8');

console.log(moduleFormats.detect(source));
```

**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.

[LICENSE file]: https://github.com/yahoo/js-module-formats/blob/master/LICENSE

---
_Source: https://npm.io/package/js-module-formats · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
