# ranma

> A converter between CommonJS/AMD/CMD/other

Latest version **0.5.0** (published 2015-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install ranma
pnpm add ranma
yarn add ranma
bun add ranma
```

## 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.5.0 |
| Published | 2015-12-17 |
| First published | 2014-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4.2 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Author | army8735 |
| Maintainers | army8735, asins |
| Keywords | convert, commonjs, amd, cmd, es6 module |

## Links

- npm: https://www.npmjs.com/package/ranma
- Repository: https://github.com/army8735/ranma
- Homepage: https://github.com/army8735/ranma#readme
- Issues: https://github.com/army8735/ranma/issues
- npm.io page: https://npm.io/package/ranma

## Dependencies (2)

- [jsdc](https://npm.io/package/jsdc.md) ^0.6.8
- [homunculus](https://npm.io/package/homunculus.md) ^0.10.4

## 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.5.0 (latest) — 2015-12-17
- 0.4.4 — 2015-02-05
- 0.4.2 — 2014-07-09
- 0.4.1 — 2014-07-09
- 0.4.0 — 2014-07-07
- 0.3.0 — 2014-07-07
- 0.2.0 — 2014-07-03
- 0.1.0 — 2014-06-06
- 0.0.13 — 2014-06-06
- 0.0.12 — 2014-06-04
- 0.0.11 — 2014-05-29
- 0.0.10 — 2014-05-23
- 0.0.9 — 2014-05-23
- 0.0.8 — 2014-04-14
- 0.0.7 — 2014-04-10
- … 6 more at https://npm.io/package/ranma/versions

## README

A converter between CommonJS/AMD/CMD/Module/other
====

ranma取自同名动漫人物乱马，意指同一个事物的不同形式。

[![NPM version](https://badge.fury.io/js/ranma.png)](https://npmjs.org/package/ranma)
[![Build Status](https://travis-ci.org/army8735/ranma.svg?branch=master)](https://travis-ci.org/army8735/ranma)
[![Coverage Status](https://coveralls.io/repos/army8735/ranma/badge.png)](https://coveralls.io/r/army8735/ranma)
[![Dependency Status](https://david-dm.org/army8735/ranma.png)](https://david-dm.org/army8735/ranma)

为满足所写的代码能同时运行于server环境和web环境，而不需手动修改，所以做了个转换方法，使得几者之间的模块能够互相等价转化。

需要注意的是AMD模块的写法应遵守文件和模块一对一的原则。

## INSTALL

```js
npm install ranma
```

## API

* cjsify(code:String):String
  * 将代码转换为`CommonJS`
  * 对于`AMD`和`CMD`，会将define的factory提取，改写return为module.exports并删除define，如果define父语句有if判断也会删除
  * 对于`es6 module`，会将module和import变为require，export变为exports，export default变为module.exports
  * 对于普通文件，会将全局声明的变量作为exports，全局使用的未声明变量作为require

* amdify(code:String):String
  * 将代码转换为`AMD`
  * 在cjsify的基础上进行define包裹
  * 如果代码是`CMD`不做修改，因为`AMD`兼容这种写法

* cmdify(code:String):String
  * 将代码转换为`CMD`
  * 在cjsify的基础上进行define包裹
  * 如果code是`AMD`类型，会进行依赖转化——即将factory的参数改为`CMD`的require, exports, module固定参数，同时依赖变为require变量声明

* type.isCommonJS(code:String):Boolean
  * code是否是`CommonJS`

* type.isAMD(code:String):Boolean
  * code是否是`AMD`

* type.isCMD(code:String):Boolean
  * code是否是`CMD`
  
* type.isModule(code:String):Boolean
  * code是否是`es6 module`

#### AMD和CMD的区分依据
* 是否出现`define.amd`的判断
* factory的参数是否为固定的`require, exports, module`

## License

[MIT License]

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