An html attribute sorter
npm install html-attribute-sorter


An html attribute sorter.
You can sort attributes by alphabetical, code guide, vue/attributes-order, idiomatic or any custom order using regex.
``bash`
$ npm install html-attribute-sorteryarn
$ yarn add html-attribute-sorter
`typescript
const { sortAttributes } = require("html-attribute-sorter");
// pass html tags that includes attributes
// default: code guide order
const sorted = sortAttributes();
console.log(sorted);
// =>
// alphabetical order
const sorted = sortAttributes(
,
{
order: "alphabetical",
}
);
console.log(sorted);
// =>
// idiomatic order
const sorted = sortAttributes(
,
{
order: "idiomatic",
}
);
console.log(sorted);
// =>
// code guide order
const sorted = sortAttributes(
,
{
order: "code-guide",
}
);
console.log(sorted);
// =>
// custom order
const sorted = sortAttributes(
,`
{
order: "custom",
customRegexes: ["id", "class", "sr.+", "alt"], // you can use regex for attritube names
}
);
console.log(sorted);
// =>
#### sortAttributes(body: string, options: ISortOption)
body: html tag string e.g.
#### ISortOption
`typescript`
export interface ISortOption {
order: string;
customRegexes?: string[];
}
| key | value | required | default |
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------ |
| order | An order to sort attributes. You can specify alphabetical, code-guide, idiomatic, vuejs or custom. | yes | code-guide |order
| customRegexes | When is specified to custom, html attributes set here will be used as order. You can use regex for attribute names. e.g. ["data-.+", "class", "src"]. | no | [] |
`bash`
$ yarn install
$ yarn run test
`bash`
$ yarn run benchmark
1. Fork it
2. Create your feature branch (git checkout -b my-new-feature)git commit -am 'Add some feature'
3. Commit your changes ()git push origin my-new-feature`)
4. Push to the branch (
5. Create new Pull Request
MIT