Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsh

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsh - npm Package Compare versions

Comparing version 0.1.19 to 0.1.20

lib/util/add-newlines.js

63

lib/vm.js

@@ -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');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc