isBase64.js 723 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isBase64;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. var notBase64 = /[^A-Z0-9+\/=]/i;
  9. function isBase64(str) {
  10. (0, _assertString.default)(str);
  11. var len = str.length;
  12. if (!len || len % 4 !== 0 || notBase64.test(str)) {
  13. return false;
  14. }
  15. var firstPaddingChar = str.indexOf('=');
  16. return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '=';
  17. }
  18. module.exports = exports.default;
  19. module.exports.default = exports.default;