123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 'use strict';
- var GetIntrinsic = require('get-intrinsic');
- var $Number = GetIntrinsic('%Number%');
- var $TypeError = require('es-errors/type');
- var $isNaN = require('../helpers/isNaN');
- var IsStringPrefix = require('./IsStringPrefix');
- var StringToBigInt = require('./StringToBigInt');
- var ToNumeric = require('./ToNumeric');
- var ToPrimitive = require('./ToPrimitive');
- var BigIntLessThan = require('./BigInt/lessThan');
- var NumberLessThan = require('./Number/lessThan');
- module.exports = function IsLessThan(x, y, LeftFirst) {
- if (typeof 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);
- }
- if (typeof px === 'string' && typeof py === 'string') {
- if (IsStringPrefix(py, px)) {
- return false;
- }
- if (IsStringPrefix(px, py)) {
- return true;
- }
-
- return px < py;
- }
- var nx;
- var ny;
- if (typeof px === 'bigint' && typeof py === 'string') {
- ny = StringToBigInt(py);
- if (typeof ny === 'undefined') {
- return void undefined;
- }
- return BigIntLessThan(px, ny);
- }
- if (typeof px === 'string' && typeof py === 'bigint') {
- nx = StringToBigInt(px);
- if (typeof nx === 'undefined') {
- return void undefined;
- }
- return BigIntLessThan(nx, py);
- }
- nx = ToNumeric(px);
- ny = ToNumeric(py);
- if (typeof nx === typeof ny) {
- return typeof nx === 'number' ? NumberLessThan(nx, ny) : BigIntLessThan(nx, ny);
- }
- if ($isNaN(nx) || $isNaN(ny)) {
- return void undefined;
- }
- if (nx === -Infinity || ny === Infinity) {
- return true;
- }
- if (nx === Infinity || ny === -Infinity) {
- return false;
- }
- return nx < ny;
- };
|