(hexString)
| 19 | })[key.toLowerCase()] // select the binary number by valid hex key with the help javascript object |
| 20 | |
| 21 | const hexToBinary = (hexString) => { |
| 22 | if (typeof hexString !== 'string') { |
| 23 | throw new TypeError('Argument is not a string type') |
| 24 | } |
| 25 | |
| 26 | if (/[^\da-f]/gi.test(hexString)) { |
| 27 | throw new Error('Argument is not a valid HEX code!') |
| 28 | } |
| 29 | /* |
| 30 | Function for converting Hex to Binary |
| 31 | |
| 32 | 1. We convert every hexadecimal bit to 4 binary bits |
| 33 | 2. Conversion goes by searching in the lookup table |
| 34 | */ |
| 35 | |
| 36 | return hexString.replace(/[0-9a-f]/gi, (lexeme) => binLookup(lexeme)) |
| 37 | } |
| 38 | |
| 39 | export default hexToBinary |
no test coverage detected