Socket
Socket
Sign inDemoInstall

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.14.7 to 1.14.8

82

js/lib/beautify-css.js

@@ -1080,14 +1080,14 @@ /* AUTO-GENERATED. DO NOT MODIFY. */

this.NESTED_AT_RULE = {
"@page": true,
"@font-face": true,
"@keyframes": true,
"page": true,
"font-face": true,
"keyframes": true,
// also in CONDITIONAL_GROUP_RULE below
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.CONDITIONAL_GROUP_RULE = {
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};

@@ -1220,4 +1220,3 @@ this.NON_SEMICOLON_NEWLINE_PROPERTY = [

var enteringConditionalGroup = false;
var insideAtExtend = false;
var insideAtImport = false;
var insideNonNestedAtRule = false;
var insideScssMap = false;

@@ -1277,6 +1276,28 @@ var topCharacter = this._ch;

this.eatWhitespace(true);
} else if (this._ch === '@' || this._ch === '$') {
} else if (this._ch === '$') {
this.preserveSingleSpace(isAfterSpace);
// deal with less propery mixins @{...}
this.print_string(this._ch);
// strip trailing space, if present, for hash property checks
var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
if (variable.match(/[ :]$/)) {
// we have a variable or pseudo-class, add it and insert one space before continuing
variable = this.eatString(": ").replace(/\s$/, '');
this.print_string(variable);
this._output.space_before_token = true;
}
variable = variable.replace(/\s$/, '');
// might be sass variable
if (parenLevel === 0 && variable.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
}
} else if (this._ch === '@') {
this.preserveSingleSpace(isAfterSpace);
// deal with less property mixins @{...}
if (this._input.peek() === '{') {

@@ -1299,10 +1320,9 @@ this.print_string(this._ch + this.eatString('}'));

if (variableOrRule === 'extend') {
insideAtExtend = true;
} else if (variableOrRule === 'import') {
insideAtImport = true;
}
// might be less variable
if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a nesting at-rule
if (variableOrRule in this.NESTED_AT_RULE) {
// might be a nesting at-rule
} else if (variableOrRule in this.NESTED_AT_RULE) {
this._nestedLevel += 1;

@@ -1312,6 +1332,6 @@ if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {

}
// might be less variable
} else if (!insideRule && parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a non-nested at-rule
} else if (parenLevel === 0 && !insidePropertyValue) {
insideNonNestedAtRule = true;
}

@@ -1328,2 +1348,5 @@ }

// non nested at rule becomes nested
insideNonNestedAtRule = false;
// when entering conditional groups, only rulesets are allowed

@@ -1369,4 +1392,3 @@ if (enteringConditionalGroup) {

}
insideAtImport = false;
insideAtExtend = false;
if (insidePropertyValue) {

@@ -1405,5 +1427,6 @@ this.outdent();

if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
// 'property: value' delimiter
// which could be in a conditional group query
this.print_string(':');

@@ -1445,4 +1468,3 @@ if (!insidePropertyValue) {

}
insideAtExtend = false;
insideAtImport = false;
insideNonNestedAtRule = false;
this.print_string(this._ch);

@@ -1512,3 +1534,3 @@ this.eatWhitespace(true);

this.eatWhitespace(true);
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
this._output.add_new_line();

@@ -1515,0 +1537,0 @@ } else {

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

"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"],
"wrap_attributes_min_attrs": Number,
"wrap_attributes_indent_size": Number,

@@ -167,2 +168,3 @@ "e4x": Boolean,

"A": ["--wrap_attributes"],
"M": ["--wrap_attributes_min_attrs"],
"i": ["--wrap_attributes_indent_size"],

@@ -400,2 +402,3 @@ "W": ["--max_char"], // obsolete since 1.3.5

msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]');
msg.push(' -M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]');
msg.push(' -i, --wrap-attributes-indent-size Indent wrapped tags to after N characters [indent-level]');

@@ -402,0 +405,0 @@ msg.push(' -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)');

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

"wrap_attributes": ["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"],
"wrap_attributes_min_attrs": Number,
"wrap_attributes_indent_size": Number,

@@ -167,2 +168,3 @@ "e4x": Boolean,

"A": ["--wrap_attributes"],
"M": ["--wrap_attributes_min_attrs"],
"i": ["--wrap_attributes_indent_size"],

@@ -400,2 +402,3 @@ "W": ["--max_char"], // obsolete since 1.3.5

msg.push(' -A, --wrap-attributes Wrap html tag attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]');
msg.push(' -M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]');
msg.push(' -i, --wrap-attributes-indent-size Indent wrapped tags to after N characters [indent-level]');

@@ -402,0 +405,0 @@ msg.push(' -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)');

@@ -57,14 +57,14 @@ /*jshint node:true */

this.NESTED_AT_RULE = {
"@page": true,
"@font-face": true,
"@keyframes": true,
"page": true,
"font-face": true,
"keyframes": true,
// also in CONDITIONAL_GROUP_RULE below
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};
this.CONDITIONAL_GROUP_RULE = {
"@media": true,
"@supports": true,
"@document": true
"media": true,
"supports": true,
"document": true
};

@@ -197,4 +197,3 @@ this.NON_SEMICOLON_NEWLINE_PROPERTY = [

var enteringConditionalGroup = false;
var insideAtExtend = false;
var insideAtImport = false;
var insideNonNestedAtRule = false;
var insideScssMap = false;

@@ -254,6 +253,28 @@ var topCharacter = this._ch;

this.eatWhitespace(true);
} else if (this._ch === '@' || this._ch === '$') {
} else if (this._ch === '$') {
this.preserveSingleSpace(isAfterSpace);
// deal with less propery mixins @{...}
this.print_string(this._ch);
// strip trailing space, if present, for hash property checks
var variable = this._input.peekUntilAfter(/[: ,;{}()[\]\/='"]/g);
if (variable.match(/[ :]$/)) {
// we have a variable or pseudo-class, add it and insert one space before continuing
variable = this.eatString(": ").replace(/\s$/, '');
this.print_string(variable);
this._output.space_before_token = true;
}
variable = variable.replace(/\s$/, '');
// might be sass variable
if (parenLevel === 0 && variable.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
}
} else if (this._ch === '@') {
this.preserveSingleSpace(isAfterSpace);
// deal with less property mixins @{...}
if (this._input.peek() === '{') {

@@ -276,10 +297,9 @@ this.print_string(this._ch + this.eatString('}'));

if (variableOrRule === 'extend') {
insideAtExtend = true;
} else if (variableOrRule === 'import') {
insideAtImport = true;
}
// might be less variable
if (parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a nesting at-rule
if (variableOrRule in this.NESTED_AT_RULE) {
// might be a nesting at-rule
} else if (variableOrRule in this.NESTED_AT_RULE) {
this._nestedLevel += 1;

@@ -289,6 +309,6 @@ if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {

}
// might be less variable
} else if (!insideRule && parenLevel === 0 && variableOrRule.indexOf(':') !== -1) {
insidePropertyValue = true;
this.indent();
// might be a non-nested at-rule
} else if (parenLevel === 0 && !insidePropertyValue) {
insideNonNestedAtRule = true;
}

@@ -305,2 +325,5 @@ }

// non nested at rule becomes nested
insideNonNestedAtRule = false;
// when entering conditional groups, only rulesets are allowed

@@ -346,4 +369,3 @@ if (enteringConditionalGroup) {

}
insideAtImport = false;
insideAtExtend = false;
if (insidePropertyValue) {

@@ -382,5 +404,6 @@ this.outdent();

if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideNonNestedAtRule && parenLevel === 0) {
// 'property: value' delimiter
// which could be in a conditional group query
this.print_string(':');

@@ -422,4 +445,3 @@ if (!insidePropertyValue) {

}
insideAtExtend = false;
insideAtImport = false;
insideNonNestedAtRule = false;
this.print_string(this._ch);

@@ -489,3 +511,3 @@ this.eatWhitespace(true);

this.eatWhitespace(true);
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideNonNestedAtRule) {
this._output.add_new_line();

@@ -492,0 +514,0 @@ } else {

@@ -299,7 +299,7 @@ /*jshint node:true */

if (raw_token.type === TOKEN.TAG_OPEN || raw_token.type === TOKEN.COMMENT) {
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token);
parser_token = this._handle_tag_open(printer, raw_token, last_tag_token, last_token, tokens);
last_tag_token = parser_token;
} else if ((raw_token.type === TOKEN.ATTRIBUTE || raw_token.type === TOKEN.EQUALS || raw_token.type === TOKEN.VALUE) ||
(raw_token.type === TOKEN.TEXT && !last_tag_token.tag_complete)) {
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, tokens);
parser_token = this._handle_inside_tag(printer, raw_token, last_tag_token, last_token);
} else if (raw_token.type === TOKEN.TAG_CLOSE) {

@@ -361,3 +361,3 @@ parser_token = this._handle_tag_close(printer, raw_token, last_tag_token);

Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, tokens) {
Beautifier.prototype._handle_inside_tag = function(printer, raw_token, last_tag_token, last_token) {
var wrapped = last_tag_token.has_wrapped_attrs;

@@ -383,3 +383,2 @@ var parser_token = {

printer.set_space_before_token(true);
last_tag_token.attr_count += 1;
} else if (raw_token.type === TOKEN.EQUALS) { //no space before =

@@ -397,25 +396,11 @@ printer.set_space_before_token(false);

if (this._is_wrap_attributes_force) {
var force_attr_wrap = last_tag_token.attr_count > 1;
if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.attr_count === 1) {
var is_only_attribute = true;
var peek_index = 0;
var peek_token;
do {
peek_token = tokens.peek(peek_index);
if (peek_token.type === TOKEN.ATTRIBUTE) {
is_only_attribute = false;
break;
}
peek_index += 1;
} while (peek_index < 4 && peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
force_attr_wrap = !is_only_attribute;
}
if (force_attr_wrap) {
printer.print_newline(false);
wrapped = true;
}
// Wrap for 'force' options, and if the number of attributes is at least that specified in 'wrap_attributes_min_attrs':
// 1. always wrap the second and beyond attributes
// 2. wrap the first attribute only if 'force-expand-multiline' is specified
if (this._is_wrap_attributes_force &&
last_tag_token.attr_count >= this._options.wrap_attributes_min_attrs &&
(last_token.type !== TOKEN.TAG_OPEN || // ie. second attribute and beyond
this._is_wrap_attributes_force_expand_multiline)) {
printer.print_newline(false);
wrapped = true;
}

@@ -549,3 +534,3 @@ }

Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token) {
Beautifier.prototype._handle_tag_open = function(printer, raw_token, last_tag_token, last_token, tokens) {
var parser_token = this._get_tag_open_token(raw_token);

@@ -555,3 +540,3 @@

!last_tag_token.is_empty_element &&
raw_token.type === TOKEN.TAG_OPEN && raw_token.text.indexOf('</') === 0) {
raw_token.type === TOKEN.TAG_OPEN && !parser_token.is_start_tag) {
// End element tags for unformatted or content_unformatted elements

@@ -570,2 +555,15 @@ // are printed raw to keep any newlines inside them exactly the same.

// count the number of attributes
if (parser_token.is_start_tag && this._is_wrap_attributes_force) {
var peek_index = 0;
var peek_token;
do {
peek_token = tokens.peek(peek_index);
if (peek_token.type === TOKEN.ATTRIBUTE) {
parser_token.attr_count += 1;
}
peek_index += 1;
} while (peek_token.type !== TOKEN.EOF && peek_token.type !== TOKEN.TAG_CLOSE);
}
//indent attributes an auto, forced, aligned or forced-align line-wrap

@@ -775,3 +773,3 @@ if (this._is_wrap_attributes_force_aligned || this._is_wrap_attributes_aligned_multiple || this._is_wrap_attributes_preserve_aligned) {

//To be used for <p> tag special case:
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_closers = ['address', 'article', 'aside', 'blockquote', 'details', 'div', 'dl', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'main', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'];
var p_parent_excludes = ['a', 'audio', 'del', 'ins', 'map', 'noscript', 'video'];

@@ -799,3 +797,3 @@

// An li element’s end tag may be omitted if the li element is immediately followed by another li element or if there is no more content in the parent element.
result = result || this._tag_stack.try_pop('li', ['ol', 'ul']);
result = result || this._tag_stack.try_pop('li', ['ol', 'ul', 'menu']);

@@ -802,0 +800,0 @@ } else if (parser_token.tag_name === 'dd' || parser_token.tag_name === 'dt') {

@@ -46,2 +46,3 @@ /*jshint node:true */

['auto', 'force', 'force-aligned', 'force-expand-multiline', 'aligned-multiple', 'preserve', 'preserve-aligned']);
this.wrap_attributes_min_attrs = this._get_number('wrap_attributes_min_attrs', 2);
this.wrap_attributes_indent_size = this._get_number('wrap_attributes_indent_size', this.indent_size);

@@ -48,0 +49,0 @@ this.extra_liners = this._get_array('extra_liners', ['head', 'body', '/html']);

@@ -768,3 +768,3 @@ /*jshint node:true */

if (this._flags.last_token.type !== TOKEN.OPERATOR && this._flags.last_token.type !== TOKEN.START_EXPR) {
if (this._flags.last_token.type === TOKEN.START_BLOCK && !this._flags.inline_frame) {
if (in_array(this._flags.last_token.type, [TOKEN.START_BLOCK, TOKEN.SEMICOLON]) && !this._flags.inline_frame) {
this.print_newline();

@@ -771,0 +771,0 @@ } else {

@@ -170,2 +170,3 @@ /*jshint node:true */

token = token || this._read_string(c);
token = token || this._read_pair(c, this._input.peek(1)); // Issue #2062 hack for record type '#{'
token = token || this._read_word(previous_token);

@@ -229,2 +230,15 @@ token = token || this._read_singles(c);

Tokenizer.prototype._read_pair = function(c, d) {
var token = null;
if (c === '#' && d === '{') {
token = this._create_token(TOKEN.START_BLOCK, c + d);
}
if (token) {
this._input.next();
this._input.next();
}
return token;
};
Tokenizer.prototype._read_punctuation = function() {

@@ -231,0 +245,0 @@ var resulting_string = this.__patterns.punct.read();

{
"name": "js-beautify",
"version": "1.14.7",
"version": "1.14.8",
"description": "beautifier.io for node",

@@ -48,3 +48,3 @@ "main": "js/index.js",

"engines": {
"node": ">=10"
"node": ">=12"
},

@@ -55,3 +55,3 @@ "browserslist": "ie 11",

"editorconfig": "^0.15.3",
"glob": "^8.0.3",
"glob": "^8.1.0",
"nopt": "^6.0.0"

@@ -62,14 +62,14 @@ },

"benchmark": "^2.1.4",
"codemirror": "^5.65.2",
"jquery": "^3.6.0",
"jshint": "^2.13.4",
"minimist": "^1.2.6",
"mocha": "^10.0.0",
"codemirror": "^5.65.13",
"jquery": "^3.6.4",
"jshint": "^2.13.6",
"minimist": "^1.2.8",
"mocha": "^10.2.0",
"mustache": "^4.2.0",
"requirejs": "^2.3.6",
"serve": "^14.0.1",
"serve": "^14.2.0",
"strip-ansi": "^7.0.1",
"webpack": "^5.74.0",
"webpack": "^5.81.0",
"webpack-cli": "^4.10.0"
}
}

@@ -61,9 +61,9 @@ <p align="center"><img src="https://raw.githubusercontent.com/beautify-web/js-beautify/7db71fc/web/wordmark-light.svg" height="200px" align="center" alt="JS Beautifier"/></p>

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify-html.min.js"></script>
```

@@ -80,3 +80,3 @@

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.7/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.8/beautify.min.js"></script>
<script src="script.js"></script>

@@ -146,3 +146,3 @@ </body>

```js
var beautify = require('js-beautify').js,
var beautify = require('js-beautify/js').js,
fs = require('fs');

@@ -374,2 +374,3 @@

-A, --wrap-attributes Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline|aligned-multiple|preserve|preserve-aligned] ["auto"]
-M, --wrap-attributes-min-attrs Minimum number of html tag attributes for force wrap attribute options [2]
-i, --wrap-attributes-indent-size Indent wrapped attributes to after N characters [indent-size] (ignored if wrap-attributes is "aligned")

@@ -439,2 +440,2 @@ -d, --inline List of tags to be considered inline tags

(README.md: js-beautify@1.14.7)
(README.md: js-beautify@1.14.8)

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

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

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

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

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