Skip to content

Commit

Permalink
📚 docs(README): Add example usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Sep 1, 2020
1 parent fa1589b commit d4126fe
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ See [docs](https://aureooms.github.io/js-total-order/index.html).
> :warning: The code requires `regeneratorRuntime` to be defined, for instance by importing
> [regenerator-runtime/runtime](https://www.npmjs.com/package/regenerator-runtime).
```js
import totalOrder from 'total-order'
[ [1, 2, 3], 0, undefined, {x: 1}, new Date(1), null, {}, /abc/, new Date(0), 'abc', [], NaN ].sort(totalOrder)
// [
// 0,
// NaN,
// null,
// [],
// [1, 2, 3],
// new Date(0),
// new Date(1),
// {},
// {x: 1},
// /abc/,
// 'abc',
// undefined,
// ]
```

[![License](https://img.shields.io/github/license/aureooms/js-total-order.svg)](https://raw.githubusercontent.com/aureooms/js-total-order/master/LICENSE)
[![Version](https://img.shields.io/npm/v/total-order.svg)](https://www.npmjs.org/package/total-order)
[![Build](https://img.shields.io/travis/aureooms/js-total-order/master.svg)](https://travis-ci.org/aureooms/js-total-order/branches)
Expand Down
33 changes: 33 additions & 0 deletions test/src/deepCompare.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,36 @@ test('circular a < b', (t) => {
t.is(-1, deepCompare(a, b));
t.is(1, deepCompare(b, a));
});

test('README', (t) => {
const values = [
[1, 2, 3],
0,
undefined,
{x: 1},
new Date(1),
null,
{},
/abc/,
new Date(0),
'abc',
[],
Number.NaN,
];
const sorted = [
0,
Number.NaN,
null,
[],
[1, 2, 3],
new Date(0),
new Date(1),
{},
{x: 1},
/abc/,
'abc',
undefined,
];
const result = values.slice().sort(deepCompare);
t.deepEqual(sorted, result);
});

0 comments on commit d4126fe

Please sign in to comment.