UNPKG

autolinker

Version:

Utility to automatically link the URLs, email addresses, phone numbers, hashtags, and mentions (Twitter, Instagram) in a given block of text/HTML

1 lines 4.25 kB
{"version":3,"file":"phone-match.js","sourceRoot":"","sources":["../../../src/match/phone-match.ts"],"names":[],"mappings":";;;;AAAA,mDAAsE;AAEtE;;;;;;;;;GASG;AACH;IAAgC,sCAAa;IAgCzC;;;;OAIG;IACH,oBAAY,GAAqB;QAC7B,YAAA,MAAK,YAAC,GAAG,CAAC,SAAC;QArCf;;;;;;;WAOG;QACa,UAAI,GAAG,OAAgB,CAAC;QAExC;;;;;;;WAOG;QACc,YAAM,GAAW,EAAE,CAAC,CAAC,gGAAgG;QAEtI;;;;;;;;WAQG;QACc,cAAQ,GAAY,KAAK,CAAC,CAAC,gGAAgG;QAUxI,KAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACzB,KAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;;IACjC,CAAC;IAED;;;;;OAKG;IACH,4BAAO,GAAP;QACI,OAAO,OAAO,CAAC;IACnB,CAAC;IAED;;;;;;;OAOG;IACH,mCAAc,GAAd;QACI,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACH,8BAAS,GAAT;QACI,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,kCAAa,GAAb;QACI,OAAO,MAAM,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,kCAAa,GAAb;QACI,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IACL,iBAAC;AAAD,CAAC,AA/FD,CAAgC,8BAAa,GA+F5C;AA/FY,gCAAU","sourcesContent":["import { AbstractMatch, AbstractMatchConfig } from './abstract-match';\n\n/**\n * @class Autolinker.match.Phone\n * @extends Autolinker.match.AbstractMatch\n *\n * Represents a Phone number match found in an input string which should be\n * Autolinked.\n *\n * See this class's superclass ({@link Autolinker.match.Match}) for more\n * details.\n */\nexport class PhoneMatch extends AbstractMatch {\n /**\n * @public\n * @property {'phone'} type\n *\n * A string name for the type of match that this class represents. Can be\n * used in a TypeScript discriminating union to type-narrow from the\n * `Match` type.\n */\n public readonly type = 'phone' as const;\n\n /**\n * @protected\n * @property {String} number (required)\n *\n * The phone number that was matched, without any delimiter characters.\n *\n * Note: This is a string to allow for prefixed 0's.\n */\n private readonly number: string = ''; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n /**\n * @protected\n * @property {Boolean} plusSign (required)\n *\n * `true` if the matched phone number started with a '+' sign. We'll include\n * it in the `tel:` URL if so, as this is needed for international numbers.\n *\n * Ex: '+1 (123) 456 7879'\n */\n private readonly plusSign: boolean = false; // default value just to get the above doc comment in the ES5 output and documentation generator\n\n /**\n * @method constructor\n * @param {Object} cfg The configuration properties for the Match\n * instance, specified in an Object (map).\n */\n constructor(cfg: PhoneMatchConfig) {\n super(cfg);\n\n this.number = cfg.number;\n this.plusSign = cfg.plusSign;\n }\n\n /**\n * Returns a string name for the type of match that this class represents.\n * For the case of PhoneMatch, returns 'phone'.\n *\n * @return {String}\n */\n getType(): 'phone' {\n return 'phone';\n }\n\n /**\n * Returns the phone number that was matched as a string, without any\n * delimiter characters.\n *\n * Note: This is a string to allow for prefixed 0's.\n *\n * @return {String}\n */\n getPhoneNumber(): string {\n return this.number;\n }\n\n /**\n * Alias of {@link #getPhoneNumber}, returns the phone number that was\n * matched as a string, without any delimiter characters.\n *\n * Note: This is a string to allow for prefixed 0's.\n *\n * @return {String}\n */\n getNumber(): string {\n return this.getPhoneNumber();\n }\n\n /**\n * Returns the anchor href that should be generated for the match.\n *\n * @return {String}\n */\n getAnchorHref(): string {\n return 'tel:' + (this.plusSign ? '+' : '') + this.number;\n }\n\n /**\n * Returns the anchor text that should be generated for the match.\n *\n * @return {String}\n */\n getAnchorText(): string {\n return this.matchedText;\n }\n}\n\nexport interface PhoneMatchConfig extends AbstractMatchConfig {\n number: string;\n plusSign: boolean;\n}\n"]}