Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

renamed

  • Loading branch information...
commit 0ce762c7e8635bb859cd2b3f3997a6078ceb2ee6 1 parent b317eeb
@tj authored
View
28 bin/jss → bin/stats
@@ -4,7 +4,7 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, fs = require('fs');
/**
@@ -23,7 +23,7 @@ var paths = [];
* Statistics.
*/
-var stats = {};
+var statistics = {};
/**
* Options.
@@ -37,7 +37,7 @@ var options = { format: 'text' };
var usage = [
''
- , ' Usage: jss [options] [file|dir ...]'
+ , ' Usage: stats [options] [file|dir ...]'
, ''
, ' Options:'
, ''
@@ -45,7 +45,7 @@ var usage = [
, ' -j, --json Output JSON statistics'
, ' -t, --text Output human-readable plain-text stats'
, ' -T, --totals Output totals only'
- , ' -V, --version Display the version of jss'
+ , ' -V, --version Display the version of stats'
, ' -h, --help Display help information'
, ''
].join('\n');
@@ -65,7 +65,7 @@ while (args.length) {
process.exit(1);
case '-V':
case '--version':
- console.log(jss.version);
+ console.log(stats.version);
process.exit(0);
break;
case '-j':
@@ -88,18 +88,18 @@ while (args.length) {
// process
var totals;
-jss.find(paths, function(err, files){
+stats.find(paths, function(err, files){
var pending = files.length;
files.forEach(function(file){
fs.readFile(file, 'utf8', function(err, str){
if (err) throw err;
- stats[file] = jss.stats(str);
+ statistics[file] = stats.parse(str);
if (totals) {
- Object.keys(stats[file]).forEach(function(key){
- totals[key] += stats[file][key];
+ Object.keys(statistics[file]).forEach(function(key){
+ totals[key] += statistics[file][key];
});
} else {
- totals = stats[file];
+ totals = statistics[file];
}
--pending || done();
});
@@ -110,10 +110,12 @@ jss.find(paths, function(err, files){
function done() {
if (options.text) {}
- var format = jss.formats[options.format];
+ var format = stats.formats[options.format];
if (!format) throw new Error('invalid format "' + options.format + '"');
var obj = { totals: totals };
- totals.files = Object.keys(stats).length;
- if (!options.totalsOnly) for (var file in stats) obj[file] = stats[file];
+ totals.files = Object.keys(statistics).length;
+ if (!options.totalsOnly) {
+ for (var file in statistics) obj[file] = statistics[file];
+ }
format(obj);
}
View
2  index.js
@@ -1,2 +1,2 @@
-module.exports = require('./lib/jss');
+module.exports = require('./lib/stats');
View
2  lib/find.js
@@ -1,6 +1,6 @@
/*!
- * jss - find
+ * stats - find
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
View
2  lib/formats/index.js
@@ -1,6 +1,6 @@
/*!
- * jss - formats
+ * stats - formats
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
View
2  lib/formats/json.js
@@ -1,6 +1,6 @@
/*!
- * jss - formats - json
+ * stats - formats - json
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
View
2  lib/formats/text.js
@@ -1,6 +1,6 @@
/*!
- * jss - formats - text
+ * stats - formats - text
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
View
39 lib/jss.js
@@ -1,39 +0,0 @@
-
-/*!
- * jss
- * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
- * MIT Licensed
- */
-
-/**
- * Library version.
- */
-
-exports.version = '0.0.1';
-
-/**
- * Return stats for the given javascript `str`.
- *
- * @param {String} str
- * @return {Object}
- * @api public
- */
-
-exports.stats = require('./stats');
-
-/**
- * Find JavaScript files by the given `paths`
- * and callback `fn(err, files)`.
- *
- * @param {Array} paths
- * @param {Function} fn
- * @api public
- */
-
-exports.find = require('./find');
-
-/**
- * Expose formatters.
- */
-
-exports.formats = require('./formats');
View
236 lib/parser.js
@@ -0,0 +1,236 @@
+
+/*!
+ * stats - parser
+ * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var parse = require('uglify-js').parser.parse;
+
+
+/**
+ * Return stats for the given javascript `str`.
+ *
+ * @param {String} str
+ * @return {Object}
+ * @api public
+ */
+
+module.exports = function(str){
+ var stats = {
+ loc: str.split('\n').length
+ , bytes: Buffer.byteLength(str)
+ , statements: 0
+ , assignments: 0
+ , functions: 0
+ , stringBytes: 0
+ , arrayLiterals: 0
+ , objectLiterals: 0
+ , objectsCreated: 0
+ , regexpLiterals: 0
+ , strings: 0
+ , numbers: 0
+ , throws: 0
+ };
+
+ function visit(node) {
+ if (!node) return;
+ var name = node[0];
+
+ // array support
+ if ('string' != typeof name) {
+ for (var i = 0, len = node.length; i < len; ++i) {
+ visit(node[i]);
+ }
+ return;
+ }
+
+ // rename "name" to "ident"
+ if ('name' == name) name = 'ident';
+
+ // visit the node
+ if (!visit[name]) throw new Error('no visitor implemented for "' + name + '"');
+ visit[name](node);
+ }
+
+ visit['toplevel'] = function(node){
+ visit(node[1]);
+ };
+
+ visit['seq'] = function(node){
+ visit(node[1]);
+ visit(node[2]);
+ };
+
+ visit['for-in'] = function(node){
+ visit(node[1]);
+ visit(node[2]);
+ visit(node[3]);
+ visit(node[4]);
+ };
+
+ visit['switch'] = function(node){
+ ++stats.statements;
+ visit(node[1]);
+ node[2].forEach(function(node){
+ visit(node[1]);
+ visit(node[2]);
+ });
+ };
+
+ visit['with'] = function(node){
+ ++stats.statements;
+ visit(node[1]);
+ visit(node[2]);
+ };
+
+ visit['try'] = function(node){
+ ++stats.statements;
+ visit(node[1]);
+ node[2] && visit(node[2][1]);
+ };
+
+ visit['conditional'] = function(node){
+ visit(node[1]);
+ visit(node[2]);
+ visit(node[3]);
+ };
+
+ visit['break'] = function(node){
+ ++stats.statements;
+ };
+
+ visit['array'] = function(node){
+ ++stats.arrayLiterals;
+ visit(node[1]);
+ };
+
+ visit['object'] = function(node){
+ ++stats.objectLiterals;
+ node[1].forEach(function(pair){
+ visit(pair[1]);
+ });
+ };
+
+ visit['var'] =
+ visit['const'] = function(node){
+ node[1].forEach(function(node){
+ if (node[1]) ++stats.assignments;
+ visit(node[1]);
+ });
+ ++stats.statements;
+ };
+
+ visit['regexp'] = function(node){
+ ++stats.regexpLiterals;
+ };
+
+ visit['num'] = function(node){
+ ++stats.numbers;
+ };
+
+ visit['do'] = function(node){
+ ++stats.statements;
+ visit(node[1]);
+ visit(node[2]);
+ };
+
+ visit['label'] = function(node){
+ visit(node[2]);
+ };
+
+ visit['atom'] = function(node){};
+
+ visit['unary-prefix'] = function(node){};
+
+ visit['unary-postfix'] = function(node){};
+
+ visit['continue'] = function(node){};
+
+ visit['return'] = function(node){};
+
+ visit['binary'] = function(node){};
+
+ visit['ident'] = function(node){};
+
+ visit['new'] = function(node){
+ ++stats.objectsCreated;
+ visit(node[1]);
+ visit(node[2]);
+ };
+
+ visit['throw'] = function(node){
+ ++stats.throws;
+ visit(node[1]);
+ };
+
+ visit['for'] = function(node){
+ visit(node[1]);
+ visit(node[2]);
+ visit(node[3]);
+ visit(node[4]);
+ };
+
+ visit['sub'] = function(node){
+ visit(node[1]);
+ visit(node[2]);
+ };
+
+ visit['string'] = function(node){
+ ++stats.strings;
+ stats.stringBytes += Buffer.byteLength(node[1]);
+ };
+
+ visit['dot'] = function(node){
+ visit(node[1]);
+ };
+
+ visit['block'] = function(node){
+ visit(node[1]);
+ };
+
+ visit['while'] = function(node){
+ ++stats.statements;
+ visit(node[2]);
+ };
+
+ visit['if'] = function(node){
+ ++stats.statements;
+ visit(node[1]);
+ visit(node[2]);
+ visit(node[3]);
+ };
+
+ visit['defun'] = function(node){
+ ++stats.functions;
+ ++stats.statements;
+ visit(node[3]);
+ };
+
+ visit['function'] = function(node){
+ ++stats.functions;
+ visit(node[3]);
+ };
+
+ visit['call'] = function(node){
+ visit(node[1]);
+ visit(node[2]);
+ };
+
+ visit['assign'] = function(node){
+ ++stats.assignments;
+ visit(node[3]);
+ };
+
+ visit['stat'] = function(node){
+ ++stats.statements;
+ visit(node[1]);
+ };
+
+ visit(parse(str));
+ return stats;
+};
View
231 lib/stats.js
@@ -1,16 +1,15 @@
/*!
- * jss - stats
+ * stats
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
/**
- * Module dependencies.
+ * Library version.
*/
-var parse = require('uglify-js').parser.parse;
-
+exports.version = '0.0.1';
/**
* Return stats for the given javascript `str`.
@@ -20,217 +19,21 @@ var parse = require('uglify-js').parser.parse;
* @api public
*/
-module.exports = function(str){
- var stats = {
- loc: str.split('\n').length
- , bytes: Buffer.byteLength(str)
- , statements: 0
- , assignments: 0
- , functions: 0
- , stringBytes: 0
- , arrayLiterals: 0
- , objectLiterals: 0
- , objectsCreated: 0
- , regexpLiterals: 0
- , strings: 0
- , numbers: 0
- , throws: 0
- };
-
- function visit(node) {
- if (!node) return;
- var name = node[0];
-
- // array support
- if ('string' != typeof name) {
- for (var i = 0, len = node.length; i < len; ++i) {
- visit(node[i]);
- }
- return;
- }
-
- // rename "name" to "ident"
- if ('name' == name) name = 'ident';
-
- // visit the node
- if (!visit[name]) throw new Error('no visitor implemented for "' + name + '"');
- visit[name](node);
- }
-
- visit['toplevel'] = function(node){
- visit(node[1]);
- };
-
- visit['seq'] = function(node){
- visit(node[1]);
- visit(node[2]);
- };
-
- visit['for-in'] = function(node){
- visit(node[1]);
- visit(node[2]);
- visit(node[3]);
- visit(node[4]);
- };
-
- visit['switch'] = function(node){
- ++stats.statements;
- visit(node[1]);
- node[2].forEach(function(node){
- visit(node[1]);
- visit(node[2]);
- });
- };
-
- visit['with'] = function(node){
- ++stats.statements;
- visit(node[1]);
- visit(node[2]);
- };
-
- visit['try'] = function(node){
- ++stats.statements;
- visit(node[1]);
- node[2] && visit(node[2][1]);
- };
-
- visit['conditional'] = function(node){
- visit(node[1]);
- visit(node[2]);
- visit(node[3]);
- };
-
- visit['break'] = function(node){
- ++stats.statements;
- };
-
- visit['array'] = function(node){
- ++stats.arrayLiterals;
- visit(node[1]);
- };
-
- visit['object'] = function(node){
- ++stats.objectLiterals;
- node[1].forEach(function(pair){
- visit(pair[1]);
- });
- };
-
- visit['var'] =
- visit['const'] = function(node){
- node[1].forEach(function(node){
- if (node[1]) ++stats.assignments;
- visit(node[1]);
- });
- ++stats.statements;
- };
-
- visit['regexp'] = function(node){
- ++stats.regexpLiterals;
- };
-
- visit['num'] = function(node){
- ++stats.numbers;
- };
-
- visit['do'] = function(node){
- ++stats.statements;
- visit(node[1]);
- visit(node[2]);
- };
-
- visit['label'] = function(node){
- visit(node[2]);
- };
-
- visit['atom'] = function(node){};
-
- visit['unary-prefix'] = function(node){};
-
- visit['unary-postfix'] = function(node){};
+exports.parse = require('./parser');
- visit['continue'] = function(node){};
-
- visit['return'] = function(node){};
-
- visit['binary'] = function(node){};
-
- visit['ident'] = function(node){};
-
- visit['new'] = function(node){
- ++stats.objectsCreated;
- visit(node[1]);
- visit(node[2]);
- };
-
- visit['throw'] = function(node){
- ++stats.throws;
- visit(node[1]);
- };
-
- visit['for'] = function(node){
- visit(node[1]);
- visit(node[2]);
- visit(node[3]);
- visit(node[4]);
- };
-
- visit['sub'] = function(node){
- visit(node[1]);
- visit(node[2]);
- };
-
- visit['string'] = function(node){
- ++stats.strings;
- stats.stringBytes += Buffer.byteLength(node[1]);
- };
-
- visit['dot'] = function(node){
- visit(node[1]);
- };
-
- visit['block'] = function(node){
- visit(node[1]);
- };
-
- visit['while'] = function(node){
- ++stats.statements;
- visit(node[2]);
- };
-
- visit['if'] = function(node){
- ++stats.statements;
- visit(node[1]);
- visit(node[2]);
- visit(node[3]);
- };
-
- visit['defun'] = function(node){
- ++stats.functions;
- ++stats.statements;
- visit(node[3]);
- };
-
- visit['function'] = function(node){
- ++stats.functions;
- visit(node[3]);
- };
-
- visit['call'] = function(node){
- visit(node[1]);
- visit(node[2]);
- };
+/**
+ * Find JavaScript files by the given `paths`
+ * and callback `fn(err, files)`.
+ *
+ * @param {Array} paths
+ * @param {Function} fn
+ * @api public
+ */
- visit['assign'] = function(node){
- ++stats.assignments;
- visit(node[3]);
- };
+exports.find = require('./find');
- visit['stat'] = function(node){
- ++stats.statements;
- visit(node[1]);
- };
+/**
+ * Expose formatters.
+ */
- visit(parse(str));
- return stats;
-};
+exports.formats = require('./formats');
View
4 package.json
@@ -1,11 +1,11 @@
{
- "name": "jss"
+ "name": "stats"
, "version": "0.0.1"
, "description": "JavaScript statistics (LOC, SLOC, etc)"
, "keywords": ["metrics", "stats", "statistics", "sloc", "uglify"]
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
, "bin": {
- "jss": "./bin/jss"
+ "stats": "./bin/stats"
}
, "dependencies": {
"uglify-js": ">= 1.0.6"
View
4 test/test.arrays.js
@@ -3,9 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats(fixture('arrays.js'));
+var stats = stats.parse(fixture('arrays.js'));
stats.should.have.property('arrayLiterals', 2);
stats.should.have.property('strings', 6);
View
6 test/test.comments.js
@@ -3,11 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-jss.should.have.property('version');
-
-var stats = jss.stats(fixture('comments.js'));
+var stats = stats.parse(fixture('comments.js'));
stats.should.have.property('statements', 0);
stats.should.have.property('loc', 8);
View
4 test/test.forin.js
@@ -3,9 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats('for (var key in val) "hey";');
+var stats = stats.parse('for (var key in val) "hey";');
stats.should.have.property('statements', 2);
stats.should.have.property('strings', 1);
View
4 test/test.functions.js
@@ -3,10 +3,10 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats(fixture('functions.js'));
+var stats = stats.parse(fixture('functions.js'));
stats.should.have.property('statements', 10);
stats.should.have.property('assignments', 2);
stats.should.have.property('functions', 4);
View
6 test/test.http.js
@@ -3,12 +3,10 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-jss.should.have.property('version');
-
-var stats = jss.stats(fixture('http.js'));
+var stats = stats.parse(fixture('http.js'));
stats.should.have.property('strings', 4);
stats.should.have.property('numbers', 1);
stats.should.have.property('statements', 4);
View
4 test/test.large.js
@@ -3,10 +3,10 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats(fixture('large.js'));
+var stats = stats.parse(fixture('large.js'));
stats.should.have.property('statements', 16);
stats.should.have.property('assignments', 9);
stats.should.have.property('loc', 65);
View
4 test/test.objects.js
@@ -3,9 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats(fixture('objects.js'));
+var stats = stats.parse(fixture('objects.js'));
stats.should.have.property('objectLiterals', 2);
stats.should.have.property('objectsCreated', 1);
View
4 test/test.postfix.js
@@ -3,7 +3,7 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats('foo++');
+var stats = stats.parse('foo++');
View
4 test/test.regexp.js
@@ -3,9 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats('foo.text(/something/)');
+var stats = stats.parse('foo.text(/something/)');
stats.should.have.property('statements', 1);
stats.should.have.property('regexpLiterals', 1);
View
4 test/test.sequence.js
@@ -3,9 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats('("foo", "bar", "baz")');
+var stats = stats.parse('("foo", "bar", "baz")');
stats.should.have.property('statements', 1);
stats.should.have.property('strings', 3);
View
6 test/test.simple.js
@@ -3,12 +3,12 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-jss.should.have.property('version');
+stats.should.have.property('version');
-var stats = jss.stats(fixture('simple.js'));
+var stats = stats.parse(fixture('simple.js'));
stats.should.have.property('statements', 4);
stats.should.have.property('assignments', 4);
stats.should.have.property('loc', 9);
View
4 test/test.switch.js
@@ -3,8 +3,8 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats(fixture('switch.js'));
+var stats = stats.parse(fixture('switch.js'));
stats.should.have.property('statements', 5);
View
4 test/test.ternary.js
@@ -3,9 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats('"foo" ? "bar" : "baz"');
+var stats = stats.parse('"foo" ? "bar" : "baz"');
stats.should.have.property('statements', 1);
stats.should.have.property('strings', 3);
View
4 test/test.trycatch.js
@@ -3,9 +3,9 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats('try { "test" } catch (err) { "testing" }');
+var stats = stats.parse('try { "test" } catch (err) { "testing" }');
stats.should.have.property('statements', 3);
stats.should.have.property('strings', 2);
View
4 test/test.while.js
@@ -3,8 +3,8 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats(fixture('while.js'));
+var stats = stats.parse(fixture('while.js'));
stats.should.have.property('statements', 5);
View
4 test/test.with.js
@@ -3,8 +3,8 @@
* Module dependencies.
*/
-var jss = require('../')
+var stats = require('../')
, common = require('./common');
-var stats = jss.stats(fixture('with.js'));
+var stats = stats.parse(fixture('with.js'));
stats.should.have.property('statements', 3);
Please sign in to comment.
Something went wrong with that request. Please try again.