Comparing version 0.1.6 to 0.1.7
@@ -9,3 +9,3 @@ // Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
var countComments, countMixed, emptyLines, endOfLine, getCommentExpressions, getStop, getType, keys, lineSum, newLines, nonEmpty, slocModule, trampoline, | ||
var X, countComments, countMixed, emptyLines, emptyLns, endOfLine, extensions, getCommentExpressions, getStop, getType, keys, lineSum, matchIdx, newLines, newLns, nonEmpty, slocModule, trampoline, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -35,2 +35,3 @@ | ||
case "pl": | ||
case "yaml": | ||
return /\#/; | ||
@@ -50,2 +51,3 @@ case "js": | ||
case "go": | ||
case "groovy": | ||
case "scss": | ||
@@ -94,2 +96,3 @@ case "less": | ||
case "go": | ||
case "groovy": | ||
case "css": | ||
@@ -137,13 +140,8 @@ case "scss": | ||
break; | ||
case "erl": | ||
case "swift": | ||
case "vb": | ||
case "r": | ||
case "clj": | ||
case "hy": | ||
case "pl": | ||
start = stop = null; | ||
break; | ||
default: | ||
throw new TypeError("File extension '" + lang + "' is not supported"); | ||
if (__indexOf.call(extensions, lang) >= 0) { | ||
start = stop = null; | ||
} else { | ||
throw new TypeError("File extension '" + lang + "' is not supported"); | ||
} | ||
} | ||
@@ -198,6 +196,20 @@ return { | ||
matchIdx = function(m) { | ||
return m.index + m[0].length; | ||
}; | ||
emptyLns = function(c) { | ||
var _ref; | ||
return ((_ref = c.match(emptyLines)) != null ? _ref.length : void 0) || 0; | ||
}; | ||
newLns = function(c) { | ||
var _ref; | ||
return ((_ref = c.match(newLines)) != null ? _ref.length : void 0) || 0; | ||
}; | ||
countComments = function(code, regex) { | ||
var myself; | ||
myself = function(res, code, idx) { | ||
var cContentIdx, comment, len, lines, match, single, splitAt, start, startIdx, stop, type, _ref, _ref1, _ref2; | ||
var cStartIdx, comment, empty, len, lines, match, single, splitAt, start, startIdx, stop, type, _ref, _ref1; | ||
if (code === '') { | ||
@@ -226,4 +238,4 @@ return res; | ||
})(); | ||
cContentIdx = match.index + match[0].length; | ||
comment = code.substring(cContentIdx); | ||
cStartIdx = matchIdx(match); | ||
comment = code.substring(cStartIdx); | ||
lines = code.substring(0, match.index).split('\n'); | ||
@@ -236,5 +248,6 @@ startIdx = lines.length - 1 + idx; | ||
} | ||
empty = emptyLns(code.substring(match.index, cStartIdx + matchIdx(stop))); | ||
comment = comment.substring(0, stop.index); | ||
len = ((_ref2 = comment.match(newLines)) != null ? _ref2.length : void 0) || 0; | ||
splitAt = cContentIdx + comment.length + stop[0].length; | ||
len = newLns(comment); | ||
splitAt = cStartIdx + comment.length + stop[0].length; | ||
code = code.substring(splitAt); | ||
@@ -244,3 +257,4 @@ countMixed(res, lines, idx, startIdx, match); | ||
start: startIdx, | ||
stop: startIdx + len | ||
stop: startIdx + len, | ||
empty: empty | ||
}; | ||
@@ -280,10 +294,16 @@ res[type].push(res.last); | ||
X = null; | ||
slocModule = function(code, lang) { | ||
var b, bIdx, block, comment, empty, mixed, res, s, single, source, total, _i, _len, _ref, _ref1, _ref2, _ref3; | ||
var b, bIdx, block, blockEmpty, comment, empty, mixed, res, s, single, source, total, x, _i, _j, _len, _len1, _ref, _ref1, _ref2; | ||
X = lang; | ||
if (typeof code !== "string") { | ||
throw new TypeError("'code' has to be a string"); | ||
} | ||
code = code.replace(/\r/g, ''); | ||
total = 1 + ((_ref = code.match(newLines)) != null ? _ref.length : void 0) || 0; | ||
empty = ((_ref1 = code.match(emptyLines)) != null ? _ref1.length : void 0) || 0; | ||
code = code.replace(/\r\n|\r/g, '\n'); | ||
if (code.slice(-1) === '\n') { | ||
code = code.slice(0, -1); | ||
} | ||
total = (1 + newLns(code)) || 1; | ||
empty = emptyLns(code); | ||
res = countComments(code, getCommentExpressions(lang)); | ||
@@ -295,8 +315,8 @@ single = lineSum(res.single); | ||
bIdx = (function() { | ||
var _i, _len, _ref2, _ref3, _results; | ||
_ref2 = res.block; | ||
var _i, _len, _ref, _ref1, _results; | ||
_ref = res.block; | ||
_results = []; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
b = _ref2[_i]; | ||
if (!(_ref3 = b.stop, __indexOf.call(_results, _ref3) >= 0)) { | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
b = _ref[_i]; | ||
if (!(_ref1 = b.stop, __indexOf.call(_results, _ref1) >= 0)) { | ||
_results.push(b.stop); | ||
@@ -307,10 +327,16 @@ } | ||
})(); | ||
_ref2 = res.single; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
s = _ref2[_i]; | ||
if (_ref3 = s.start, __indexOf.call(bIdx, _ref3) >= 0) { | ||
_ref = res.single; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
s = _ref[_i]; | ||
if (_ref1 = s.start, __indexOf.call(bIdx, _ref1) >= 0) { | ||
comment--; | ||
} | ||
} | ||
source = total - comment - empty + mixed; | ||
blockEmpty = 0; | ||
_ref2 = res.block; | ||
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { | ||
x = _ref2[_j]; | ||
blockEmpty = +x.empty; | ||
} | ||
source = total - comment - empty + blockEmpty + mixed; | ||
return { | ||
@@ -327,4 +353,6 @@ total: total, | ||
slocModule.extensions = ["c", "cc", "clj", "coffee", "cpp", "cs", "css", "erl", "go", "h", "hpp", "hs", "html", "hx", "hy", "ino", "java", "jl", "js", "less", "lua", "ls", "monkey", "nix", "php", "php5", "pl", "py", "r", "rb", "rkt", "rs", "scala", "scss", "styl", "swift", "ts", "vb"]; | ||
extensions = ["c", "cc", "clj", "coffee", "cpp", "cs", "css", "erl", "go", "groovy", "h", "hpp", "hs", "html", "hx", "hy", "ino", "java", "jl", "js", "less", "lua", "ls", "monkey", "nix", "php", "php5", "pl", "py", "r", "rb", "rkt", "rs", "scala", "scss", "styl", "swift", "ts", "vb", "yaml"]; | ||
slocModule.extensions = extensions; | ||
slocModule.keys = keys; | ||
@@ -331,0 +359,0 @@ |
{ | ||
"name": "sloc", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"main": "lib/sloc", | ||
@@ -52,4 +52,4 @@ "bin": "bin/sloc", | ||
"prepublish": "coffee -c -o lib/ src/", | ||
"test": "mocha --reporter spec --compilers coffee:coffee-script/register --recursive spec/" | ||
"test": "mocha --reporter spec --compilers coffee:coffee-script/register --recursive spec/*.spec.coffee" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29237
747
255