-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
Seeking willingness to incorporate a PR based on the following:
Add option crockford: bool to isBase32
isBase32(str [, options]) where options is {crockford: false} by default.
Usage: isBase32("CD89FGE", {crockford: true})
Example implementation:
import assertString from './util/assertString';
import merge from './util/merge';
const base32 = /^[A-Z2-7]+=*$/;
const crockfordBase32 = /^[A-HJKMNP-UW-Z0-9]+=*$/;
const defaultBase32Options = {
crockford: false,
};
export default function isBase32(str, options) {
assertString(str);
options = merge(options, defaultBase32Options);
const len = str.length;
if (options.crockford) {
return crockfordBase32.test(str);
}
if (len % 8 === 0 && base32.test(str)) {
return true;
}
return false;
}