Comparing version 0.1.19 to 0.1.20
@@ -7,2 +7,3 @@ var waitfor = require('./waitfor'), | ||
inspect = require('./util/inspect'), | ||
addNewlines = require('./util/add-newlines'), | ||
escapeSpaces = require('./util/escape-spaces'), | ||
@@ -102,64 +103,2 @@ toCamelCase = require('./util/to-camel-case'); | ||
} | ||
function addNewlines(cmd) { | ||
var i = 0, addingNewLine = false, inConditional = false, inString = false, stringChar = '', inBracketedVar = false, leavingBracketedVar = false; | ||
while (cmd[i]) { | ||
if (!inString && cmd[i] === '$' && cmd[i + 1] === '{') { | ||
inBracketedVar = true; | ||
} | ||
if (leavingBracketedVar) { | ||
leavingBracketedVar = false; | ||
inBracketedVar = false; | ||
} | ||
if (!inString && inBracketedVar && cmd[i] === '}') { | ||
leavingBracketedVar = true; | ||
} | ||
if (!inString && (cmd[i] === '"' || cmd[i] === '\'') && cmd[i - 1] !== '\\') { | ||
inString = true; | ||
stringChar = cmd[i]; | ||
i++; | ||
continue; | ||
} else if (inString) { | ||
if (cmd[i] === stringChar && cmd[i - 1] !== '\\') { | ||
inString = false; | ||
stringChar = ''; | ||
} | ||
i++; | ||
continue; | ||
} else if (!inString && !inConditional && (cmd.substr(i, 2) === 'if' || cmd.substr(i, 3) === 'for' || cmd.substr(i, 5) === 'while')) { | ||
inConditional = true; | ||
addingNewLine = true; | ||
i++; | ||
continue; | ||
} else if (!inString && inConditional) { | ||
if (cmd[i] === ')') { | ||
inConditional = false; | ||
addingNewLine = false; | ||
cmd = cmd.substr(0, i + 1) + '\n' + cmd.substr(i + 1); | ||
i += 2; | ||
continue; | ||
} else { | ||
i++; | ||
continue; | ||
} | ||
} else if (!inString) { | ||
if (!inBracketedVar && cmd[i] === '{') { | ||
cmd = cmd.substr(0, i - 1) + '\n' + '{' + '\n' + cmd.substr(i + 1); | ||
i += 3; | ||
continue; | ||
} else if (!inBracketedVar && cmd[i] === '}') { | ||
cmd = cmd.substr(0, i - 1) + '\n' + '}' + '\n' + cmd.substr(i + 1); | ||
i += 3; | ||
continue; | ||
} else if (cmd[i] === ';') { | ||
cmd = cmd.substr(0, i + 1) + '\n' + cmd.substr(i + 1); | ||
i += 2; | ||
continue; | ||
} else { | ||
i++; | ||
continue; | ||
} | ||
} | ||
} | ||
return cmd; | ||
} | ||
function sandr (cmd) { | ||
@@ -166,0 +105,0 @@ var parts = cmd.split('\n'); |
{ | ||
"name": "jsh", | ||
"version": "0.1.19", | ||
"version": "0.1.20", | ||
"description": "The JavaScript shell interpreter.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
var expect = require('chai').expect; | ||
var toCamelCase = require('../lib/util/to-camel-case'); | ||
var toCamelCase = require('../lib/util/to-camel-case'), | ||
addNewlines = require('../lib/util/add-newlines'); | ||
describe('jsh utility modules', function () { | ||
@@ -9,2 +10,8 @@ it('should convert to camel-case', function () { | ||
}); | ||
it('should add newlines without altering content', function () { | ||
expect(addNewlines('var a = { a: 1}')).to.equal('var a = \n{\n a: 1\n}\n'); | ||
}); | ||
it('should add newlines after semicolons and preserve strings', function () { | ||
expect(addNewlines('console.log(\'{a:1}\');')).to.equal('console.log(\'{a:1}\');\n'); | ||
}); | ||
}); |
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
112650
39
1825