This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
2020-11-01 22:46:04 +00:00

52 lines
929 B
JavaScript

'use strict'
var decimal = require('is-decimal')
var alphabetical = require('is-alphabetical')
var plusSign = 43 // '+'
var dash = 45 // '-'
var dot = 46 // '.'
var underscore = 95 // '_'
module.exports = locate
// See: <https://github.github.com/gfm/#extended-email-autolink>
function locate(value, fromIndex) {
var self = this
var at
var position
if (!this.options.gfm) {
return -1
}
at = value.indexOf('@', fromIndex)
if (at === -1) {
return -1
}
position = at
if (position === fromIndex || !isGfmAtext(value.charCodeAt(position - 1))) {
return locate.call(self, value, at + 1)
}
while (position > fromIndex && isGfmAtext(value.charCodeAt(position - 1))) {
position--
}
return position
}
function isGfmAtext(code) {
return (
decimal(code) ||
alphabetical(code) ||
code === plusSign ||
code === dash ||
code === dot ||
code === underscore
)
}