Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrmlnc/posthtml-attrs-sorter
:postbox: Sorting of the tag attributes in the specified order.
https://github.com/mrmlnc/posthtml-attrs-sorter
posthtml posthtml-plugin
Last synced: 19 days ago
JSON representation
:postbox: Sorting of the tag attributes in the specified order.
- Host: GitHub
- URL: https://github.com/mrmlnc/posthtml-attrs-sorter
- Owner: mrmlnc
- License: mit
- Created: 2016-01-20T20:28:45.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-04T17:27:26.000Z (over 7 years ago)
- Last Synced: 2024-10-11T23:10:41.739Z (about 1 month ago)
- Topics: posthtml, posthtml-plugin
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 16
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# posthtml-attrs-sorter
> A [PostHTML](https://github.com/posthtml/posthtml) plugin for sort attribute of the tag based on the given order.
[![Travis](https://img.shields.io/travis/mrmlnc/posthtml-attrs-sorter.svg?style=flat-square)](https://travis-ci.org/mrmlnc/posthtml-attrs-sorter)
[![NPM version](https://img.shields.io/npm/v/posthtml-attrs-sorter.svg?style=flat-square)](https://www.npmjs.com/package/posthtml-attrs-sorter)
[![devDependency Status](https://img.shields.io/david/mrmlnc/posthtml-attrs-sorter.svg?style=flat-square)](https://david-dm.org/mrmlnc/posthtml-attrs-sorter#info=dependencies)
[![devDependency Status](https://img.shields.io/david/dev/mrmlnc/posthtml-attrs-sorter.svg?style=flat-square)](https://david-dm.org/mrmlnc/posthtml-attrs-sorter#info=devDependencies)## Install
```shell
$ npm i -D posthtml-attrs-sorter
```## Why?
To follow the guidelines for writing code such as [Code Guide by @mdo](http://codeguide.co/).
## Usage
```js
const posthtml = require('posthtml');
const attrsSorter = require('posthtml-attrs-sorter');
const htmlRaw = fs.readFileSync('path/to/file.html');posthtml()
.use(attrsSorter({
// Options
}))
.process(htmlRaw)
.then(function(result) {
fs.writeFileSync('path/to/file.html');
})
```You can also use this plugin in the PostHTML plugin to [Gulp](https://www.npmjs.com/package/gulp-posthtml) or [Grunt](https://www.npmjs.com/package/grunt-posthtml).
## Options
#### order
* Type: `string[]`
* Info:
* Strings are turned into [Regular Expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
* Use `$unknown$` to specify where the unsorted attributes are placed
* Default: http://codeguide.co/#html-attribute-order
```json
{
"order": [
"class", "id", "name",
"data-.+", "ng-.+", "src",
"for", "type", "href",
"values", "title", "alt",
"role", "aria-.+",
"$unknown$"
]
}
```An array of attributes in the correct order.
## Plugins for editors and IDE
* [Visual Studio Code](https://github.com/mrmlnc/vscode-attrs-sorter)
## Changelog
See the [Releases section of our GitHub project](https://github.com/mrmlnc/posthtml-attrs-sorter/releases) for changelogs for each release version.
## License
MIT.