source: imaps-frontend/node_modules/es-abstract/2024/IsLooselyEqual.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[d565449]1'use strict';
2
3var isFinite = require('../helpers/isFinite');
4
5var IsStrictlyEqual = require('./IsStrictlyEqual');
6var StringToBigInt = require('./StringToBigInt');
7var ToNumber = require('./ToNumber');
8var ToPrimitive = require('./ToPrimitive');
9var Type = require('./Type');
10
11// https://262.ecma-international.org/13.0/#sec-islooselyequal
12
13module.exports = function IsLooselyEqual(x, y) {
14 var xType = Type(x);
15 var yType = Type(y);
16 if (xType === yType) {
17 return IsStrictlyEqual(x, y);
18 }
19 if (x == null && y == null) {
20 return true;
21 }
22 if (xType === 'Number' && yType === 'String') {
23 return IsLooselyEqual(x, ToNumber(y));
24 }
25 if (xType === 'String' && yType === 'Number') {
26 return IsLooselyEqual(ToNumber(x), y);
27 }
28 if (xType === 'BigInt' && yType === 'String') {
29 var n = StringToBigInt(y);
30 if (typeof n === 'undefined') {
31 return false;
32 }
33 return IsLooselyEqual(x, n);
34 }
35 if (xType === 'String' && yType === 'BigInt') {
36 return IsLooselyEqual(y, x);
37 }
38 if (xType === 'Boolean') {
39 return IsLooselyEqual(ToNumber(x), y);
40 }
41 if (yType === 'Boolean') {
42 return IsLooselyEqual(x, ToNumber(y));
43 }
44 if ((xType === 'String' || xType === 'Number' || xType === 'Symbol' || xType === 'BigInt') && yType === 'Object') {
45 return IsLooselyEqual(x, ToPrimitive(y));
46 }
47 if (xType === 'Object' && (yType === 'String' || yType === 'Number' || yType === 'Symbol' || yType === 'BigInt')) {
48 return IsLooselyEqual(ToPrimitive(x), y);
49 }
50 if ((xType === 'BigInt' && yType === 'Number') || (xType === 'Number' && yType === 'BigInt')) {
51 if (!isFinite(x) || !isFinite(y)) {
52 return false;
53 }
54 // eslint-disable-next-line eqeqeq
55 return x == y; // shortcut for step 13.b.
56 }
57 return false;
58};
Note: See TracBrowser for help on using the repository browser.