Sha256: 0246b938fe11124d2c1f58f39636646b85f5415edf3f25aaf24e1b35abbd6ef5

Contents?: true

Size: 1.55 KB

Versions: 136

Compression:

Stored size: 1.55 KB

Contents

'use strict';

var GetIntrinsic = require('get-intrinsic');

var $Number = GetIntrinsic('%Number%');
var $TypeError = GetIntrinsic('%TypeError%');

var $isNaN = require('../helpers/isNaN');
var $isFinite = require('../helpers/isFinite');
var isPrefixOf = require('../helpers/isPrefixOf');

var ToNumber = require('./ToNumber');
var ToPrimitive = require('./ToPrimitive');
var Type = require('./Type');

// https://262.ecma-international.org/5.1/#sec-11.8.5

// eslint-disable-next-line max-statements
module.exports = function AbstractRelationalComparison(x, y, LeftFirst) {
	if (Type(LeftFirst) !== 'Boolean') {
		throw new $TypeError('Assertion failed: LeftFirst argument must be a Boolean');
	}
	var px;
	var py;
	if (LeftFirst) {
		px = ToPrimitive(x, $Number);
		py = ToPrimitive(y, $Number);
	} else {
		py = ToPrimitive(y, $Number);
		px = ToPrimitive(x, $Number);
	}
	var bothStrings = Type(px) === 'String' && Type(py) === 'String';
	if (!bothStrings) {
		var nx = ToNumber(px);
		var ny = ToNumber(py);
		if ($isNaN(nx) || $isNaN(ny)) {
			return undefined;
		}
		if ($isFinite(nx) && $isFinite(ny) && nx === ny) {
			return false;
		}
		if (nx === Infinity) {
			return false;
		}
		if (ny === Infinity) {
			return true;
		}
		if (ny === -Infinity) {
			return false;
		}
		if (nx === -Infinity) {
			return true;
		}
		return nx < ny; // by now, these are both nonzero, finite, and not equal
	}
	if (isPrefixOf(py, px)) {
		return false;
	}
	if (isPrefixOf(px, py)) {
		return true;
	}
	return px < py; // both strings, neither a prefix of the other. shortcut for steps c-f
};

Version data entries

136 entries across 30 versions & 4 rubygems

Version Path
immosquare-cleaner-0.1.32 node_modules/es-abstract/2016/AbstractRelationalComparison.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2017/AbstractRelationalComparison.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/5/AbstractRelationalComparison.js
immosquare-cleaner-0.1.32 node_modules/es-abstract/2015/AbstractRelationalComparison.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2016/AbstractRelationalComparison.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2015/AbstractRelationalComparison.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/5/AbstractRelationalComparison.js
immosquare-cleaner-0.1.31 node_modules/es-abstract/2017/AbstractRelationalComparison.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2017/AbstractRelationalComparison.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2015/AbstractRelationalComparison.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/2016/AbstractRelationalComparison.js
immosquare-cleaner-0.1.30 node_modules/es-abstract/5/AbstractRelationalComparison.js
immosquare-cleaner-0.1.29 node_modules/es-abstract/2015/AbstractRelationalComparison.js
immosquare-cleaner-0.1.29 node_modules/es-abstract/2016/AbstractRelationalComparison.js
immosquare-cleaner-0.1.29 node_modules/es-abstract/2017/AbstractRelationalComparison.js
immosquare-cleaner-0.1.29 node_modules/es-abstract/5/AbstractRelationalComparison.js
immosquare-cleaner-0.1.28 node_modules/es-abstract/2016/AbstractRelationalComparison.js
immosquare-cleaner-0.1.28 node_modules/es-abstract/2017/AbstractRelationalComparison.js
immosquare-cleaner-0.1.28 node_modules/es-abstract/5/AbstractRelationalComparison.js
immosquare-cleaner-0.1.28 node_modules/es-abstract/2015/AbstractRelationalComparison.js