npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

toris-format

v1.7.29

Published

Node utility for formatting SASS, HTML, Angular1 HTML and Angular2 HTML

Downloads

268

Readme

toris-format

toris-format is a Node utility for formatting SASS, HTML, Angular1 HTML and Angular2 HTML

Trello Board

https://trello.com/b/2mSSarol/product-toris-format

Installation

(requires Node.js v4+)

$ npm install toris-format

Examples

Here are some example usages

Print out well formatted HTML

Create and run a node file with:

const format = require('toris-format');
const unformattedHTML = `
<html>
<h1 style="font-weight:bold" class="title">HI</h1>
   </html>
`
const config = {
    definition_type: 'HTML'
}
const formattedHTML = format.formatContents(unformattedHTML, config);
console.log(formattedHTML);

This will return:

<html>
    <h1
        class="title"
        style="font-weight:bold">HI</h1>
</html>

Print out well formatted CSS

Create and run a node file with:

const format = require('toris-format');
const unformattedCSS = `
.class {
    padding-left: -$unit;
padding-top: 2 -$unit;
padding-right: -2 2 -$unit;

width:-2; border: 0 -2px 0 0;
margin-top: -($unit / 2);
margin-bottom: -(1.25  *     $unit);
  padding: (0.2 * $unit) $unit;

}
`
const config = {
    definition_type: 'SCSS'
}
const formattedCSS = format.formatContents(unformattedCSS, config);
console.log(formattedCSS);

This will return:

.class {
    padding-left: -$unit;
    padding-top: 2 -$unit;
    padding-right: -2 2 -$unit;
    width: -2;
    border: 0 -2px 0 0;
    margin-top: -($unit / 2);
    margin-bottom: -(1.25 * $unit);
    padding: (0.2 * $unit) $unit;
}

Print out well formatted content from a file

Create and run a node file with:

const format = require('toris-format');
const filePath = './file.css'
const config = {} // Don't need to set the definition type since this gets deduced from the file extension
const formatted = format.formatFile(filePath, config);
// To overwrite file, you'll need to write the formatted contents to the file

Configuration Options

Default Configuration for html formatting

const config = {
    definition_type: 'HTML',
    add_noopener_noreferrer: false, // true or false
    angular_version: 1, // 1 or 2
    remove_css: false, // true or false
    allow_empty_files: false, // true or false
    indent: '    ', // spaces, tabs etc...
    convert_line_endings: true, // true or false
    line_ending: '\n', // \n, \r, \r\n
}

definition_type

Either HTML or SCSS, set to HTML for formatting HTML content

add_noopener_noreferrer

If set to true, adds noopener noreferrer to links with the _blank target See this link for more details

angular_version

Which angular syntax to use for formatting, 1 refers to AngularJS/Angular1, 2 refers to Angular/Angular2,3,4, etc...

remove_css

Removes inline CSS from HTML and leaves a comment in place

allow_empty_files

Shows a warning on empty content

indent

The indent to use for formatting, can be any string, but spaces or tabs are recommended

convert_line_endings

If set to true, converts line endings

line_ending

Line ending to use for conversion if convert_line_endings is true, one of \n, \r, \r\n

Default Configuration for css/scss formatting

const config = {
    definition_type: 'SCSS',
    allow_empty: false, // true or false
    convert_line_endings: true, // true or false
    line_ending: '\n', // \n, \r, \r\n
}

definition_type

Either HTML or SCSS, set to SCSS for formattting CSS/SCSS content

allow_empty

Shows a warning on empty content

indent

The indent to use for formatting, can be any string, but spaces or tabs are recommended

convert_line_endings

If set to true, converts line endings

line_ending

Line ending to use for conversion if convert_line_endings is true, one of \n, \r, \r\n

Todos

  • Still more documentation to come

License

ISC