component-sort

0.0.4 • Public • Published

sort

Sort DOM elements

Installation

$ component install component/sort

API

sort(el, fn)

Sort element ascending with the given callback function.

sort.asc(el, fn)

Alias of sort(el, fn)

sort.desc(el, fn)

Sort descending, inverting the fn() return value.

Example

<ul>
  <li>Tobi</li>
  <li>Jane</li>
  <li>Abby</li>
  <li>Loki</li>
  <li>Simon</li>
  <li>Manny</li>
  <li>Luna</li>
</ul>
 
<button onclick='asc()'>Sort ascending</button>
<button onclick='desc()'>Sort descending</button>
 
<script src="build/build.js"></script>
<script>
  var sort = require('sort');
  var ul = document.querySelector('ul');
 
  function alpha(a, b){
    a = a.textContent;
    b = b.textContent;
    if (< b) return -1;
    if (> b) return 1;
    return 0;
  }
 
  function asc() {
    sort(ul, alpha);
  }
 
  function desc() {
    sort.desc(ul, alpha);
  }
</script> 

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i component-sort

      Weekly Downloads

      6

      Version

      0.0.4

      License

      MIT

      Last publish

      Collaborators

      • defunctzombie
      • dfcreative
      • tootallnate
      • tjholowaychuk
      • rauchg
      • retrofox
      • kelonye
      • mattmueller
      • yields
      • anthonyshort
      • jongleberry
      • ianstormtaylor
      • cristiandouce
      • swatinem
      • stagas
      • amasad
      • juliangruber
      • calvinfo
      • dominicbarnes
      • nami-doc
      • jonathanong
      • clintwood
      • thehydroimpulse
      • stephenmathieson
      • trevorgerhardt
      • timaschew
      • hughsk