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C,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,CAAO,SAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import * as Globalize from 'globalize/dist/globalize';\nimport i18n from '../i18n';\n\n/**\n * @private\n * Normalize an array of formatter arguments into a discrete object with `locale`, `options`, `value` and\n * `unit` properties for use with the various Globalize.js formatter methods.\n *\n * @param args\n * An object with an optional locale, options, value, and/or unit.\n *\n * @return\n * The normalized object map.\n */\nfunction normalizeFormatterArguments<T, O>(args: DelegatorOptions<T> | FormatterDelegatorOptions<T, O>) {\n\tlet { locale, optionsOrLocale, unit, value } = args as FormatterDelegatorOptions<T, O>;\n\tlet options = optionsOrLocale;\n\n\tif (typeof optionsOrLocale === 'string') {\n\t\tlocale = optionsOrLocale;\n\t\toptions = undefined;\n\t}\n\n\treturn { locale, options, unit, value };\n}\n\nexport interface DelegatorOptions<O> {\n\tlocale?: string;\n\toptionsOrLocale?: O | string;\n}\n\nexport interface FormatterDelegatorOptions<T, O> extends DelegatorOptions<O> {\n\tunit?: string;\n\tvalue?: T;\n}\n\n/**\n * Return a Globalize.js object for the specified locale. If no locale is provided, then the root\n * locale is assumed.\n *\n * @param string\n * An optional locale for the Globalize.js object.\n *\n * @return\n * The localized Globalize.js object.\n */\nexport default function getGlobalize(locale?: string) {\n\treturn locale && locale !== i18n.locale ? new Globalize(locale) : Globalize;\n}\n\n/**\n * Call the specified Globalize.js method with the specified value, unit, and options, for the specified locale.\n *\n * @param method\n * The name of the static method on the `Globalize` object (required).\n *\n * @param args\n * An object containing any locale, options, value, or unit required by the underlying Globalize.js method.\n *\n * @return\n * The value returned by the underlying Globalize.js method.\n */\nexport function globalizeDelegator<O, R>(method: string, args: DelegatorOptions<O>): R;\nexport function globalizeDelegator<T, O, R>(method: string, args: FormatterDelegatorOptions<T, O>): R;\nexport function globalizeDelegator<T, O, R>(\n\tmethod: string,\n\targs: DelegatorOptions<O> | FormatterDelegatorOptions<T, O>\n): R {\n\tconst { locale, options, value, unit } = normalizeFormatterArguments<T, O>(args);\n\tconst methodArgs: any[] = typeof value !== 'undefined' ? [value] : [];\n\n\tif (typeof unit !== 'undefined') {\n\t\tmethodArgs.push(unit);\n\t}\n\n\tif (typeof options !== 'undefined') {\n\t\tmethodArgs.push(options);\n\t}\n\n\tconst globalize = getGlobalize(locale);\n\treturn (<any>globalize)[method].apply(globalize, methodArgs);\n}\n"]}