]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/object/compare.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / node-gyp / node_modules / path-array / node_modules / array-index / node_modules / es6-symbol / node_modules / es5-ext / object / compare.js
1 'use strict';
2
3 var strCompare = require('../string/#/case-insensitive-compare')
4   , isObject   = require('./is-object')
5
6   , resolve, typeMap;
7
8 typeMap = {
9         undefined: 0,
10         object: 1,
11         boolean: 2,
12         string: 3,
13         number: 4
14 };
15
16 resolve = function (a) {
17         if (isObject(a)) {
18                 if (typeof a.valueOf !== 'function') return NaN;
19                 a = a.valueOf();
20                 if (isObject(a)) {
21                         if (typeof a.toString !== 'function') return NaN;
22                         a = a.toString();
23                         if (typeof a !== 'string') return NaN;
24                 }
25         }
26         return a;
27 };
28
29 module.exports = function (a, b) {
30         if (a === b) return 0; // Same
31
32         a = resolve(a);
33         b = resolve(b);
34         if (a == b) return typeMap[typeof a] - typeMap[typeof b]; //jslint: ignore
35         if (a == null) return -1;
36         if (b == null) return 1;
37         if ((typeof a === 'string') || (typeof b === 'string')) {
38                 return strCompare.call(a, b);
39         }
40         if ((a !== a) && (b !== b)) return 0; //jslint: ignore
41         return Number(a) - Number(b);
42 };