source: imaps-frontend/node_modules/core-js/internals/uint8-from-hex.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1001 bytes
Line 
1'use strict';
2var globalThis = require('../internals/global-this');
3var uncurryThis = require('../internals/function-uncurry-this');
4
5var Uint8Array = globalThis.Uint8Array;
6var SyntaxError = globalThis.SyntaxError;
7var parseInt = globalThis.parseInt;
8var min = Math.min;
9var NOT_HEX = /[^\da-f]/i;
10var exec = uncurryThis(NOT_HEX.exec);
11var stringSlice = uncurryThis(''.slice);
12
13module.exports = function (string, into) {
14 var stringLength = string.length;
15 if (stringLength % 2 !== 0) throw new SyntaxError('String should be an even number of characters');
16 var maxLength = into ? min(into.length, stringLength / 2) : stringLength / 2;
17 var bytes = into || new Uint8Array(maxLength);
18 var read = 0;
19 var written = 0;
20 while (written < maxLength) {
21 var hexits = stringSlice(string, read, read += 2);
22 if (exec(NOT_HEX, hexits)) throw new SyntaxError('String should only contain hex characters');
23 bytes[written++] = parseInt(hexits, 16);
24 }
25 return { bytes: bytes, read: read };
26};
Note: See TracBrowser for help on using the repository browser.