source: trip-planner-front/node_modules/stable/README.md@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
Line 
1## Stable
2
3A stable array sort, because `Array#sort()` is not guaranteed stable.
4
5MIT licensed.
6
7[![Node.js CI](https://secure.travis-ci.org/Two-Screen/stable.png)](http://travis-ci.org/Two-Screen/stable)
8
9[![Browser CI](http://ci.testling.com/Two-Screen/stable.png)](http://ci.testling.com/Two-Screen/stable)
10
11#### From npm
12
13Install with:
14
15```sh
16npm install stable
17```
18
19Then use it in Node.js or some other CommonJS environment as:
20
21```js
22const stable = require('stable')
23```
24
25#### From the browser
26
27Include [`stable.js`] or the minified version [`stable.min.js`]
28in your page, then call `stable()`.
29
30 [`stable.js`]: https://raw.github.com/Two-Screen/stable/master/stable.js
31 [`stable.min.js`]: https://raw.github.com/Two-Screen/stable/master/stable.min.js
32
33#### Usage
34
35The default sort is, as with `Array#sort`, lexicographical:
36
37```js
38stable(['foo', 'bar', 'baz']) // => ['bar', 'baz', 'foo']
39stable([10, 1, 5]) // => [1, 10, 5]
40```
41
42Unlike `Array#sort`, the default sort is **NOT** in-place. To do an in-place
43sort, use `stable.inplace`, which otherwise works the same:
44
45```js
46const arr = [10, 1, 5]
47stable(arr) === arr // => false
48stable.inplace(arr) === arr // => true
49```
50
51A comparator function can be specified:
52
53```js
54// Regular sort() compatible comparator, that returns a number.
55// This demonstrates the default behavior.
56const lexCmp = (a, b) => String(a).localeCompare(b)
57stable(['foo', 'bar', 'baz'], lexCmp) // => ['bar', 'baz', 'foo']
58
59// Boolean comparator. Sorts `b` before `a` if true.
60// This demonstrates a simple way to sort numerically.
61const greaterThan = (a, b) => a > b
62stable([10, 1, 5], greaterThan) // => [1, 5, 10]
63```
64
65#### License
66
67Copyright (C) 2018 Angry Bytes and contributors.
68
69Permission is hereby granted, free of charge, to any person obtaining a copy of
70this software and associated documentation files (the "Software"), to deal in
71the Software without restriction, including without limitation the rights to
72use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
73of the Software, and to permit persons to whom the Software is furnished to do
74so, subject to the following conditions:
75
76The above copyright notice and this permission notice shall be included in all
77copies or substantial portions of the Software.
78
79THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
81FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
82AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
83LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
84OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
85SOFTWARE.
Note: See TracBrowser for help on using the repository browser.