js-beautify
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -61,2 +61,3 @@ # Contributing | ||
Merge changes from `master` to `gh-pages` branch. This is very low cost and can be done whenever is convenient. | ||
If doing a general release, update the `bower.json` file to the new version and commit the change. | ||
@@ -63,0 +64,0 @@ ##Python |
@@ -41,5 +41,8 @@ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */ | ||
The options are: | ||
indent_size (default 4) — indentation size, | ||
indent_char (default space) — character to indent with, | ||
The options are (default in brackets): | ||
indent_size (4) — indentation size, | ||
indent_char (space) — character to indent with, | ||
selector_separator_newline (true) - separate selectors with newline or | ||
not (e.g. "a,\nbr" or "a, br") | ||
end_with_newline (false) - end with a newline | ||
@@ -50,3 +53,5 @@ e.g | ||
'indent_size': 1, | ||
'indent_char': '\t' | ||
'indent_char': '\t', | ||
'selector_separator': ' ', | ||
'end_with_newline': false, | ||
}); | ||
@@ -58,3 +63,3 @@ */ | ||
(function() { | ||
(function () { | ||
function css_beautify(source_text, options) { | ||
@@ -64,2 +69,6 @@ options = options || {}; | ||
var indentCharacter = options.indent_char || ' '; | ||
var selectorSeparatorNewline = true; | ||
if (options.selector_separator_newline != undefined) | ||
selectorSeparatorNewline = options.selector_separator_newline; | ||
var endWithNewline = options.end_with_newline || false; | ||
@@ -88,3 +97,3 @@ // compatibility | ||
function eatString(comma) { | ||
function eatString(endChar) { | ||
var start = pos; | ||
@@ -95,3 +104,3 @@ while (next()) { | ||
next(); | ||
} else if (ch === comma) { | ||
} else if (ch === endChar) { | ||
break; | ||
@@ -134,3 +143,4 @@ } else if (ch === "\n") { | ||
function lookBack(str) { | ||
return source_text.substring(pos - str.length, pos).toLowerCase() === str; | ||
return source_text.substring(pos - str.length, pos).toLowerCase() === | ||
str; | ||
} | ||
@@ -154,3 +164,3 @@ | ||
var print = {}; | ||
print["{"] = function(ch) { | ||
print["{"] = function (ch) { | ||
print.singleSpace(); | ||
@@ -160,3 +170,3 @@ output.push(ch); | ||
}; | ||
print["}"] = function(ch) { | ||
print["}"] = function (ch) { | ||
print.newLine(); | ||
@@ -167,5 +177,9 @@ output.push(ch); | ||
print.newLine = function(keepWhitespace) { | ||
print._lastCharWhitespace = function () { | ||
return whiteRe.test(output[output.length - 1]); | ||
} | ||
print.newLine = function (keepWhitespace) { | ||
if (!keepWhitespace) { | ||
while (whiteRe.test(output[output.length - 1])) { | ||
while (print._lastCharWhitespace()) { | ||
output.pop(); | ||
@@ -182,4 +196,4 @@ } | ||
}; | ||
print.singleSpace = function() { | ||
if (output.length && !whiteRe.test(output[output.length - 1])) { | ||
print.singleSpace = function () { | ||
if (output.length && !print._lastCharWhitespace()) { | ||
output.push(' '); | ||
@@ -194,2 +208,3 @@ } | ||
var insideRule = false; | ||
while (true) { | ||
@@ -200,11 +215,26 @@ var isAfterSpace = skipWhitespace(); | ||
break; | ||
} | ||
if (ch === '{') { | ||
indent(); | ||
print["{"](ch); | ||
} else if (ch === '/' && peek() === '*') { // comment | ||
print.newLine(); | ||
output.push(eatComment(), "\n", indentString); | ||
var header = lookBack("") | ||
if (header) { | ||
print.newLine(); | ||
} | ||
} else if (ch === '{') { | ||
eatWhitespace(); | ||
if (peek() == '}') { | ||
next(); | ||
output.push(" {}"); | ||
} else { | ||
indent(); | ||
print["{"](ch); | ||
} | ||
} else if (ch === '}') { | ||
outdent(); | ||
print["}"](ch); | ||
insideRule = false; | ||
} else if (ch === ":") { | ||
eatWhitespace(); | ||
output.push(ch, " "); | ||
insideRule = true; | ||
} else if (ch === '"' || ch === '\'') { | ||
@@ -214,5 +244,2 @@ output.push(eatString(ch)); | ||
output.push(ch, '\n', indentString); | ||
} else if (ch === '/' && peek() === '*') { // comment | ||
print.newLine(); | ||
output.push(eatComment(), "\n", indentString); | ||
} else if (ch === '(') { // may be a url | ||
@@ -241,3 +268,7 @@ if (lookBack("url")) { | ||
output.push(ch); | ||
print.singleSpace(); | ||
if (!insideRule && selectorSeparatorNewline) { | ||
print.newLine(); | ||
} else { | ||
print.singleSpace(); | ||
} | ||
} else if (ch === ']') { | ||
@@ -259,2 +290,11 @@ output.push(ch); | ||
var sweetCode = output.join('').replace(/[\n ]+$/, ''); | ||
// establish end_with_newline | ||
var should = endWithNewline; | ||
var actually = /\n$/.test(sweetCode) | ||
if (should && !actually) | ||
sweetCode += "\n"; | ||
else if (!should && actually) | ||
sweetCode = sweetCode.slice(0, -1); | ||
return sweetCode; | ||
@@ -265,3 +305,3 @@ } | ||
// Add support for require.js | ||
define(function(require, exports, module) { | ||
define(function (require, exports, module) { | ||
exports.css_beautify = css_beautify; | ||
@@ -281,2 +321,2 @@ }); | ||
}()); | ||
}()); |
@@ -106,3 +106,3 @@ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */ | ||
brace_style = options.brace_style || 'collapse'; | ||
wrap_line_length = options.wrap_line_length === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10); | ||
wrap_line_length = parseInt(options.wrap_line_length, 10) === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10); | ||
unformatted = options.unformatted || ['a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; | ||
@@ -611,3 +611,3 @@ preserve_newlines = options.preserve_newlines || true; | ||
// tets next_tag to see if it is just html tag (no external content) | ||
// test next_tag to see if it is just html tag (no external content) | ||
var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/); | ||
@@ -614,0 +614,0 @@ |
@@ -119,2 +119,22 @@ #!/usr/bin/env node | ||
function verifyExists(fullPath) { | ||
return fs.existsSync(fullPath) ? fullPath : null; | ||
} | ||
function findRecursive(dir, fileName) { | ||
var fullPath = path.join(dir, fileName); | ||
var nextDir = path.dirname(dir); | ||
var result = verifyExists(fullPath); | ||
if (!result && (nextDir !== dir)) { | ||
result = findRecursive(nextDir, fileName); | ||
} | ||
return result; | ||
} | ||
function getUserHome() { | ||
return process.env.HOME || process.env.USERPROFILE; | ||
} | ||
// var cli = require('js-beautify/cli'); cli.interpret(); | ||
@@ -136,4 +156,4 @@ var interpret = exports.interpret = function(argv, slice) { | ||
parsed.config, | ||
cc.find('.jsbeautifyrc'), | ||
cc.find(path.join(process.env.HOME || "", ".jsbeautifyrc")), | ||
findRecursive(process.cwd(), '.jsbeautifyrc'), | ||
verifyExists(path.join(getUserHome() || "", ".jsbeautifyrc")), | ||
__dirname + '/../config/defaults.json' | ||
@@ -140,0 +160,0 @@ ).snapshot; |
@@ -7,2 +7,3 @@ /*global js_beautify: true */ | ||
js_beautify = require('../index').js_beautify, | ||
css_beautify = require('../index').css_beautify, | ||
html_beautify = require('../index').html_beautify, | ||
@@ -12,3 +13,3 @@ run_beautifier_tests = require('./beautify-tests').run_beautifier_tests; | ||
function node_beautifier_tests() { | ||
var results = run_beautifier_tests(new SanityTest(), Urlencoded, js_beautify, html_beautify); | ||
var results = run_beautifier_tests(new SanityTest(), Urlencoded, js_beautify, html_beautify, css_beautify); | ||
console.log(results.results_raw()); | ||
@@ -15,0 +16,0 @@ return results; |
{ | ||
"name": "js-beautify", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "jsbeautifier.org for node", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
Sorry, the diff of this file is too big to display
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
250625
29
4855
6