Skip to content

Instantly share code, notes, and snippets.

@9point6
Last active August 29, 2015 14:04

Revisions

  1. 9point6 revised this gist Jul 22, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion email-normalizer.coffee
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ defaultOptions =
    'stripComments': true

    class EmailNormalizer
    constructor: (@email, options = {}) ->
    constructor: ( @email, options = {} ) ->
    @options = defaultOptions
    for own k, v of options
    @options[k] = v
  2. 9point6 revised this gist Jul 22, 2014. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions email-normalizer.coffee
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,4 @@ class EmailNormalizer

    @normalized = out

    # Node JS
    if module?
    module.exports = EmailNormalizer
    ( module?.exports or window?.EmailNormalizer ) = EmailNormalizer
  3. 9point6 renamed this gist Jul 22, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions email-normaliser.coffee → email-normalizer.coffee
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    defaultOptions =
    'normaliseGmail': true
    'normalizeGmail': true
    'lowerCaseLocal': true
    'stripTags': true
    'stripComments': true

    class EmailNormaliser
    class EmailNormalizer
    constructor: (@email, options = {}) ->
    @options = defaultOptions
    for own k, v of options
    @options[k] = v

    normalise: ( ) ->
    return @normalised if @normalised
    normalize: ( ) ->
    return @normalized if @normalized

    out = @email

    @@ -24,7 +24,7 @@ class EmailNormaliser
    if @options.stripComments
    out = out.replace /^((\([^)]*\))?)([^@]+)((\([^)]*\))?)\@/, '$3@'

    if @options.normaliseGmail
    if @options.normalizeGmail
    out = out.split '@'

    if out[1] is 'googlemail.com'
    @@ -34,8 +34,8 @@ class EmailNormaliser

    out = out.join '@'

    @normalised = out
    @normalized = out

    # Node JS
    if module?
    module.exports = EmailNormaliser
    module.exports = EmailNormalizer
  4. 9point6 created this gist Jul 22, 2014.
    41 changes: 41 additions & 0 deletions email-normaliser.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    defaultOptions =
    'normaliseGmail': true
    'lowerCaseLocal': true
    'stripTags': true
    'stripComments': true

    class EmailNormaliser
    constructor: (@email, options = {}) ->
    @options = defaultOptions
    for own k, v of options
    @options[k] = v

    normalise: ( ) ->
    return @normalised if @normalised

    out = @email

    if @options.lowerCaseLocal
    out = out.toLowerCase( )

    if @options.stripTags
    out = out.replace /^([^+]+)(\+[^@]*)/, '$1'

    if @options.stripComments
    out = out.replace /^((\([^)]*\))?)([^@]+)((\([^)]*\))?)\@/, '$3@'

    if @options.normaliseGmail
    out = out.split '@'

    if out[1] is 'googlemail.com'
    out[1] = 'gmail.com'

    out[0] = out[0].replace /\./g, ''

    out = out.join '@'

    @normalised = out

    # Node JS
    if module?
    module.exports = EmailNormaliser