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

ranma

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ranma

A converter between CommonJS/AMD/CMD/other

  • 0.0.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
2
Weekly downloads
 
Created
Source

A converter between CommonJS/AMD/CMD/other

NPM version Build Status Coverage Status Dependency Status

为满足所写的代码能同时运行于server环境和web环境,而不需手动修改,所以做了个转换方法,使得几者之间的模块能够互相等价转化。
需要注意的是AMD模块的写法应遵守文件和模块一对一的原则。

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

INSTALL

npm install ranma

API

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

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

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

  • ranma.type.isCommonJS(code:String):Boolean
    code是否是CommonJS

  • ranma.type.isAMD(code:String):Boolean
    code是否是AMD

  • ranma.type.isCMD(code:String):Boolean
    code是否是CMD

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

License

[MIT License]

Keywords

FAQs

Package last updated on 04 Jun 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