reorder-attributes

0.1.1 • Public • Published

reorder-attributes NPM version

Re-format attributes in HTML tags to flow in a specific order. If you always prefer class before id or whatever, this module does that.

Install

Install with npm:

npm i reorder-attributes --save-dev

Run tests

npm test

Usage

Pass a string of HTML to reorderAttr():

var reorderAttr = require('strip-attributes');
var str = '<h1 id="a" class="b">Foo</h1>';
 
// Re-order so `class` is before `id`
reorderAttr(str, ['class']);
//=> '<h1 class="b" id="a">Foo</h1>'

Create an array of attributes to order all of your attributes:

var attr = ['id', 'class', 'name', 'href', 'rel', ...];
// only the attributes that actually exist will be re-ordered.
reorderAttr(str, attr);

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on October 16, 2014.

Package Sidebar

Install

npm i reorder-attributes

Weekly Downloads

2

Version

0.1.1

License

none

Last publish

Collaborators

  • doowb
  • jonschlinkert