npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ranma

v0.5.0

Published

A converter between CommonJS/AMD/CMD/other

Downloads

14

Readme

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

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

NPM version Build Status Coverage Status Dependency Status

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

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

INSTALL

npm install ranma

API

  • cjsify(code:String):String

    • 将代码转换为CommonJS
    • 对于AMDCMD,会将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]