Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/popomore/defines
Lookup all define in js file and replace it.
https://github.com/popomore/defines
Last synced: about 2 months ago
JSON representation
Lookup all define in js file and replace it.
- Host: GitHub
- URL: https://github.com/popomore/defines
- Owner: popomore
- Created: 2014-06-09T10:54:43.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-09T10:55:21.000Z (over 10 years ago)
- Last Synced: 2024-11-20T04:43:46.227Z (about 2 months ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
Awesome Lists containing this project
README
# defines [![Build Status](https://travis-ci.org/popomore/defines.png?branch=master)](https://travis-ci.org/popomore/defines) [![Coverage Status](https://coveralls.io/repos/popomore/defines/badge.png?branch=master)](https://coveralls.io/r/popomore/defines?branch=master)
Lookup all define in js file and replace it.
---
## Install
```
$ npm install defines -g
```## Usage
Javascript file
```
define(function(){});define(['./a', './b'], function(a, b){});
```Get defines with code below
```
var defines = require('defines');
defines(fs.readFileSync('a.js'));
```yield
```
[
{
string: 'define(function(){})',
args: [
'function(){}'
]
},
{
string: 'define(["./a", "./b"], function(a, b){})',
args: [
['./a', './b'],
'function(a, b){}'
]
}
]
```Replace it with code below
```
var code = fs.readFileSync('a.js');
defines(code, function(args, index) {
if (index === 0) {
args.unshift('a');
}
});
```yield
```
define('a', function(){});define(['./a', './b'], function(a, b){});
```Detect if it contains `define`
```
var code = fs.readFileSync('a.js');
defines.hasDefine(code);
```## LISENCE
Copyright (c) 2014 popomore. Licensed under the MIT license.