"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var regex_1=require("./regex");function applyOption(t,e){return"function"==typeof e?e(t):e}function transform(t,e){var r="",n=1/0,o={},a=!1;if(e&&e.specialTransform)for(var i=0;i<e.specialTransform.length;i++){var p=e.specialTransform[i];if(p.test.test(t))return p.transform(t)}return e&&e.exclude&&applyOption(t,e.exclude)?t:(e&&e.protocol&&(r=applyOption(t,e.protocol)),r=regex_1.protocolPresent.test(t)?"":r||(regex_1.emailRegex.test(t)?"mailto:":regex_1.fileRegex.test(t)?"file:///":"http://"),e&&e.truncate&&(n=applyOption(t,e.truncate)),e&&e.middleTruncation&&(a=applyOption(t,e.middleTruncation)),e&&e.attributes&&(o=applyOption(t,e.attributes)),"<a "+Object.keys(o).map(function(t){return!0===o[t]?t:t+'="'+o[t]+'" '}).join(" ")+'href="'+r+t+'">'+(t.length>n?a?t.substring(0,Math.floor(n/2))+"…"+t.substring(t.length-Math.ceil(n/2),t.length):t.substring(0,n)+"…":t)+"</a>")}exports.transform=transform;