第一次提交
This commit is contained in:
13
node_modules/js/History.md
generated
vendored
Normal file
13
node_modules/js/History.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
0.1.0 / 2013-04-24
|
||||
==================
|
||||
|
||||
* Add silent flag.
|
||||
* Add ugly output mode.
|
||||
* Attempt to parse code both in expression and statement list contexts.
|
||||
* Use expression result as status.
|
||||
|
||||
0.0.1 / 2013-04-22
|
||||
==================
|
||||
|
||||
* Initial release.
|
||||
21
node_modules/js/LICENSE
generated
vendored
Normal file
21
node_modules/js/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Marco Aurélio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
29
node_modules/js/README.md
generated
vendored
Normal file
29
node_modules/js/README.md
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# js
|
||||
|
||||
**js** is a a better alternative to `node -p`. It will automatically convert data from and to JSON string representations, and will automatically expose enviroment variables as globals preceded with `$`.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
js <javascript>
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
Using math
|
||||
|
||||
```bash
|
||||
js 2+2
|
||||
```
|
||||
|
||||
Read a field from a JSON file
|
||||
|
||||
```bash
|
||||
js stdin.version < package.json
|
||||
```
|
||||
|
||||
Add a field to a JSON file on the fly
|
||||
|
||||
```bash
|
||||
js 'stdin.foo = "bar", stdin' < in.json > out.json
|
||||
```
|
||||
87
node_modules/js/bin/js
generated
vendored
Executable file
87
node_modules/js/bin/js
generated
vendored
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var program = require('commander');
|
||||
|
||||
program
|
||||
.version(JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8')).version)
|
||||
.usage('<javascript>')
|
||||
.option('-r, --raw', 'do not attempt to convert data from JSON')
|
||||
.option('-u, --ugly', 'ugly output (no indentation)')
|
||||
.option('-s, --silent', 'do not print result to standard output')
|
||||
.parse(process.argv);
|
||||
|
||||
var stdin = "";
|
||||
|
||||
if (!process.stdin.isTTY) {
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding('utf8');
|
||||
process.stdin.on('data', function(chunk) {
|
||||
stdin += chunk;
|
||||
})
|
||||
process.stdin.on('end', start);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
|
||||
function start() {
|
||||
if (!program.raw) {
|
||||
// attempt to interpret stdin as JSON
|
||||
try {
|
||||
stdin = JSON.parse(stdin);
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
// expose environment variables as globals preceded with $
|
||||
for (var name in process.env) {
|
||||
var value = process.env[name];
|
||||
|
||||
if (!program.raw) {
|
||||
// attempt to interpret variable as JSON
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
global['$' + name] = value;
|
||||
}
|
||||
|
||||
var result, output;
|
||||
|
||||
try {
|
||||
result = output = eval('(' + (program.args.join(' ') || 'undefined') + ')');
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
result = output = eval(program.args.join(' ') || 'undefined');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof output == 'string') {
|
||||
if (output[output.length - 1] != '\n') {
|
||||
output = output + '\n';
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
if (program.ugly) {
|
||||
output = JSON.stringify(output) + '\n';
|
||||
} else {
|
||||
output = JSON.stringify(output, null, 2) + '\n';
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (!program.silent) {
|
||||
process.stdout.write(output);
|
||||
}
|
||||
|
||||
process.exit(result ? 0 : 1);
|
||||
}
|
||||
12
node_modules/js/package.json
generated
vendored
Normal file
12
node_modules/js/package.json
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "js",
|
||||
"description": "A better `node -p`.",
|
||||
"author": "Marco Aurelio <thecoreh@gmail.com>",
|
||||
"version": "0.1.0",
|
||||
"bin": {
|
||||
"js": "./bin/js"
|
||||
},
|
||||
"dependencies": {
|
||||
"commander": "~1.1.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user