index.js 940 B

123456789101112131415161718192021222324252627
  1. /*global define */
  2. // Detecting data URLs
  3. // data URI - MDN https://developer.mozilla.org/en-US/docs/data_URIs
  4. // The "data" URL scheme: http://tools.ietf.org/html/rfc2397
  5. // Valid URL Characters: http://tools.ietf.org/html/rfc2396#section2
  6. (function (root, factory) {
  7. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignore-a-umd-wrapper
  8. /* istanbul ignore next */
  9. if (typeof define === 'function' && define.amd) {
  10. define([], factory);
  11. } else if (typeof module === 'object' && module.exports) {
  12. module.exports = factory();
  13. } else {
  14. root.validDataUrl = factory();
  15. }
  16. }(this, function () {
  17. 'use strict';
  18. function validDataUrl(s) {
  19. return validDataUrl.regex.test((s || '').trim());
  20. }
  21. validDataUrl.regex = /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*?)$/i;
  22. return validDataUrl;
  23. }));