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

js-beautify

Package Overview
Dependencies
Maintainers
2
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-beautify - npm Package Compare versions

Comparing version 1.5.10 to 1.6.0

appveyor.yml

7

CONTRIBUTING.md

@@ -7,6 +7,9 @@ # Contributing

## Build and test
If you run `./build full` from the root folder locally, build and tests will run and should all pass.
## Fix issues
Pull requests with fixes are totally welcome. Familiarize yourself with the folder structure and code style before you dive in. Where possible fixes should include tests to prevent future regressions in functionality. Also, if they apply and you have the ability, make fixes to both python and javascript implementations.
We use travis-ci.org to run build and test passes. If you run `make` from the root folder locally, tests will run and should all pass before your pull request will be accepted.
We use travis-ci.org to run build and test passes. If you run `./build full` from the root folder locally, tests will run and must all pass. The build may generate updated test files - commit any changes reported by `git status` after the build completes. Then create pull request.

@@ -41,3 +44,3 @@

### PHP
There is a out-of-date version of the beautifier available on branch `attic-php`. If you're interested
There is an out-of-date version of the beautifier available on branch `attic-php`. If you're interested
in using it feel free. If you plan to enhance it, please consider joining this project, and updating this

@@ -44,0 +47,0 @@ version to match current functionality.

@@ -66,3 +66,2 @@ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */

'brace_style': 'expand',
'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u'],
'preserve_newlines': true,

@@ -121,5 +120,15 @@ 'max_preserve_newlines': 5,

wrap_line_length = parseInt(options.wrap_line_length, 10) === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10);
unformatted = options.unformatted || ['a', 'span', 'img', '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'];
unformatted = options.unformatted || [
// https://www.w3.org/TR/html5/dom.html#phrasing-content
'a', 'abbr', 'area', 'audio', 'b', 'bdi', 'bdo', 'br', 'button', 'canvas', 'cite',
'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img',
'input', 'ins', 'kbd', 'keygen', 'label', 'map', 'mark', 'math', 'meter', 'noscript',
'object', 'output', 'progress', 'q', 'ruby', 's', 'samp', /* 'script', */ 'select', 'small',
'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'var',
'video', 'wbr', 'text',
// prexisting - not sure of full effect of removing, leaving in
'acronym', 'address', 'big', 'dt', 'ins', 'small', 'strike', 'tt',
'pre',
'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
];
preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines;

@@ -131,3 +140,3 @@ max_preserve_newlines = preserve_newlines ?

wrap_attributes = (options.wrap_attributes === undefined) ? 'auto' : options.wrap_attributes;
wrap_attributes_indent_size = (options.wrap_attributes_indent_size === undefined) ? indent_size : parseInt(options.wrap_attributes_indent_size, 10) || indent_size;
wrap_attributes_indent_size = (isNaN(parseInt(options.wrap_attributes_indent_size, 10))) ? indent_size : parseInt(options.wrap_attributes_indent_size, 10);
end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;

@@ -163,3 +172,21 @@ extra_liners = (typeof options.extra_liners == 'object') && options.extra_liners ?

whitespace: "\n\r\t ".split(''),
single_token: 'br,input,link,meta,source,!doctype,basefont,base,area,hr,wbr,param,img,isindex,embed'.split(','), //all the single tags for HTML
single_token: [
// HTLM void elements - aka self-closing tags - aka singletons
// https://www.w3.org/html/wg/drafts/html/master/syntax.html#void-elements
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr',
// NOTE: Optional tags - are not understood.
// https://www.w3.org/TR/html5/syntax.html#optional-tags
// The rules for optional tags are too complex for a simple list
// Also, the content of these tags should still be indented in many cases.
// 'li' is a good exmple.
// Doctype and xml elements
'!doctype', '?xml',
// ?php tag
'?php',
// other tags that were in this list, keeping just in case
'basefont', 'isindex'
],
extra_liners: extra_liners, //for tags that need a line of whitespace before them

@@ -178,3 +205,3 @@ in_array: function(what, arr) {

this.is_whitespace = function(text) {
for (var n = 0; n < text.length; text++) {
for (var n = 0; n < text.length; n++) {
if (!this.Utils.in_array(text.charAt(n), this.Utils.whitespace)) {

@@ -208,2 +235,3 @@ return false;

// at the wrap_line_length, append a newline/indentation.
// return true if a newline was added, false if a space was added
this.space_or_wrap = function(content) {

@@ -213,5 +241,7 @@ if (this.line_char_count >= this.wrap_line_length) { //insert a line when the wrap_line_length is reached

this.print_indentation(content);
return true;
} else {
this.line_char_count++;
content.push(' ');
return false;
}

@@ -372,7 +402,12 @@ };

//no space after = or before >
this.space_or_wrap(content);
var wrapped = this.space_or_wrap(content);
var indentAttrs = wrapped && input_char !== '/' && wrap_attributes !== 'force';
space = false;
if (!first_attr && wrap_attributes === 'force' && input_char !== '/') {
this.print_newline(true, content);
this.print_newline(false, content);
this.print_indentation(content);
indentAttrs = true;
}
if (indentAttrs) {
//indent attributes an auto or forced line-wrap
for (var count = 0; count < wrap_attributes_indent_size; count++) {

@@ -477,3 +512,3 @@ content.push(indent_character);

(tag_complete.search('type') > -1 &&
tag_complete.search(/\b(text|application)\/(x-)?(javascript|ecmascript|jscript|livescript)/) > -1))) {
tag_complete.search(/\b(text|application)\/(x-)?(javascript|ecmascript|jscript|livescript|(ld\+)?json)/) > -1))) {
if (!peek) {

@@ -536,3 +571,3 @@ this.record_tag(tag_check);

this.pos = start_pos;
input_char = this.input.charAt(this.pos);
var input_char = this.input.charAt(this.pos);
this.pos++;

@@ -582,4 +617,21 @@

function tokenMatcher(delimiter) {
var token = '';
var add = function (str) {
var newToken = token + str.toLowerCase();
token = newToken.length <= delimiter.length ? newToken : newToken.substr(newToken.length - delimiter.length, delimiter.length);
};
var doesNotMatch = function () {
return token.indexOf(delimiter) === -1;
};
return {
add: add,
doesNotMatch: doesNotMatch
};
}
this.get_unformatted = function(delimiter, orig_tag) { //function to return unformatted content in its entirety
if (orig_tag && orig_tag.toLowerCase().indexOf(delimiter) !== -1) {

@@ -590,4 +642,6 @@ return '';

var content = '';
var min_index = 0;
var space = true;
var delimiterMatcher = tokenMatcher(delimiter);
do {

@@ -620,2 +674,3 @@

content += input_char;
delimiterMatcher.add(input_char);
this.line_char_count++;

@@ -627,6 +682,6 @@ space = true;

content += this.get_unformatted('}}');
// These expressions are opaque. Ignore delimiters found in them.
min_index = content.length;
// Don't consider when stopping for delimiters.
}
} while (content.toLowerCase().indexOf(delimiter, min_index) === -1);
} while (delimiterMatcher.doesNotMatch());
return content;

@@ -848,2 +903,17 @@ };

case 'TK_TAG_HANDLEBARS_ELSE':
// Don't add a newline if opening {{#if}} tag is on the current line
var foundIfOnCurrentLine = false;
for (var lastCheckedOutput=multi_parser.output.length-1; lastCheckedOutput>=0; lastCheckedOutput--) {
if (multi_parser.output[lastCheckedOutput] === '\n') {
break;
} else {
if (multi_parser.output[lastCheckedOutput].match(/{{#if/)) {
foundIfOnCurrentLine = true;
break;
}
}
}
if (!foundIfOnCurrentLine) {
multi_parser.print_newline(false, multi_parser.output);
}
multi_parser.print_token(multi_parser.token_text);

@@ -850,0 +920,0 @@ if (multi_parser.indent_content) {

@@ -158,3 +158,3 @@ #!/usr/bin/env node

function getUserHome() {
return process.env.HOME || process.env.USERPROFILE;
return process.env.USERPROFILE || process.env.HOME;
}

@@ -174,10 +174,20 @@

var cfg = cc(
parsed,
cleanOptions(cc.env('jsbeautify_'), knownOpts),
parsed.config,
findRecursive(process.cwd(), '.jsbeautifyrc'),
verifyExists(path.join(getUserHome() || "", ".jsbeautifyrc")),
__dirname + '/../config/defaults.json'
).snapshot;
var cfg;
try {
cfg = cc(
parsed,
cleanOptions(cc.env('jsbeautify_'), knownOpts),
parsed.config,
findRecursive(process.cwd(), '.jsbeautifyrc'),
verifyExists(path.join(getUserHome() || "", ".jsbeautifyrc")),
__dirname + '/../config/defaults.json'
).snapshot;
} catch (ex) {
debug(cfg);
// usage(ex);
console.error(ex);
console.error('Error while loading beautifier configuration file.');
console.error('Run `' + getScriptName() + ' -h` for help.');
process.exit(1);
}

@@ -227,3 +237,4 @@ try {

' -t, --indent-with-tabs Indent with tabs, overrides -s and -c',
' -e, --eol Character(s) to use as line terminators. (default newline - "\\n")',
' -e, --eol Character(s) to use as line terminators.',
' [first newline in file, otherwise "\\n]',
' -n, --end-with-newline End output with newline'

@@ -292,2 +303,3 @@ ];

input.resume();
input.setEncoding('utf8');

@@ -420,3 +432,10 @@

var argv = parsed.argv;
var isTTY = true;
try {
isTTY = process.stdin.isTTY;
} catch (ex) {
debug("error querying for isTTY:", ex);
}
if (!parsed.files) {

@@ -434,3 +453,5 @@ parsed.files = [];

argv.remain.forEach(function(f) {
parsed.files.push(path.resolve(f));
if (f !== '-') {
parsed.files.push(path.resolve(f));
}
});

@@ -446,11 +467,11 @@ }

if (argv.original.indexOf('-') > -1) {
// ensure '-' without '-f' still consumes stdin
if (!parsed.files.length) {
// read stdin by default
parsed.files.push('-');
}
debug('files.length ' + parsed.files.length);
if (!parsed.files.length) {
throw 'Must define at least one file.';
if (parsed.files.indexOf('-') > -1 && isTTY) {
throw 'Must pipe input or define at least one file.';
}
debug('files.length ' + parsed.files.length);

@@ -457,0 +478,0 @@ parsed.files.forEach(testFilePath);

@@ -7,5 +7,5 @@ /*global js_beautify: true */

Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
run_javascript_tests = require('./beautify-javascript-tests').run_javascript_tests,
run_css_tests = require('./beautify-css-tests').run_css_tests,
run_html_tests = require('./beautify-html-tests').run_html_tests;
run_javascript_tests = require('./generated/beautify-javascript-tests').run_javascript_tests,
run_css_tests = require('./generated/beautify-css-tests').run_css_tests,
run_html_tests = require('./generated/beautify-html-tests').run_html_tests;

@@ -12,0 +12,0 @@ requirejs.config({

@@ -6,17 +6,14 @@ /*global js_beautify: true */

Urlencoded = require('../lib/unpackers/urlencode_unpacker'),
run_javascript_tests = require('./beautify-javascript-tests').run_javascript_tests,
run_css_tests = require('./beautify-css-tests').run_css_tests,
run_html_tests = require('./beautify-html-tests').run_html_tests;
run_javascript_tests = require('./generated/beautify-javascript-tests').run_javascript_tests,
run_css_tests = require('./generated/beautify-css-tests').run_css_tests,
run_html_tests = require('./generated/beautify-html-tests').run_html_tests;
function node_beautifier_legacy_tests(name, test_runner) {
console.log('Testing ' + name + ' with node.js CommonJS (legacy names)...');
function test_legacy_names() {
var beautify = require('../index');
var results = new SanityTest();
var beautify = require('../index');
test_runner(
results,
Urlencoded,
beautify.js_beautify,
beautify.html_beautify,
beautify.css_beautify);
console.log('First ensure that legacy import names equal the new ones');
results.expect(beautify.js, beautify.js_beautify);
results.expect(beautify.css, beautify.css_beautify);
results.expect(beautify.html, beautify.html_beautify);

@@ -28,7 +25,6 @@ console.log(results.results_raw());

function node_beautifier_tests(name, test_runner) {
console.log('Testing ' + name + ' with node.js CommonJS (new names)...');
var results = new SanityTest();
console.log('Testing ' + name + ' with node.js CommonJS...');
var beautify = require('../index');
var results = new SanityTest();
test_runner(

@@ -45,12 +41,9 @@ results,

if (require.main === module) {
process.exit(
test_legacy_names() +
node_beautifier_tests('js-beautifier', run_javascript_tests).get_exitcode() +
node_beautifier_legacy_tests('js-beautifier', run_javascript_tests).get_exitcode() +
node_beautifier_tests('cs-beautifier', run_css_tests).get_exitcode() +
node_beautifier_legacy_tests('css-beautifier', run_css_tests).get_exitcode() +
node_beautifier_tests('html-beautifier', run_html_tests).get_exitcode() +
node_beautifier_legacy_tests('html-beautifier', run_html_tests).get_exitcode()
node_beautifier_tests('html-beautifier', run_html_tests).get_exitcode()
);
}
{
"name": "js-beautify",
"version": "1.5.10",
"version": "1.6.0",
"description": "jsbeautifier.org for node",
"main": "js/index.js",
"preferGlobal": true,
"bin": {

@@ -16,6 +15,3 @@ "css-beautify": "./js/bin/css-beautify.js",

},
"scripts": {
"test": "./js/test/shell-smoke-test.sh",
"update-codemirror": "npm install codemirror && rm -rf ./web/third-party/codemirror/* && cp ./node_modules/codemirror/LICENSE ./web/third-party/codemirror/ && cp ./node_modules/codemirror/README.md ./web/third-party/codemirror/ && cp -r ./node_modules/codemirror/lib ./web/third-party/codemirror/ && mkdir -p ./web/third-party/codemirror/mode && cp -r ./node_modules/codemirror/mode/javascript ./web/third-party/codemirror/mode/ && git add -Av ./web/third-party/codemirror"
},
"scripts": {},
"bugs": "https://github.com/beautify-web/js-beautify/issues",

@@ -22,0 +18,0 @@ "homepage": "http://jsbeautifier.org/",

# JS Beautifier
[![Build Status](https://img.shields.io/travis/beautify-web/js-beautify/master.svg)](http://travis-ci.org/beautify-web/js-beautify)
[![Build status](https://ci.appveyor.com/api/projects/status/5bxmpvew5n3e58te/branch/master?svg=true)](https://ci.appveyor.com/project/beautify-web/js-beautify/branch/master)
[![NPM version](https://img.shields.io/npm/v/js-beautify.svg)](https://www.npmjs.com/package/js-beautify)

@@ -100,3 +101,3 @@ [![Download stats](https://img.shields.io/npm/dm/js-beautify.svg)](https://www.npmjs.com/package/js-beautify)

-a, --space-after-anon-function Add a space before an anonymous function's parens, ie. function ()
-b, --brace-style [collapse|expand|end-expand|none] ["collapse"]
-b, --brace-style [collapse-preserve-inline|collapse|expand|end-expand|none] ["collapse"]
-B, --break-chained-methods Break chained method calls across subsequent lines

@@ -149,3 +150,3 @@ -k, --keep-array-indentation Preserve array indentation

## Directives to Ignore or Preserve sections (Javascript only)
## Directives to Ignore or Preserve sections (Javascript only)

@@ -208,3 +209,3 @@ Beautifier for supports directives in comments inside the file.

-I, --indent-inner-html Indent <head> and <body> sections. Default is false.
-b, --brace-style [collapse|expand|end-expand|none] ["collapse"]
-b, --brace-style [collapse-preserve-inline|collapse|expand|end-expand|none] ["collapse"]
-S, --indent-scripts [keep|separate|normal] ["normal"]

@@ -225,3 +226,3 @@ -w, --wrap-line-length Maximum characters per line (0 disables) [250]

* Written by Einar Lielmanis, <einar@jsbeautifier.org>
* Created by Einar Lielmanis, <einar@jsbeautifier.org>
* Python version flourished by Stefano Sanfilippo <a.little.coder@gmail.com>

@@ -235,2 +236,2 @@ * General maintenance and expansion by Liam Newman <bitwiseman@gmail.com>

js-beautify@1.5.7
js-beautify@1.6.0-0
#!/usr/bin/env node
var fs = require('fs');
var mustache = require('mustache');
var path = require('path');

@@ -9,30 +10,50 @@ function generate_tests() {

// javascript
test_data = require(__dirname + '/data/javascript.js').test_data;
set_formatters(test_data, 'bt', '// ')
template = fs.readFileSync(__dirname + '/template/node-javascript.mustache', {encoding: 'utf-8'});
fs.writeFileSync(__dirname + '/../js/test/beautify-javascript-tests.js', mustache.render(template, test_data), {encoding: 'utf-8'});
generate_test_files('javascript', 'bt', 'js/test/generated/beautify-javascript-tests.js', 'python/jsbeautifier/tests/generated/tests.py' );
set_formatters(test_data, 'bt', '# ')
template = fs.readFileSync(__dirname + '/template/python-javascript.mustache', {encoding: 'utf-8'});
fs.writeFileSync(__dirname + '/../python/jsbeautifier/tests/testjsbeautifier.py', mustache.render(template, test_data), {encoding: 'utf-8'});
// css
test_data = require(__dirname + '/data/css.js').test_data;
set_formatters(test_data, 't', '// ')
template = fs.readFileSync(__dirname + '/template/node-css.mustache', {encoding: 'utf-8'});
fs.writeFileSync(__dirname + '/../js/test/beautify-css-tests.js', mustache.render(template, test_data), {encoding: 'utf-8'});
generate_test_files('css', 't', 'js/test/generated/beautify-css-tests.js', 'python/cssbeautifier/tests/generated/tests.py' );
set_formatters(test_data, 't', '# ')
template = fs.readFileSync(__dirname + '/template/python-css.mustache', {encoding: 'utf-8'});
fs.writeFileSync(__dirname + '/../python/cssbeautifier/tests/test.py', mustache.render(template, test_data), {encoding: 'utf-8'});
// html
test_data = require(__dirname + '/data/html.js').test_data;
set_formatters(test_data, 'bth', '// ')
template = fs.readFileSync(__dirname + '/template/node-html.mustache', {encoding: 'utf-8'});
fs.writeFileSync(__dirname + '/../js/test/beautify-html-tests.js', mustache.render(template, test_data), {encoding: 'utf-8'});
// no python html beautifier, so no tests
generate_test_files('html', 'bth', 'js/test/generated/beautify-html-tests.js');
}
function generate_test_files(data_folder, test_method, node_output, python_output) {
var data_file_path, input_path, template_file_path;
var test_data, template;
input_path = path.resolve(__dirname, 'data', data_folder);
data_file_path = path.resolve(input_path, 'tests.js');
test_data = require(data_file_path).test_data;
template_file_path = path.resolve(input_path, 'node.mustache');
template = fs.readFileSync(template_file_path, {encoding: 'utf-8'});
set_formatters(test_data, test_method, '// ')
set_generated_header(test_data, data_file_path, template_file_path);
fs.writeFileSync(path.resolve(__dirname, '..', node_output),
mustache.render(template, test_data), {encoding: 'utf-8'});
if (python_output) {
template_file_path = path.resolve(input_path, 'python.mustache');
template = fs.readFileSync(template_file_path, {encoding: 'utf-8'});
set_formatters(test_data, test_method, '# ')
set_generated_header(test_data, data_file_path, template_file_path);
fs.writeFileSync(path.resolve(__dirname, '..', python_output),
mustache.render(template, test_data), {encoding: 'utf-8'});
}
}
function set_generated_header (data, data_file_path, template_file_path) {
var relative_script_path = path.relative(process.cwd(), __filename).split(path.sep).join('/');
var relative_data_file_path = path.relative(process.cwd(), data_file_path).split(path.sep).join('/');
var relative_template_file_path = path.relative(process.cwd(), template_file_path).split(path.sep).join('/');
data.header_text =
' AUTO-GENERATED. DO NOT MODIFY.\n' +
' Script: ' + relative_script_path + '\n' +
' Template: ' + relative_template_file_path + '\n' +
' Data: ' + relative_data_file_path;
}
function isStringOrArray(val) {

@@ -39,0 +60,0 @@ return typeof val === 'string' || val instanceof Array;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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