isBase64.js 719 B

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