Skip to content

Commit

Permalink
Extract hex regex in its own var for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Mar 29, 2024
1 parent 1fa5d30 commit 007b75e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion auth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ <h2>Message log</h2>
* @returns {Uint8Array}
*/
var uint8arrayFromHexString = function(hexString) {
if (!hexString || hexString.length % 2 != 0 || !/^[0-9A-Fa-f]+$/.test(hexString)) {
var hexRegex = /^[0-9A-Fa-f]+$/;
if (!hexString || hexString.length % 2 != 0 || !hexRegex.test(hexString)) {
throw new Error('cannot create uint8array from invalid hex string: "' + hexString + '"');
}
return new Uint8Array(hexString.match(/../g).map(h=>parseInt(h,16)));
Expand Down
3 changes: 2 additions & 1 deletion export/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ <h2>Message log</h2>
* @returns {Uint8Array}
*/
const uint8arrayFromHexString = function(hexString) {
if (!hexString || hexString.length % 2 != 0 || !/^[0-9A-Fa-f]+$/.test(hexString)) {
var hexRegex = /^[0-9A-Fa-f]+$/;
if (!hexString || hexString.length % 2 != 0 || !hexRegex.test(hexString)) {
throw new Error('cannot create uint8array from invalid hex string: "' + hexString + '"');
}
return new Uint8Array(hexString.match(/../g).map(h=>parseInt(h,16)));
Expand Down

0 comments on commit 007b75e

Please sign in to comment.