{"version":3,"file":"address-formatter.js","sources":["../../node_modules/mustache/mustache.js","../../src/index.js"],"sourcesContent":["(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n (global = global || self, global.Mustache = factory());\n}(this, (function () { 'use strict';\n\n /*!\n * mustache.js - Logic-less {{mustache}} templates with JavaScript\n * http://github.com/janl/mustache.js\n */\n\n var objectToString = Object.prototype.toString;\n var isArray = Array.isArray || function isArrayPolyfill (object) {\n return objectToString.call(object) === '[object Array]';\n };\n\n function isFunction (object) {\n return typeof object === 'function';\n }\n\n /**\n * More correct typeof string handling array\n * which normally returns typeof 'object'\n */\n function typeStr (obj) {\n return isArray(obj) ? 'array' : typeof obj;\n }\n\n function escapeRegExp (string) {\n return string.replace(/[\\-\\[\\]{}()*+?.,\\\\\\^$|#\\s]/g, '\\\\$&');\n }\n\n /**\n * Null safe way of checking whether or not an object,\n * including its prototype, has a given property\n */\n function hasProperty (obj, propName) {\n return obj != null && typeof obj === 'object' && (propName in obj);\n }\n\n /**\n * Safe way of detecting whether or not the given thing is a primitive and\n * whether it has the given property\n */\n function primitiveHasOwnProperty (primitive, propName) {\n return (\n primitive != null\n && typeof primitive !== 'object'\n && primitive.hasOwnProperty\n && primitive.hasOwnProperty(propName)\n );\n }\n\n // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577\n // See https://github.com/janl/mustache.js/issues/189\n var regExpTest = RegExp.prototype.test;\n function testRegExp (re, string) {\n return regExpTest.call(re, string);\n }\n\n var nonSpaceRe = /\\S/;\n function isWhitespace (string) {\n return !testRegExp(nonSpaceRe, string);\n }\n\n var entityMap = {\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '/': '/',\n '`': '`',\n '=': '='\n };\n\n function escapeHtml (string) {\n return String(string).replace(/[&<>\"'`=\\/]/g, function fromEntityMap (s) {\n return entityMap[s];\n });\n }\n\n var whiteRe = /\\s*/;\n var spaceRe = /\\s+/;\n var equalsRe = /\\s*=/;\n var curlyRe = /\\s*\\}/;\n var tagRe = /#|\\^|\\/|>|\\{|&|=|!/;\n\n /**\n * Breaks up the given `template` string into a tree of tokens. If the `tags`\n * argument is given here it must be an array with two string values: the\n * opening and closing tags used in the template (e.g. [ \"<%\", \"%>\" ]). Of\n * course, the default is to use mustaches (i.e. mustache.tags).\n *\n * A token is an array with at least 4 elements. The first element is the\n * mustache symbol that was used inside the tag, e.g. \"#\" or \"&\". If the tag\n * did not contain a symbol (i.e. {{myValue}}) this element is \"name\". For\n * all text that appears outside a symbol this element is \"text\".\n *\n * The second element of a token is its \"value\". For mustache tags this is\n * whatever else was inside the tag besides the opening symbol. For text tokens\n * this is the text itself.\n *\n * The third and fourth elements of the token are the start and end indices,\n * respectively, of the token in the original template.\n *\n * Tokens that are the root node of a subtree contain two more elements: 1) an\n * array of tokens in the subtree and 2) the index in the original template at\n * which the closing tag for that section begins.\n *\n * Tokens for partials also contain two more elements: 1) a string value of\n * indendation prior to that tag and 2) the index of that tag on that line -\n * eg a value of 2 indicates the partial is the third tag on this line.\n */\n function parseTemplate (template, tags) {\n if (!template)\n return [];\n var lineHasNonSpace = false;\n var sections = []; // Stack to hold section tokens\n var tokens = []; // Buffer to hold the tokens\n var spaces = []; // Indices of whitespace tokens on the current line\n var hasTag = false; // Is there a {{tag}} on the current line?\n var nonSpace = false; // Is there a non-space char on the current line?\n var indentation = ''; // Tracks indentation for tags that use it\n var tagIndex = 0; // Stores a count of number of tags encountered on a line\n\n // Strips all whitespace tokens array for the current line\n // if there was a {{#tag}} on it and otherwise only space.\n function stripSpace () {\n if (hasTag && !nonSpace) {\n while (spaces.length)\n delete tokens[spaces.pop()];\n } else {\n spaces = [];\n }\n\n hasTag = false;\n nonSpace = false;\n }\n\n var openingTagRe, closingTagRe, closingCurlyRe;\n function compileTags (tagsToCompile) {\n if (typeof tagsToCompile === 'string')\n tagsToCompile = tagsToCompile.split(spaceRe, 2);\n\n if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)\n throw new Error('Invalid tags: ' + tagsToCompile);\n\n openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\\\s*');\n closingTagRe = new RegExp('\\\\s*' + escapeRegExp(tagsToCompile[1]));\n closingCurlyRe = new RegExp('\\\\s*' + escapeRegExp('}' + tagsToCompile[1]));\n }\n\n compileTags(tags || mustache.tags);\n\n var scanner = new Scanner(template);\n\n var start, type, value, chr, token, openSection;\n while (!scanner.eos()) {\n start = scanner.pos;\n\n // Match any text between tags.\n value = scanner.scanUntil(openingTagRe);\n\n if (value) {\n for (var i = 0, valueLength = value.length; i < valueLength; ++i) {\n chr = value.charAt(i);\n\n if (isWhitespace(chr)) {\n spaces.push(tokens.length);\n indentation += chr;\n } else {\n nonSpace = true;\n lineHasNonSpace = true;\n indentation += ' ';\n }\n\n tokens.push([ 'text', chr, start, start + 1 ]);\n start += 1;\n\n // Check for whitespace on the current line.\n if (chr === '\\n') {\n stripSpace();\n indentation = '';\n tagIndex = 0;\n lineHasNonSpace = false;\n }\n }\n }\n\n // Match the opening tag.\n if (!scanner.scan(openingTagRe))\n break;\n\n hasTag = true;\n\n // Get the tag type.\n type = scanner.scan(tagRe) || 'name';\n scanner.scan(whiteRe);\n\n // Get the tag value.\n if (type === '=') {\n value = scanner.scanUntil(equalsRe);\n scanner.scan(equalsRe);\n scanner.scanUntil(closingTagRe);\n } else if (type === '{') {\n value = scanner.scanUntil(closingCurlyRe);\n scanner.scan(curlyRe);\n scanner.scanUntil(closingTagRe);\n type = '&';\n } else {\n value = scanner.scanUntil(closingTagRe);\n }\n\n // Match the closing tag.\n if (!scanner.scan(closingTagRe))\n throw new Error('Unclosed tag at ' + scanner.pos);\n\n if (type == '>') {\n token = [ type, value, start, scanner.pos, indentation, tagIndex, lineHasNonSpace ];\n } else {\n token = [ type, value, start, scanner.pos ];\n }\n tagIndex++;\n tokens.push(token);\n\n if (type === '#' || type === '^') {\n sections.push(token);\n } else if (type === '/') {\n // Check section nesting.\n openSection = sections.pop();\n\n if (!openSection)\n throw new Error('Unopened section \"' + value + '\" at ' + start);\n\n if (openSection[1] !== value)\n throw new Error('Unclosed section \"' + openSection[1] + '\" at ' + start);\n } else if (type === 'name' || type === '{' || type === '&') {\n nonSpace = true;\n } else if (type === '=') {\n // Set the tags for the next time around.\n compileTags(value);\n }\n }\n\n stripSpace();\n\n // Make sure there are no open sections when we're done.\n openSection = sections.pop();\n\n if (openSection)\n throw new Error('Unclosed section \"' + openSection[1] + '\" at ' + scanner.pos);\n\n return nestTokens(squashTokens(tokens));\n }\n\n /**\n * Combines the values of consecutive text tokens in the given `tokens` array\n * to a single token.\n */\n function squashTokens (tokens) {\n var squashedTokens = [];\n\n var token, lastToken;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n token = tokens[i];\n\n if (token) {\n if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {\n lastToken[1] += token[1];\n lastToken[3] = token[3];\n } else {\n squashedTokens.push(token);\n lastToken = token;\n }\n }\n }\n\n return squashedTokens;\n }\n\n /**\n * Forms the given array of `tokens` into a nested tree structure where\n * tokens that represent a section have two additional items: 1) an array of\n * all tokens that appear in that section and 2) the index in the original\n * template that represents the end of that section.\n */\n function nestTokens (tokens) {\n var nestedTokens = [];\n var collector = nestedTokens;\n var sections = [];\n\n var token, section;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n token = tokens[i];\n\n switch (token[0]) {\n case '#':\n case '^':\n collector.push(token);\n sections.push(token);\n collector = token[4] = [];\n break;\n case '/':\n section = sections.pop();\n section[5] = token[2];\n collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens;\n break;\n default:\n collector.push(token);\n }\n }\n\n return nestedTokens;\n }\n\n /**\n * A simple string scanner that is used by the template parser to find\n * tokens in template strings.\n */\n function Scanner (string) {\n this.string = string;\n this.tail = string;\n this.pos = 0;\n }\n\n /**\n * Returns `true` if the tail is empty (end of string).\n */\n Scanner.prototype.eos = function eos () {\n return this.tail === '';\n };\n\n /**\n * Tries to match the given regular expression at the current position.\n * Returns the matched text if it can match, the empty string otherwise.\n */\n Scanner.prototype.scan = function scan (re) {\n var match = this.tail.match(re);\n\n if (!match || match.index !== 0)\n return '';\n\n var string = match[0];\n\n this.tail = this.tail.substring(string.length);\n this.pos += string.length;\n\n return string;\n };\n\n /**\n * Skips all text until the given regular expression can be matched. Returns\n * the skipped string, which is the entire tail if no match can be made.\n */\n Scanner.prototype.scanUntil = function scanUntil (re) {\n var index = this.tail.search(re), match;\n\n switch (index) {\n case -1:\n match = this.tail;\n this.tail = '';\n break;\n case 0:\n match = '';\n break;\n default:\n match = this.tail.substring(0, index);\n this.tail = this.tail.substring(index);\n }\n\n this.pos += match.length;\n\n return match;\n };\n\n /**\n * Represents a rendering context by wrapping a view object and\n * maintaining a reference to the parent context.\n */\n function Context (view, parentContext) {\n this.view = view;\n this.cache = { '.': this.view };\n this.parent = parentContext;\n }\n\n /**\n * Creates a new context using the given view with this context\n * as the parent.\n */\n Context.prototype.push = function push (view) {\n return new Context(view, this);\n };\n\n /**\n * Returns the value of the given name in this context, traversing\n * up the context hierarchy if the value is absent in this context's view.\n */\n Context.prototype.lookup = function lookup (name) {\n var cache = this.cache;\n\n var value;\n if (cache.hasOwnProperty(name)) {\n value = cache[name];\n } else {\n var context = this, intermediateValue, names, index, lookupHit = false;\n\n while (context) {\n if (name.indexOf('.') > 0) {\n intermediateValue = context.view;\n names = name.split('.');\n index = 0;\n\n /**\n * Using the dot notion path in `name`, we descend through the\n * nested objects.\n *\n * To be certain that the lookup has been successful, we have to\n * check if the last object in the path actually has the property\n * we are looking for. We store the result in `lookupHit`.\n *\n * This is specially necessary for when the value has been set to\n * `undefined` and we want to avoid looking up parent contexts.\n *\n * In the case where dot notation is used, we consider the lookup\n * to be successful even if the last \"object\" in the path is\n * not actually an object but a primitive (e.g., a string, or an\n * integer), because it is sometimes useful to access a property\n * of an autoboxed primitive, such as the length of a string.\n **/\n while (intermediateValue != null && index < names.length) {\n if (index === names.length - 1)\n lookupHit = (\n hasProperty(intermediateValue, names[index])\n || primitiveHasOwnProperty(intermediateValue, names[index])\n );\n\n intermediateValue = intermediateValue[names[index++]];\n }\n } else {\n intermediateValue = context.view[name];\n\n /**\n * Only checking against `hasProperty`, which always returns `false` if\n * `context.view` is not an object. Deliberately omitting the check\n * against `primitiveHasOwnProperty` if dot notation is not used.\n *\n * Consider this example:\n * ```\n * Mustache.render(\"The length of a football field is {{#length}}{{length}}{{/length}}.\", {length: \"100 yards\"})\n * ```\n *\n * If we were to check also against `primitiveHasOwnProperty`, as we do\n * in the dot notation case, then render call would return:\n *\n * \"The length of a football field is 9.\"\n *\n * rather than the expected:\n *\n * \"The length of a football field is 100 yards.\"\n **/\n lookupHit = hasProperty(context.view, name);\n }\n\n if (lookupHit) {\n value = intermediateValue;\n break;\n }\n\n context = context.parent;\n }\n\n cache[name] = value;\n }\n\n if (isFunction(value))\n value = value.call(this.view);\n\n return value;\n };\n\n /**\n * A Writer knows how to take a stream of tokens and render them to a\n * string, given a context. It also maintains a cache of templates to\n * avoid the need to parse the same template twice.\n */\n function Writer () {\n this.templateCache = {\n _cache: {},\n set: function set (key, value) {\n this._cache[key] = value;\n },\n get: function get (key) {\n return this._cache[key];\n },\n clear: function clear () {\n this._cache = {};\n }\n };\n }\n\n /**\n * Clears all cached templates in this writer.\n */\n Writer.prototype.clearCache = function clearCache () {\n if (typeof this.templateCache !== 'undefined') {\n this.templateCache.clear();\n }\n };\n\n /**\n * Parses and caches the given `template` according to the given `tags` or\n * `mustache.tags` if `tags` is omitted, and returns the array of tokens\n * that is generated from the parse.\n */\n Writer.prototype.parse = function parse (template, tags) {\n var cache = this.templateCache;\n var cacheKey = template + ':' + (tags || mustache.tags).join(':');\n var isCacheEnabled = typeof cache !== 'undefined';\n var tokens = isCacheEnabled ? cache.get(cacheKey) : undefined;\n\n if (tokens == undefined) {\n tokens = parseTemplate(template, tags);\n isCacheEnabled && cache.set(cacheKey, tokens);\n }\n return tokens;\n };\n\n /**\n * High-level method that is used to render the given `template` with\n * the given `view`.\n *\n * The optional `partials` argument may be an object that contains the\n * names and templates of partials that are used in the template. It may\n * also be a function that is used to load partial templates on the fly\n * that takes a single argument: the name of the partial.\n *\n * If the optional `config` argument is given here, then it should be an\n * object with a `tags` attribute or an `escape` attribute or both.\n * If an array is passed, then it will be interpreted the same way as\n * a `tags` attribute on a `config` object.\n *\n * The `tags` attribute of a `config` object must be an array with two\n * string values: the opening and closing tags used in the template (e.g.\n * [ \"<%\", \"%>\" ]). The default is to mustache.tags.\n *\n * The `escape` attribute of a `config` object must be a function which\n * accepts a string as input and outputs a safely escaped string.\n * If an `escape` function is not provided, then an HTML-safe string\n * escaping function is used as the default.\n */\n Writer.prototype.render = function render (template, view, partials, config) {\n var tags = this.getConfigTags(config);\n var tokens = this.parse(template, tags);\n var context = (view instanceof Context) ? view : new Context(view, undefined);\n return this.renderTokens(tokens, context, partials, template, config);\n };\n\n /**\n * Low-level method that renders the given array of `tokens` using\n * the given `context` and `partials`.\n *\n * Note: The `originalTemplate` is only ever used to extract the portion\n * of the original template that was contained in a higher-order section.\n * If the template doesn't use higher-order sections, this argument may\n * be omitted.\n */\n Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate, config) {\n var buffer = '';\n\n var token, symbol, value;\n for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {\n value = undefined;\n token = tokens[i];\n symbol = token[0];\n\n if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate, config);\n else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate, config);\n else if (symbol === '>') value = this.renderPartial(token, context, partials, config);\n else if (symbol === '&') value = this.unescapedValue(token, context);\n else if (symbol === 'name') value = this.escapedValue(token, context, config);\n else if (symbol === 'text') value = this.rawValue(token);\n\n if (value !== undefined)\n buffer += value;\n }\n\n return buffer;\n };\n\n Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate, config) {\n var self = this;\n var buffer = '';\n var value = context.lookup(token[1]);\n\n // This function is used to render an arbitrary template\n // in the current context by higher-order sections.\n function subRender (template) {\n return self.render(template, context, partials, config);\n }\n\n if (!value) return;\n\n if (isArray(value)) {\n for (var j = 0, valueLength = value.length; j < valueLength; ++j) {\n buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate, config);\n }\n } else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') {\n buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate, config);\n } else if (isFunction(value)) {\n if (typeof originalTemplate !== 'string')\n throw new Error('Cannot use higher-order sections without the original template');\n\n // Extract the portion of the original template that the section contains.\n value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender);\n\n if (value != null)\n buffer += value;\n } else {\n buffer += this.renderTokens(token[4], context, partials, originalTemplate, config);\n }\n return buffer;\n };\n\n Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate, config) {\n var value = context.lookup(token[1]);\n\n // Use JavaScript's definition of falsy. Include empty arrays.\n // See https://github.com/janl/mustache.js/issues/186\n if (!value || (isArray(value) && value.length === 0))\n return this.renderTokens(token[4], context, partials, originalTemplate, config);\n };\n\n Writer.prototype.indentPartial = function indentPartial (partial, indentation, lineHasNonSpace) {\n var filteredIndentation = indentation.replace(/[^ \\t]/g, '');\n var partialByNl = partial.split('\\n');\n for (var i = 0; i < partialByNl.length; i++) {\n if (partialByNl[i].length && (i > 0 || !lineHasNonSpace)) {\n partialByNl[i] = filteredIndentation + partialByNl[i];\n }\n }\n return partialByNl.join('\\n');\n };\n\n Writer.prototype.renderPartial = function renderPartial (token, context, partials, config) {\n if (!partials) return;\n var tags = this.getConfigTags(config);\n\n var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];\n if (value != null) {\n var lineHasNonSpace = token[6];\n var tagIndex = token[5];\n var indentation = token[4];\n var indentedValue = value;\n if (tagIndex == 0 && indentation) {\n indentedValue = this.indentPartial(value, indentation, lineHasNonSpace);\n }\n var tokens = this.parse(indentedValue, tags);\n return this.renderTokens(tokens, context, partials, indentedValue, config);\n }\n };\n\n Writer.prototype.unescapedValue = function unescapedValue (token, context) {\n var value = context.lookup(token[1]);\n if (value != null)\n return value;\n };\n\n Writer.prototype.escapedValue = function escapedValue (token, context, config) {\n var escape = this.getConfigEscape(config) || mustache.escape;\n var value = context.lookup(token[1]);\n if (value != null)\n return (typeof value === 'number' && escape === mustache.escape) ? String(value) : escape(value);\n };\n\n Writer.prototype.rawValue = function rawValue (token) {\n return token[1];\n };\n\n Writer.prototype.getConfigTags = function getConfigTags (config) {\n if (isArray(config)) {\n return config;\n }\n else if (config && typeof config === 'object') {\n return config.tags;\n }\n else {\n return undefined;\n }\n };\n\n Writer.prototype.getConfigEscape = function getConfigEscape (config) {\n if (config && typeof config === 'object' && !isArray(config)) {\n return config.escape;\n }\n else {\n return undefined;\n }\n };\n\n var mustache = {\n name: 'mustache.js',\n version: '4.2.0',\n tags: [ '{{', '}}' ],\n clearCache: undefined,\n escape: undefined,\n parse: undefined,\n render: undefined,\n Scanner: undefined,\n Context: undefined,\n Writer: undefined,\n /**\n * Allows a user to override the default caching strategy, by providing an\n * object with set, get and clear methods. This can also be used to disable\n * the cache by setting it to the literal `undefined`.\n */\n set templateCache (cache) {\n defaultWriter.templateCache = cache;\n },\n /**\n * Gets the default or overridden caching object from the default writer.\n */\n get templateCache () {\n return defaultWriter.templateCache;\n }\n };\n\n // All high-level mustache.* functions use this writer.\n var defaultWriter = new Writer();\n\n /**\n * Clears all cached templates in the default writer.\n */\n mustache.clearCache = function clearCache () {\n return defaultWriter.clearCache();\n };\n\n /**\n * Parses and caches the given template in the default writer and returns the\n * array of tokens it contains. Doing this ahead of time avoids the need to\n * parse templates on the fly as they are rendered.\n */\n mustache.parse = function parse (template, tags) {\n return defaultWriter.parse(template, tags);\n };\n\n /**\n * Renders the `template` with the given `view`, `partials`, and `config`\n * using the default writer.\n */\n mustache.render = function render (template, view, partials, config) {\n if (typeof template !== 'string') {\n throw new TypeError('Invalid template! Template should be a \"string\" ' +\n 'but \"' + typeStr(template) + '\" was given as the first ' +\n 'argument for mustache#render(template, view, partials)');\n }\n\n return defaultWriter.render(template, view, partials, config);\n };\n\n // Export the escaping function so that the user may override it.\n // See https://github.com/janl/mustache.js/issues/244\n mustache.escape = escapeHtml;\n\n // Export these mainly for testing, but also for advanced usage.\n mustache.Scanner = Scanner;\n mustache.Context = Context;\n mustache.Writer = Writer;\n\n return mustache;\n\n})));\n","const Mustache = require('mustache');\nconst templates = require('./templates/templates.json');\nconst aliases = require('./templates/aliases.json');\nconst stateCodes = require('./templates/state-codes.json');\nconst countyCodes = require('./templates/county-codes.json');\nconst country2lang = require('./templates/country-to-lang.json');\nconst abbreviations = require('./templates/abbreviations.json');\nconst countryNames = require('./templates/country-names.json');\n\nconst knownComponents = aliases.map((a) => a.alias);\nconst VALID_REPLACEMENT_COMPONENTS = ['state'];\n\nconst determineCountryCode = (input, fallbackCountryCode = null) => {\n let countryCode = input.country_code && input.country_code.toUpperCase();\n if (!templates[countryCode] && fallbackCountryCode) {\n countryCode = fallbackCountryCode.toUpperCase();\n }\n if (!countryCode || countryCode.length !== 2) {\n // TODO change this to exceptions\n return input;\n }\n if (countryCode === 'UK') {\n countryCode = 'GB';\n }\n\n if (templates[countryCode] && templates[countryCode].use_country) {\n const oldCountryCode = countryCode;\n countryCode = templates[countryCode].use_country.toUpperCase();\n if (templates[oldCountryCode].change_country) {\n let newCountry = templates[oldCountryCode].change_country;\n const componentRegex = /\\$(\\w*)/;\n const componentMatch = componentRegex.exec(newCountry);\n if (componentMatch) {\n if (input[componentMatch[1]]) {\n newCountry = newCountry.replace(new RegExp(`\\\\$${componentMatch[1]}`), input[componentMatch[1]]);\n } else {\n newCountry = newCountry.replace(new RegExp(`\\\\$${componentMatch[1]}`), '');\n }\n }\n input.country = newCountry;\n }\n if (templates[oldCountryCode].add_component && templates[oldCountryCode].add_component.indexOf('=') > -1) {\n const splitted = templates[oldCountryCode].add_component.split('=');\n if (VALID_REPLACEMENT_COMPONENTS.indexOf(splitted[0]) > -1) {\n input[splitted[0]] = splitted[1];\n }\n }\n }\n \n if (countryCode === 'NL' && input.state) {\n if (input.state === 'Curaçao') {\n countryCode = 'CW';\n input.country = 'Curaçao';\n } else if (input.state.match(/sint maarten/i)) {\n countryCode = 'SX';\n input.country = 'Sint Maarten';\n } else if (input.state.match(/aruba/i)) {\n countryCode = 'AW';\n input.country = 'Aruba';\n }\n }\n\n // eslint-disable-next-line camelcase\n input.country_code = countryCode;\n return input;\n};\n\nconst normalizeComponentKeys = (input) => {\n const inputKeys = Object.keys(input);\n for (let i = 0; i < inputKeys.length; i++) {\n const snaked = inputKeys[i].replace(/([A-Z])/g, '_$1').toLowerCase();\n if (knownComponents.indexOf(snaked) > -1 && !input[snaked]) {\n if (input[inputKeys[i]]) {\n input[snaked] = input[inputKeys[i]];\n }\n delete input[inputKeys[i]];\n }\n }\n return input;\n};\n\nconst applyAliases = (input) => {\n const inputKeys = Object.keys(input);\n for (let i = 0; i < inputKeys.length; i++) {\n const alias = aliases.find((a) => a.alias === inputKeys[i]);\n if (alias && !input[alias.name]) {\n input[alias.name] = input[alias.alias];\n }\n }\n return input;\n};\n\nconst getStateCode = (state, countryCode) => {\n if (!stateCodes[countryCode]) {\n return;\n }\n // TODO what if state is actually the stateCode?\n // https://github.com/OpenCageData/perl-Geo-Address-Formatter/blob/master/lib/Geo/Address/Formatter.pm#L526\n const found = stateCodes[countryCode].find((e) => {\n if (typeof e.name == 'string' && e.name.toUpperCase() === state.toUpperCase()) {\n return e;\n }\n const variants = Object.values(e.name);\n const foundVariant = variants.find((e) => e.toUpperCase() === state.toUpperCase());\n if (foundVariant) {\n return {\n key: e.key,\n };\n }\n return false;\n });\n return found && found.key;\n};\n\nconst getCountyCode = (county, countryCode) => {\n if (!countyCodes[countryCode]) {\n return;\n }\n // TODO what if county is actually the countyCode?\n const found = countyCodes[countryCode].find((e) => {\n if (typeof e.name == 'string' && e.name.toUpperCase() === county.toUpperCase()) {\n return e;\n }\n const variants = Object.values(e.name);\n const foundVariant = variants.find((e) => e.toUpperCase() === county.toUpperCase());\n if (foundVariant) {\n return {\n key: e.key,\n };\n }\n return false;\n });\n return found && found.key;\n};\n\nconst cleanupInput = (input, replacements = [], options = {}) => {\n // If the country is a number, use the state as country\n let inputKeys = Object.keys(input);\n if (input.country && input.state && Number.isInteger(input.country)) {\n input.country = input.state;\n delete input.state;\n }\n if (replacements && replacements.length) {\n for (let i = 0; i < inputKeys.length; i++) {\n for (let j = 0; j < replacements.length; j++) {\n const componentRegex = new RegExp(`^${inputKeys[i]}=`);\n if (replacements[j][0].match(componentRegex)) {\n const val = replacements[j][0].replace(componentRegex, '');\n if (input[inputKeys[i]] === val) {\n input[inputKeys[i]] = replacements[j][1];\n }\n } else {\n input[inputKeys[i]] = `${input[inputKeys[i]]}`.replace(new RegExp(replacements[j][0]), replacements[j][1]);\n }\n }\n }\n }\n if (!input.state_code && input.state) {\n // eslint-disable-next-line camelcase\n input.state_code = getStateCode(input.state, input.country_code);\n if (input.state.match(/^washington,? d\\.?c\\.?/i)) {\n // eslint-disable-next-line camelcase\n input.state_code = 'DC';\n input.state = 'District of Columbia';\n input.city = 'Washington';\n }\n }\n if (!input.county_code && input.county) {\n // eslint-disable-next-line camelcase\n input.county_code = getCountyCode(input.county, input.country_code);\n }\n const unknownComponents = [];\n for (let i = 0; i < inputKeys.length; i++) {\n if (knownComponents.indexOf(inputKeys[i]) === -1) {\n unknownComponents.push(inputKeys[i]);\n }\n }\n if (unknownComponents.length) {\n input.attention = unknownComponents.map((c) => input[c]).join(', ');\n }\n\n if (input.postcode && options.cleanupPostcode !== false) {\n // convert to string\n input.postcode = `${input.postcode}`;\n const multiCodeRegex = /^(\\d{5}),\\d{5}/;\n const multiCodeMatch = multiCodeRegex.exec(input.postcode);\n if (input.postcode.length > 20) {\n delete input.postcode;\n // OSM may use postcode ranges\n } else if (input.postcode.match(/\\d+;\\d+/)) {\n delete input.postcode;\n } else if (multiCodeMatch) {\n input.postcode = multiCodeMatch[1];\n }\n }\n\n if (options.abbreviate && input.country_code && country2lang[input.country_code]) {\n for (let i = 0; i < country2lang[input.country_code].length; i++) {\n const lang = country2lang[input.country_code][i];\n if (abbreviations[lang]) {\n for (let j = 0; j < abbreviations[lang].length; j++) {\n if (input[abbreviations[lang][j].component]) {\n for (let k = 0; k < abbreviations[lang][j].replacements.length; k++) {\n input[abbreviations[lang][j].component] = input[abbreviations[lang][j].component].replace(\n new RegExp(`\\\\b${abbreviations[lang][j].replacements[k].src}\\\\b`),\n abbreviations[lang][j].replacements[k].dest,\n );\n }\n }\n }\n }\n }\n }\n \n // naive url cleanup, keys might have changed along the cleanup\n inputKeys = Object.keys(input);\n for (let i = 0; i < inputKeys.length; i++) {\n if (`${input[inputKeys[i]]}`.match(/^https?:\\/\\//i)) {\n delete input[inputKeys[i]];\n }\n }\n\n return input;\n};\n\nconst findTemplate = (input) => {\n return templates[input.country_code] ? templates[input.country_code] : templates.default;\n};\n\nconst chooseTemplateText = (template, input) => {\n let selected = template.address_template || templates.default.address_template;\n const threshold = 2;\n // Choose fallback only when none of these is present\n const required = ['road', 'postcode'];\n const missingValuesCnt = required\n .map((r) => !!input[r])\n .filter((s) => !s)\n .length;\n if (missingValuesCnt === threshold) {\n selected = template.fallback_template || templates.default.fallback_template;\n }\n return selected;\n};\n\nconst cleanupRender = (text) => {\n const replacements = [\n // eslint-disable-next-line no-useless-escape\n { s: /[\\},\\s]+$/u, d: '' },\n { s: /^[,\\s]+/u, d: '' },\n { s: /^- /u, d: '' }, // line starting with dash due to a parameter missing\n { s: /,\\s*,/u, d: ', ' }, // multiple commas to one\n { s: /[ \\t]+,[ \\t]+/u, d: ', ' }, // one horiz whitespace behind comma\n { s: /[ \\t][ \\t]+/u, d: ' ' }, // multiple horiz whitespace to one\n { s: /[ \\t]\\n/u, d: '\\n' }, // horiz whitespace, newline to newline\n { s: /\\n,/u, d: '\\n' }, // newline comma to just newline\n { s: /,,+/u, d: ',' }, // multiple commas to one\n { s: /,\\n/u, d: '\\n' }, // comma newline to just newline\n { s: /\\n[ \\t]+/u, d: '\\n' }, // newline plus space to newline\n { s: /\\n\\n+/u, d: '\\n' }, // multiple newline to one\n ];\n const dedupe = (inputChunks, glue, modifier = (s) => s) => {\n const seen = {};\n const result = [];\n for (let i = 0; i < inputChunks.length; i++) {\n const chunk = inputChunks[i].trim();\n // Special casing New York here, no dedupe for it\n if (chunk.toLowerCase() === 'new york') {\n seen[chunk] = 1;\n result.push(chunk);\n continue;\n }\n if (!seen[chunk]) {\n seen[chunk] = 1;\n result.push(modifier(chunk));\n }\n }\n return result.join(glue);\n };\n for (let i = 0; i < replacements.length; i++) {\n text = text.replace(replacements[i].s, replacements[i].d);\n text = dedupe(text.split('\\n'), '\\n', (s) => {\n return dedupe(s.split(', '), ', ');\n });\n }\n return text.trim();\n};\n\nconst renderTemplate = (template, input) => {\n const templateText = chooseTemplateText(template, input);\n const templateInput = Object.assign({}, input, {\n first: () => {\n return (text, render) => {\n const possibilities = render(text, input)\n .split(/\\s*\\|\\|\\s*/)\n .filter((b) => b.length > 0);\n return possibilities.length ? possibilities[0] : '';\n };\n },\n });\n\n let render = cleanupRender(Mustache.render(templateText, templateInput));\n if (template.postformat_replace) {\n for (let i = 0; i < template.postformat_replace.length; i++) {\n const replacement = template.postformat_replace[i];\n render = render.replace(new RegExp(replacement[0]), replacement[1]);\n }\n }\n render = cleanupRender(render);\n if (!render.trim().length) {\n render = cleanupRender(Object.keys(input)\n .map((i) => input[i])\n .filter((s) => !!s)\n .join(', '));\n }\n\n return render + '\\n';\n};\n\nmodule.exports = {\n format: (input, options = {\n countryCode: undefined,\n abbreviate: false,\n output: 'string',\n appendCountry: false,\n cleanupPostcode: true,\n }) => {\n let realInput = Object.assign({}, input);\n realInput = normalizeComponentKeys(realInput);\n if (options.countryCode) {\n // eslint-disable-next-line camelcase\n realInput.country_code = options.countryCode;\n }\n realInput = determineCountryCode(realInput, options.fallbackCountryCode);\n if (options.appendCountry && countryNames[realInput.country_code] && !realInput.country) {\n realInput.country = countryNames[realInput.country_code];\n }\n realInput = applyAliases(realInput);\n const template = findTemplate(realInput);\n realInput = cleanupInput(realInput, template.replace, options);\n const result = renderTemplate(template, realInput);\n if (options.output === 'array') {\n return result.split('\\n').filter((f) => !!f);\n }\n return result;\n },\n _determineCountryCode: determineCountryCode,\n _normalizeComponentKeys: normalizeComponentKeys,\n _applyAliases: applyAliases,\n _getStateCode: getStateCode,\n _getCountyCode: getCountyCode,\n _cleanupInput: cleanupInput,\n _findTemplate: findTemplate,\n _chooseTemplateText: chooseTemplateText,\n _cleanupRender: cleanupRender,\n _renderTemplate: renderTemplate,\n};\n"],"names":["module","objectToString","Object","prototype","toString","isArray","Array","object","call","isFunction","typeStr","obj","escapeRegExp","string","replace","hasProperty","propName","primitiveHasOwnProperty","primitive","hasOwnProperty","regExpTest","RegExp","test","testRegExp","re","nonSpaceRe","isWhitespace","entityMap","&","<",">","\"","'","/","`","=","escapeHtml","String","s","whiteRe","spaceRe","equalsRe","curlyRe","tagRe","parseTemplate","template","tags","openingTagRe","closingTagRe","closingCurlyRe","lineHasNonSpace","sections","tokens","spaces","hasTag","nonSpace","indentation","tagIndex","stripSpace","length","pop","compileTags","tagsToCompile","split","Error","mustache","start","type","value","chr","token","openSection","scanner","Scanner","eos","pos","scanUntil","i","valueLength","charAt","push","scan","nestTokens","squashTokens","lastToken","squashedTokens","numTokens","nestedTokens","collector","this","tail","Context","view","parentContext","cache",".","parent","Writer","templateCache","_cache","set","key","get","clear","match","index","substring","search","lookup","name","intermediateValue","names","context","lookupHit","indexOf","clearCache","parse","cacheKey","join","isCacheEnabled","undefined","render","partials","config","getConfigTags","renderTokens","originalTemplate","symbol","buffer","renderSection","renderInverted","renderPartial","unescapedValue","escapedValue","rawValue","self","subRender","j","slice","indentPartial","partial","filteredIndentation","partialByNl","indentedValue","escape","getConfigEscape","version","defaultWriter","TypeError","factory","knownComponents","aliases","map","a","alias","VALID_REPLACEMENT_COMPONENTS","determineCountryCode","input","fallbackCountryCode","countryCode","country_code","toUpperCase","templates","use_country","oldCountryCode","change_country","newCountry","componentRegex","componentMatch","exec","country","add_component","splitted","state","normalizeComponentKeys","inputKeys","keys","snaked","toLowerCase","applyAliases","find","getStateCode","stateCodes","found","e","values","getCountyCode","county","countyCodes","cleanupInput","replacements","options","Number","isInteger","val","state_code","city","county_code","unknownComponents","attention","c","postcode","cleanupPostcode","multiCodeRegex","multiCodeMatch","abbreviate","country2lang","lang","abbreviations","component","k","src","dest","findTemplate","default","chooseTemplateText","selected","address_template","r","filter","fallback_template","cleanupRender","text","d","dedupe","inputChunks","glue","modifier","seen","result","chunk","trim","renderTemplate","templateText","templateInput","assign","first","possibilities","b","Mustache","postformat_replace","replacement","format","output","appendCountry","realInput","countryNames","f","_determineCountryCode","_normalizeComponentKeys","_applyAliases","_getStateCode","_getCountyCode","_cleanupInput","_findTemplate","_chooseTemplateText","_cleanupRender","_renderTemplate"],"mappings":"2fACiEA;;;;;AAU/D,IAAIC,EAAiBC,OAAOC,UAAUC,SAClCC,EAAUC,MAAMD,SAAW,SAA0BE,GACvD,MAAuC,mBAAhCN,EAAeO,KAAKD,IAG7B,SAASE,EAAYF,GACnB,MAAyB,mBAAXA,EAOhB,SAASG,EAASC,GAChB,OAAON,EAAQM,GAAO,eAAiBA,EAGzC,SAASC,EAAcC,GACrB,OAAOA,EAAOC,QAAQ,8BAA+B,QAOvD,SAASC,EAAaJ,EAAKK,GACzB,OAAc,MAAPL,GAA8B,iBAARA,GAAqBK,KAAYL,EAOhE,SAASM,EAAyBC,EAAWF,GAC3C,OACe,MAAbE,GACwB,iBAAdA,GACPA,EAAUC,gBACVD,EAAUC,eAAeH,GAMhC,IAAII,EAAaC,OAAOlB,UAAUmB,KAClC,SAASC,EAAYC,EAAIX,GACvB,OAAOO,EAAWZ,KAAKgB,EAAIX,GAG7B,IAAIY,EAAa,KACjB,SAASC,EAAcb,GACrB,OAAQU,EAAWE,EAAYZ,GAGjC,IAA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