ToUint8.js 452 B

12345678910111213141516171819
  1. 'use strict';
  2. var isFinite = require('../helpers/isFinite');
  3. var modulo = require('./modulo');
  4. var ToNumber = require('./ToNumber');
  5. var truncate = require('./truncate');
  6. // https://262.ecma-international.org/14.0/#sec-touint8
  7. module.exports = function ToUint8(argument) {
  8. var number = ToNumber(argument);
  9. if (!isFinite(number) || number === 0) {
  10. return 0;
  11. }
  12. var int = truncate(number);
  13. var int8bit = modulo(int, 0x100);
  14. return int8bit;
  15. };