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

html-attribute-sorter

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-attribute-sorter

An html attribute sorter

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
decreased by-3.67%
Maintainers
1
Weekly downloads
 
Created
Source

npm CI codecov

html-attribute-sorter

An html attribute sorter.

You can sort attributes by alphabetical, code guide, vue/attributes-order or idiomatic order.

Installation

$ npm install html-attribute-sorter
# yarn
$ yarn add html-attribute-sorter

Usage

const { sortAttributes } = require("html-attribute-sorter");

// pass html tags that includes attributes
// default: code guide order
const sorted = sortAttributes(`<img src="foo" class="img b-30" id="img_10">`);
console.log(sorted);
// => <img class="img b-30" id="img_10" src="foo">

// alphabetical order
const sorted = sortAttributes(
  `<img src="foo" alt="title" class="img b-30" id="img_10">`,
  {
    order: "alphabetical",
  }
);
console.log(sorted);
// => <img alt="title" class="img b-30" id="img_10" src="foo">

// idiomatic order
const sorted = sortAttributes(
  `<img src="foo" alt="title" class="img b-30" id="img_10">`,
  {
    order: "idiomatic",
  }
);
console.log(sorted);
// => <img class="img b-30" id="img_10" alt="title" src="foo">

// code guide order
const sorted = sortAttributes(
  `<img src="foo" alt="title" class="img b-30" id="img_10">`,
  {
    order: "code-guide",
  }
);
console.log(sorted);
// => <img class="img b-30" id="img_10" src="foo">

API

functions

sortAttributes(body: string, options: ISortOption)

body: html tag string e.g. <img src="..." alt="title" class="pg-10">

Interfaces

ISortOption
export interface ISortOption {
  order: string;
}
keyvalue
orderAn order to sort attributes. You can specify alphabetical, code-guide, idiomatic or vuejs. default: code-guide

Testing

$ yarn install
$ yarn run test

Benchmarking

$ yarn run benchmark

image

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

LICENSE

MIT

Keywords

FAQs

Package last updated on 06 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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