smtp-address-parser
Advanced tools
Comparing version 1.0.6 to 1.0.7
export declare function parse(address: string): any; | ||
/** | ||
* Apply common addreess local-part normalization rules, strip | ||
* "+something" and remove interior "."s in a dotString. Fold case. | ||
*/ | ||
export declare function normalize_dot_string(dot_string: string): string; | ||
/** | ||
* Apply common address normalization rules, strip "+something" and | ||
@@ -4,0 +9,0 @@ * remove interior "."s in a dotString. Fold case. |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.normalize = exports.parse = void 0; | ||
exports.normalize = exports.normalize_dot_string = exports.parse = void 0; | ||
// const punycode = require('punycode'); | ||
@@ -24,2 +24,18 @@ const nearley = require("nearley"); | ||
/** | ||
* Apply common addreess local-part normalization rules, strip | ||
* "+something" and remove interior "."s in a dotString. Fold case. | ||
*/ | ||
function normalize_dot_string(dot_string) { | ||
const tagless = (function () { | ||
const plus_loc = dot_string.indexOf("+"); | ||
if (plus_loc === -1) { | ||
return dot_string; | ||
} | ||
return dot_string.substr(0, plus_loc); | ||
})(); | ||
const dotless = tagless.replace(/\./g, ""); | ||
return dotless.toLowerCase(); | ||
} | ||
exports.normalize_dot_string = normalize_dot_string; | ||
/** | ||
* Apply common address normalization rules, strip "+something" and | ||
@@ -40,11 +56,3 @@ * remove interior "."s in a dotString. Fold case. | ||
} | ||
const tagless = (function () { | ||
const plus_loc = a.localPart.DotString.indexOf("+"); | ||
if (plus_loc === -1) { | ||
return a.localPart.DotString; | ||
} | ||
return a.localPart.DotString.substr(0, plus_loc); | ||
})(); | ||
const dotless = tagless.replace(/\./g, ""); | ||
return dotless.toLowerCase(); | ||
return normalize_dot_string(a.localPart.DotString); | ||
})(); | ||
@@ -51,0 +59,0 @@ return `${local}@${domain}`; |
declare const assert: any; | ||
declare const normalize: any, parse: any; | ||
declare const normalize_dot_string: any, normalize: any, parse: any; | ||
declare function _check(address: string, dot?: string, quote?: string, name?: string, addr?: string): void; |
"use strict"; | ||
const assert = require("assert"); | ||
const { normalize, parse } = require("../lib/index.js"); | ||
const { normalize_dot_string, normalize, parse } = require("../lib/index.js"); | ||
function _check(address, dot, quote, name, addr) { | ||
@@ -161,2 +161,14 @@ const a = parse(address); | ||
describe("test normalize", function () { | ||
it("foo", function () { | ||
assert.equal(normalize_dot_string("foo"), "foo"); | ||
}); | ||
it("foo+bar", function () { | ||
assert.equal(normalize_dot_string("foo+bar"), "foo"); | ||
}); | ||
it("foo.bar", function () { | ||
assert.equal(normalize_dot_string("foo.bar"), "foobar"); | ||
}); | ||
it("Foo.Bar", function () { | ||
assert.equal(normalize_dot_string("Foo.Bar"), "foobar"); | ||
}); | ||
it("foo@example.org", function () { | ||
@@ -163,0 +175,0 @@ assert.equal(normalize("foo@example.org"), "foo@example.org"); |
@@ -24,2 +24,18 @@ "use strict"; | ||
/** | ||
* Apply common addreess local-part normalization rules, strip | ||
* "+something" and remove interior "."s in a dotString. Fold case. | ||
*/ | ||
export function normalize_dot_string(dot_string: string) { | ||
const tagless = (function () { | ||
const plus_loc = dot_string.indexOf("+"); | ||
if (plus_loc === -1) { | ||
return dot_string; | ||
} | ||
return dot_string.substr(0, plus_loc); | ||
})(); | ||
const dotless = tagless.replace(/\./g, ""); | ||
return dotless.toLowerCase(); | ||
} | ||
/** | ||
* Apply common address normalization rules, strip "+something" and | ||
@@ -39,13 +55,5 @@ * remove interior "."s in a dotString. Fold case. | ||
} | ||
const tagless = (function () { | ||
const plus_loc = a.localPart.DotString.indexOf("+"); | ||
if (plus_loc === -1) { | ||
return a.localPart.DotString; | ||
} | ||
return a.localPart.DotString.substr(0, plus_loc); | ||
})(); | ||
const dotless = tagless.replace(/\./g, ""); | ||
return dotless.toLowerCase(); | ||
return normalize_dot_string(a.localPart.DotString); | ||
})(); | ||
return `${local}@${domain}`; | ||
} |
{ | ||
"name": "smtp-address-parser", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Parse an SMTP (RFC-5321) address", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
@@ -5,3 +5,3 @@ "use strict"; | ||
const { normalize, parse } = require("../lib/index.js"); | ||
const { normalize_dot_string, normalize, parse } = require("../lib/index.js"); | ||
@@ -175,2 +175,14 @@ function _check(address: string, dot?: string, quote?: string, name?: string, addr?: string) { | ||
describe("test normalize", function () { | ||
it("foo", function () { | ||
assert.equal(normalize_dot_string("foo"), "foo"); | ||
}); | ||
it("foo+bar", function () { | ||
assert.equal(normalize_dot_string("foo+bar"), "foo"); | ||
}); | ||
it("foo.bar", function () { | ||
assert.equal(normalize_dot_string("foo.bar"), "foobar"); | ||
}); | ||
it("Foo.Bar", function () { | ||
assert.equal(normalize_dot_string("Foo.Bar"), "foobar"); | ||
}); | ||
it("foo@example.org", function () { | ||
@@ -177,0 +189,0 @@ assert.equal(normalize("foo@example.org"), "foo@example.org"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
65854
754