Socket
Socket
Sign inDemoInstall

pretty

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pretty - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

58

index.js
/*!
* pretty <https://github.com/jonschlinkert/pretty>
*
* Copyright (c) 2013-2015, Jon Schlinkert.
* Licensed under the MIT license.
* Copyright (c) 2013-2015, 2017, Jon Schlinkert.
* Released under the MIT License.
*/

@@ -11,40 +11,36 @@

var beautify = require('js-beautify');
var condense = require('condense-newlines');
var extend = require('extend-shallow');
var defaults = {
unformatted: ['code', 'pre', 'em', 'strong', 'span'],
indent_inner_html: true,
indent_char: ' ',
indent_size: 2,
sep: '\n'
};
module.exports = function pretty(str, options) {
str = beautify.html(str, {
indent_char: ' ',
indent_size: 2,
indent_inner_html: true,
unformatted: ['code', 'pre', 'em', 'strong', 'span']
});
var opts = extend({}, defaults, options);
str = beautify.html(str, opts);
return ocd(str, options);
if (opts.ocd === true) {
if (opts.newlines) opts.sep = opts.newlines;
return ocd(str, opts);
}
return str;
};
function ocd(str, options) {
return str
// Remove any empty lines at the top of a file.
.replace(/^\s*/g, '')
// Normalize and condense all newlines
.replace(/(\r\n|\n){2,}/g, '\n')
// fix multiline, Bootstrap-style comments
.replace(/(\s*)(<!--.+)\s*(===.+)/g, '$1$2$1$3')
// make <li><a></li> on one line, but only when li > a
.replace(/(<li>)(\s*)(<a .+)(\s*)(<\/li>)/g, '$1 $3 $5')
// make <a><span></a> on one line, but only when a > span
.replace(/(<a.+)(\s*)(<span .+)(\s*)(<\/a>)/g, '$1 $3 $5')
// Adjust spacing for button > span
.replace(/(<button.+)(<span.+)(\s*)(<\/button>)/g, '$1$3 $2$3$4')
// Adjust spacing for span > input
.replace(/(\s*)(<span.+)(\s*)(<input.+)(\s*)(<\/span>)/g, '$1$2$1 $4$1$6')
// Add a newline for tags nested inside <h1-6>
.replace(/(\s*)(<h[0-6](?:.+)?>)(.*)(<(?:small|span|strong|em)(?:.+)?)(\s*)(<\/h[0-6]>)/g, '$1$2$3$1 $4$1$6')
// Normalize and condense all newlines
return condense(str, options)
// Remove empty whitespace the top of a file.
.replace(/^\s+/g, '')
// Remove extra whitespace from eof
.replace(/\s+$/g, '\n')
// Add a space above each comment
.replace(/(\s*<!--)/g, '\n$1')
// Fix conditional comments
.replace(/( *)(<!--\[.+)(\s*)(.+\s*)?(.+\s*)?(<!\[endif\]-->)/g, '$1$2\n $1$4$1$5$1$6')
// Bring closing comments up to the same line as closing tag.
.replace(/\s*(<!--\s*\/.+)/g, '$1')
// Add a space after some inline elements, since prettifying strips them sometimes
.replace(/(<\/(a|small|span|strong|em)>(?:(?!,)))/g, '$1 ');
.replace(/>(\s*)(?=<!--\s*\/)/g, '> ');
}
{
"name": "pretty",
"description": "Some tweaks for beautifying HTML with js-beautify according to my preferences.",
"version": "1.0.0",
"version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/pretty",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"repository": {
"type": "git",
"url": "https://github.com/jonschlinkert/pretty.git"
},
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/pretty",
"bugs": {
"url": "https://github.com/jonschlinkert/pretty/issues"
},
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/pretty/blob/master/LICENSE-MIT"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=0.10.0"
},
"main": "index.js",
"scripts": {
"docs": "update && license && npmignore && deps && verb",
"all": "npm run docs"
"test": "mocha"
},
"dependencies": {
"js-beautify": "~1.5.4"
"condense-newlines": "^0.2.1",
"extend-shallow": "^2.0.1",
"js-beautify": "^1.6.12"
},
"devDependencies": {
"mocha": "*",
"should": "*"
"gulp-format-md": "^0.1.12",
"mocha": "^3.2.0"
},

@@ -45,3 +40,16 @@ "keywords": [

"pretty"
]
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"lint": {
"reflinks": true
}
}
}

@@ -1,11 +0,19 @@

# pretty [![NPM version](https://badge.fury.io/js/pretty.svg)](http://badge.fury.io/js/pretty)
# pretty [![NPM version](https://img.shields.io/npm/v/pretty.svg?style=flat)](https://www.npmjs.com/package/pretty) [![NPM monthly downloads](https://img.shields.io/npm/dm/pretty.svg?style=flat)](https://npmjs.org/package/pretty) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/pretty.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/pretty)
> Some tweaks for beautifying HTML with js-beautify according to my preferences.
## Install with [npm](npmjs.org)
## Install
```bash
npm i pretty --save
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save pretty
```
Install with [yarn](https://yarnpkg.com):
```sh
$ yarn add pretty
```
## Usage

@@ -16,3 +24,3 @@

pretty(STRING_OF_HTML_HERE);
pretty(STRING_OF_HTML);
```

@@ -28,3 +36,3 @@

After
After

@@ -44,26 +52,57 @@ ```html

## Run tests
## Options
Install dev dependencies:
### ocd
```bash
node i -d && mocha
```js
pretty(STRING_OF_HTML, {ocd: true});
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/pretty/issues)
**Type**: `Boolean`
## Author
**Default**: `undefined`
* condenses multiple newlines to a single newline
* trims leading and trailing whitespace
* ensures that a trailing newline is inserted
* normalizes whitespace before code comments
## About
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
### Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```
### Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb](https://github.com/assemble/verb) on January 04, 2015._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 13, 2017._

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