isBase32.js 863 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isBase32;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. var _merge = _interopRequireDefault(require("./util/merge"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. var base32 = /^[A-Z2-7]+=*$/;
  10. var crockfordBase32 = /^[A-HJKMNP-TV-Z0-9]+$/;
  11. var defaultBase32Options = {
  12. crockford: false
  13. };
  14. function isBase32(str, options) {
  15. (0, _assertString.default)(str);
  16. options = (0, _merge.default)(options, defaultBase32Options);
  17. if (options.crockford) {
  18. return crockfordBase32.test(str);
  19. }
  20. var len = str.length;
  21. if (len % 8 === 0 && base32.test(str)) {
  22. return true;
  23. }
  24. return false;
  25. }
  26. module.exports = exports.default;
  27. module.exports.default = exports.default;