UNPKG

1.3 kBTypeScriptView Raw
1declare module '@ember/utils/lib/compare' {
2 type Compare = -1 | 0 | 1;
3 /**
4 @module @ember/utils
5 */
6 /**
7 Compares two javascript values and returns:
8
9 - -1 if the first is smaller than the second,
10 - 0 if both are equal,
11 - 1 if the first is greater than the second.
12
13 ```javascript
14 import { compare } from '@ember/utils';
15
16 compare('hello', 'hello'); // 0
17 compare('abc', 'dfg'); // -1
18 compare(2, 1); // 1
19 ```
20
21 If the types of the two objects are different precedence occurs in the
22 following order, with types earlier in the list considered `<` types
23 later in the list:
24
25 - undefined
26 - null
27 - boolean
28 - number
29 - string
30 - array
31 - object
32 - instance
33 - function
34 - class
35 - date
36
37 ```javascript
38 import { compare } from '@ember/utils';
39
40 compare('hello', 50); // 1
41 compare(50, 'hello'); // -1
42 ```
43
44 @method compare
45 @for @ember/utils
46 @static
47 @param {Object} v First value to compare
48 @param {Object} w Second value to compare
49 @return {Number} -1 if v < w, 0 if v = w and 1 if v > w.
50 @public
51 */
52 export default function compare<T>(v: T, w: T): Compare;
53 export {};
54}