Sha256: 1889d47e10210821ec877087e2e8bb3ad4cb274b246b9e1643ca97abd9b3b5a7

Contents?: true

Size: 929 Bytes

Versions: 23

Compression:

Stored size: 929 Bytes

Contents

'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
  )
}

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
trusty-cms-5.0.7 node_modules/remark-parse/lib/locate/email.js
trusty-cms-5.0.6 node_modules/remark-parse/lib/locate/email.js
trusty-cms-5.0.5 node_modules/remark-parse/lib/locate/email.js
trusty-cms-5.0.4 node_modules/remark-parse/lib/locate/email.js
trusty-cms-5.0.3 node_modules/remark-parse/lib/locate/email.js
trusty-cms-5.0.2 node_modules/remark-parse/lib/locate/email.js
trusty-cms-5.0.1 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.3.5 node_modules/remark-parse/lib/locate/email.js
trusty-cms-5.0.0 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.3.4 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.3.3 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.3.2 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.3.1 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.3 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.2.3 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.2.2 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.2.1 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.2 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.1.9 node_modules/remark-parse/lib/locate/email.js
trusty-cms-4.1.8 node_modules/remark-parse/lib/locate/email.js