url.js 460 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. module.exports = locate;
  3. var PROTOCOLS = ['https://', 'http://', 'mailto:'];
  4. function locate(value, fromIndex) {
  5. var length = PROTOCOLS.length;
  6. var index = -1;
  7. var min = -1;
  8. var position;
  9. if (!this.options.gfm) {
  10. return -1;
  11. }
  12. while (++index < length) {
  13. position = value.indexOf(PROTOCOLS[index], fromIndex);
  14. if (position !== -1 && (position < min || min === -1)) {
  15. min = position;
  16. }
  17. }
  18. return min;
  19. }