source: imaps-frontend/node_modules/es-abstract/2019/ToUint8Clamp.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 515 bytes
Line 
1'use strict';
2
3var ToNumber = require('./ToNumber');
4var floor = require('./floor');
5
6var $isNaN = require('../helpers/isNaN');
7
8// https://262.ecma-international.org/6.0/#sec-touint8clamp
9
10module.exports = function ToUint8Clamp(argument) {
11 var number = ToNumber(argument);
12 if ($isNaN(number) || number <= 0) { return 0; }
13 if (number >= 0xFF) { return 0xFF; }
14 var f = floor(number);
15 if (f + 0.5 < number) { return f + 1; }
16 if (number < f + 0.5) { return f; }
17 if (f % 2 !== 0) { return f + 1; }
18 return f;
19};
Note: See TracBrowser for help on using the repository browser.