utils/node_modules/validator/lib/isBase32.js

38 lines
863 B
JavaScript
Raw Normal View History

2024-02-07 01:33:07 -05:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isBase32;
var _assertString = _interopRequireDefault(require("./util/assertString"));
var _merge = _interopRequireDefault(require("./util/merge"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var base32 = /^[A-Z2-7]+=*$/;
var crockfordBase32 = /^[A-HJKMNP-TV-Z0-9]+$/;
var defaultBase32Options = {
crockford: false
};
function isBase32(str, options) {
(0, _assertString.default)(str);
options = (0, _merge.default)(options, defaultBase32Options);
if (options.crockford) {
return crockfordBase32.test(str);
}
var len = str.length;
if (len % 8 === 0 && base32.test(str)) {
return true;
}
return false;
}
module.exports = exports.default;
module.exports.default = exports.default;