Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

sort-nodes

megazazik6MIT0.1.1TypeScript support: included

The packege to sort arrays of DOM nodes according to the HTML tree order

html, order, sort, nodes

readme

sort-nodes

The packege to sort arrays of DOM nodes according to the HTML tree order. Based on this code.

Installation

npm i sort-nodes

sortNodes

The sortNodes function returns a new array sorted according to the HTML tree order. This function does not change an original array. You can pass true as the second argument if you need a reverse order.

import { sortNodes } from "sort-nodes";

const sortedNodes = sortNodes(nodes);

// reverse order
const reversed = sortNodes(nodes, true);

compareOrder

The compareOrder function compares order of nodes in the HTML tree. It can be used in the sort method of arrays.

import { compareOrder } from "sort-nodes";

nodes.sort(compareOrder);

reverseCompareOrder

This function is similar to compareOrder but it compares nodes in reverse order.

import { reverseCompareOrder } from "sort-nodes";

nodes.sort(reverseCompareOrder);

changelog

0.1.1 (2019-09-22)

0.1.0 (2019-09-22)