Skip to content

Commit

Permalink
new build
Browse files Browse the repository at this point in the history
  • Loading branch information
alselawi committed Apr 3, 2020
1 parent a3f3e40 commit 485a19a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 22 deletions.
37 changes: 25 additions & 12 deletions dist/browser/anchorme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
(global = global || self, global.anchorme = factory());
}(this, (function () { 'use strict';

var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
Expand Down Expand Up @@ -63,8 +65,8 @@
Object.defineProperty(exports, "__esModule", { value: true });

var email_address = "([a-z0-9!#$%&'*+=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+=?^_`{|}~-]+)*)";
var domainWithTLD = "(([a-z0-9]+)(([a-z0-9-]+)?)(?<=[a-z0-9])\\.)+(" + dictionary.TLDs + ")";
var domainWithAnyTLD = "([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]";
var domainWithTLD = "([a-z0-9]+(-+[a-z0-9]+)*\\.)+(" + dictionary.TLDs + ")";
var domainWithAnyTLD = "([a-z0-9]+(-+[a-z0-9]+)*\\.)+([a-z0-9][a-z0-9-]{0," + (Math.max.apply(commonjsGlobal, dictionary.TLDs.split("|").map(function (x) { return x.length; })) - 2) + "}[a-z0-9])";
var allowedInPath = "a-zA-Z\\d\\-._~\\!$&*+,;=:@%'\"\\[\\]()";
var path = "(((\\/(?:(?:[" + allowedInPath + "]+(?:\\/[" + allowedInPath + "]*)*))?)?)((?:\\?([" + allowedInPath + "\\/?]*))?)((?:\\#([" + allowedInPath + "\\/?]*))?))?";
var ipv4 = "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
Expand All @@ -78,6 +80,7 @@
exports.url = "(" + nonLatinMatches + ")|(\\b(((" + protocol + ")?(" + domainWithTLD + "|" + ipv4 + "|" + protocol + "(" + ipv6 + "|" + domainWithAnyTLD + "))(?!@\\w)" + port + path + ")|(" + confirmedByProtocol + "))\\b" + additionalSlashes + ")";
exports.file = "file:\\/\\/\\/([a-z]+:\\/)?([\\w.]+[\\/\\\\]?)+";
exports.final = exports.url + "|" + exports.email + "|" + exports.file;
exports.finalRegex = new RegExp(exports.final, "gi");
// for validation purposes
exports.ipRegex = new RegExp("^(" + ipv4 + "|" + ipv6 + ")$", "i");
exports.emailRegex = new RegExp("^(" + exports.email + ")$", "i");
Expand All @@ -90,11 +93,12 @@
var regex_1 = regex.email;
var regex_2 = regex.url;
var regex_3 = regex.file;
var regex_4 = regex.ipRegex;
var regex_5 = regex.emailRegex;
var regex_6 = regex.fileRegex;
var regex_7 = regex.urlRegex;
var regex_8 = regex.protocolPresent;
var regex_4 = regex.finalRegex;
var regex_5 = regex.ipRegex;
var regex_6 = regex.emailRegex;
var regex_7 = regex.fileRegex;
var regex_8 = regex.urlRegex;
var regex_9 = regex.protocolPresent;

var transform_1 = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
Expand Down Expand Up @@ -154,8 +158,9 @@
attributes = applyOption(input, options.attributes);
}
return "<a " + Object.keys(attributes)
.filter(function (x) { return typeof attributes[x] !== "undefined"; })
.map(function (key) { return key + "=\"" + attributes[key] + "\" "; })
.map(function (key) {
return attributes[key] === true ? key : key + "=\"" + attributes[key] + "\" ";
})
.join(" ") + "href=\"" + protocol + input + "\">" + (input.length > truncation
? truncateFromTheMiddle
? input.substring(0, Math.floor(truncation / 2)) +
Expand Down Expand Up @@ -199,7 +204,7 @@
exports.isInsideAttribute = isInsideAttribute;
function isInsideAnchorTag(target, fullInput, targetEnd) {
var escapedTarget = target.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
var regex = new RegExp("(?<=(<a))(?!([\\s\\S]*)(<\\/a>)(" + escapedTarget + "))[\\s\\S]*?(" + escapedTarget + ")(?!\"|')", "gi");
var regex = new RegExp("(?=(<a))(?!([\\s\\S]*)(<\\/a>)(" + escapedTarget + "))[\\s\\S]*?(" + escapedTarget + ")(?!\"|')", "gi");
var result = null;
while ((result = regex.exec(fullInput)) !== null) {
var end = result.index + result[0].length;
Expand All @@ -225,7 +230,13 @@


var list = function (input) {
var regex$1 = new RegExp(regex.final, "gi");
// early kill
if (!regex.finalRegex.test(input)) {
return [];
}
else {
regex.finalRegex.lastIndex = 0;
}
var found = [];
var result = null;
var _loop_1 = function () {
Expand Down Expand Up @@ -278,7 +289,7 @@
string: string
});
};
while ((result = regex$1.exec(input)) !== null) {
while ((result = regex.finalRegex.exec(input)) !== null) {
_loop_1();
}
return found;
Expand All @@ -295,6 +306,8 @@
}
var found = list(input);
var newStr = "";
// the following code isn't very intuitive nor human readable
// but faster than others
for (var index = 0; index < found.length; index++) {
newStr =
(newStr
Expand Down
2 changes: 1 addition & 1 deletion dist/browser/anchorme.min.js

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions dist/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ var regex_1 = require("./regex");
var transform_1 = require("./transform");
var utils_1 = require("./utils");
var list = function (input) {
var regex = new RegExp(regex_1.final, "gi");
// early kill
if (!regex_1.finalRegex.test(input)) {
return [];
}
else {
regex_1.finalRegex.lastIndex = 0;
}
var found = [];
var result = null;
var _loop_1 = function () {
Expand Down Expand Up @@ -58,7 +64,7 @@ var list = function (input) {
string: string
});
};
while ((result = regex.exec(input)) !== null) {
while ((result = regex_1.finalRegex.exec(input)) !== null) {
_loop_1();
}
return found;
Expand All @@ -75,6 +81,8 @@ var anchorme = function (arg) {
}
var found = list(input);
var newStr = "";
// the following code isn't very intuitive nor human readable
// but faster than others
for (var index = 0; index < found.length; index++) {
newStr =
(newStr
Expand Down
1 change: 1 addition & 0 deletions dist/node/regex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export declare const email: string;
export declare const url: string;
export declare const file = "file:\\/\\/\\/([a-z]+:\\/)?([\\w.]+[\\/\\\\]?)+";
export declare const final: string;
export declare const finalRegex: RegExp;
export declare const ipRegex: RegExp;
export declare const emailRegex: RegExp;
export declare const fileRegex: RegExp;
Expand Down
5 changes: 3 additions & 2 deletions dist/node/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
var dictionary_1 = require("./dictionary");
var email_address = "([a-z0-9!#$%&'*+=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+=?^_`{|}~-]+)*)";
var domainWithTLD = "(([a-z0-9]+)(([a-z0-9-]+)?)(?<=[a-z0-9])\\.)+(" + dictionary_1.TLDs + ")";
var domainWithAnyTLD = "([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]";
var domainWithTLD = "([a-z0-9]+(-+[a-z0-9]+)*\\.)+(" + dictionary_1.TLDs + ")";
var domainWithAnyTLD = "([a-z0-9]+(-+[a-z0-9]+)*\\.)+([a-z0-9][a-z0-9-]{0," + (Math.max.apply(this, dictionary_1.TLDs.split("|").map(function (x) { return x.length; })) - 2) + "}[a-z0-9])";
var allowedInPath = "a-zA-Z\\d\\-._~\\!$&*+,;=:@%'\"\\[\\]()";
var path = "(((\\/(?:(?:[" + allowedInPath + "]+(?:\\/[" + allowedInPath + "]*)*))?)?)((?:\\?([" + allowedInPath + "\\/?]*))?)((?:\\#([" + allowedInPath + "\\/?]*))?))?";
var ipv4 = "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
Expand All @@ -17,6 +17,7 @@ exports.email = "\\b(mailto:)?" + email_address + "@(" + domainWithTLD + "|" + i
exports.url = "(" + nonLatinMatches + ")|(\\b(((" + protocol + ")?(" + domainWithTLD + "|" + ipv4 + "|" + protocol + "(" + ipv6 + "|" + domainWithAnyTLD + "))(?!@\\w)" + port + path + ")|(" + confirmedByProtocol + "))\\b" + additionalSlashes + ")";
exports.file = "file:\\/\\/\\/([a-z]+:\\/)?([\\w.]+[\\/\\\\]?)+";
exports.final = exports.url + "|" + exports.email + "|" + exports.file;
exports.finalRegex = new RegExp(exports.final, "gi");
// for validation purposes
exports.ipRegex = new RegExp("^(" + ipv4 + "|" + ipv6 + ")$", "i");
exports.emailRegex = new RegExp("^(" + exports.email + ")$", "i");
Expand Down
5 changes: 3 additions & 2 deletions dist/node/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ function transform(input, options) {
attributes = applyOption(input, options.attributes);
}
return "<a " + Object.keys(attributes)
.filter(function (x) { return typeof attributes[x] !== "undefined"; })
.map(function (key) { return key + "=\"" + attributes[key] + "\" "; })
.map(function (key) {
return attributes[key] === true ? key : key + "=\"" + attributes[key] + "\" ";
})
.join(" ") + "href=\"" + protocol + input + "\">" + (input.length > truncation
? truncateFromTheMiddle
? input.substring(0, Math.floor(truncation / 2)) +
Expand Down
4 changes: 2 additions & 2 deletions dist/node/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface TokenProps {
string: string;
}
export declare type DesiredValues = {
[key: string]: string | undefined;
[key: string]: string | undefined | true;
} | number | string | boolean;
export declare type TransformationOption<desiredValue> = desiredValue | ((props: string) => desiredValue);
export interface Options {
Expand All @@ -17,6 +17,6 @@ export interface Options {
middleTruncation: TransformationOption<boolean>;
exclude: TransformationOption<boolean>;
attributes: TransformationOption<{
[key: string]: string | undefined;
[key: string]: string | undefined | true;
}>;
}
2 changes: 1 addition & 1 deletion dist/node/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function isInsideAttribute(quoteType, prevFragment) {
exports.isInsideAttribute = isInsideAttribute;
function isInsideAnchorTag(target, fullInput, targetEnd) {
var escapedTarget = target.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
var regex = new RegExp("(?<=(<a))(?!([\\s\\S]*)(<\\/a>)(" + escapedTarget + "))[\\s\\S]*?(" + escapedTarget + ")(?!\"|')", "gi");
var regex = new RegExp("(?=(<a))(?!([\\s\\S]*)(<\\/a>)(" + escapedTarget + "))[\\s\\S]*?(" + escapedTarget + ")(?!\"|')", "gi");
var result = null;
while ((result = regex.exec(fullInput)) !== null) {
var end = result.index + result[0].length;
Expand Down

0 comments on commit 485a19a

Please sign in to comment.