"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/es5-ext/object/compare.js" (8 Mar 2017, 912 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 };