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I,IAAM,KAAM,EAAI,EAAM,EAC5C,IAQF,MAAM,aAAe,IAAI,SAAS,GAAI,CACpC,QAAS,WACP,MAAO,CAAC,CACV,IAGF,MAAM,MAAQ,MACd,MAAM,eAAiB,eACvB,MAAM,SAAW,SACjB,MAAM,KAAO,KACb,MAAM,kBAAoB,UAG1B,MAAM,mBAAmB,MAAM,cAC/B,UAAU,IAAI,MAAM,aAEpB,MAAM,SAAS,KAAM,CACnB,WAAY,CACV,UAAW,IACX,QAAS,KAEX,cAAe,CACb,SAAU,IACV,QAAS,IACT,QAAS,IACT,SAAU,KAEZ,QAAS,SAAS,GAChB,IAAI,EAAI,EAAS,GACjB,OAAkC,MAAvB,EAAS,IAAM,IAAa,KAC9B,IAAN,EAAW,KACH,IAAN,EAAW,KACH,IAAN,EAAW,KAAO,IAC3B,EACA,SAAU,CACR,OAAQ,OAIZ,OAAO,QAAU","file":"/npm/numbr@0.0.6/numbr.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/numbr@0.0.6/numbr.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\r\n\r\nvar\r\n  _ = require('lodash'),\r\n  consumers = require('./lib/consumers'),\r\n  Consumer = consumers.Consumer,\r\n  Step = consumers.Step;\r\n\r\nvar\r\n  autoId = 0,\r\n  zeroFormat,\r\n  defaultFormat = '0.0',\r\n  fmtConsumers = {},\r\n  defaultConsumers,\r\n  compileFn = compileWithCache,\r\n  formatCache = {},\r\n  languages = {},\r\n  globalLang = 'en';\r\n\r\n/**\r\n * A wrapper for numeral-like formatting.\r\n * Stores the given value for further formatting.\r\n *\r\n * @param {number} value\r\n * @param {string} [lang]\r\n * @constructor\r\n */\r\nfunction Numbr(value, lang){\r\n  this.num = value;\r\n  this.lang = (lang || '').toLowerCase();\r\n}\r\n\r\n/**\r\n * Formats the wrapped value according to fmt.\r\n * By default, the format is compiled into a series of transformations and then cached globally, if you'd like to\r\n * disable the caching feature, use {@link numbr.cacheEnabled}.\r\n * @param {string} [fmt=defaultFormat]\r\n * @param {function} [roundFn=Math.round]\r\n * @returns {string} the formatted number\r\n */\r\nNumbr.prototype.format = function(fmt, roundFn){\r\n  return compileFn(fmt || defaultFormat).run(this.num, roundFn, this.lang);\r\n};\r\n\r\n/**\r\n * Sets the language for this Numbr.\r\n * The provided language must be already loaded via {@link numbr.loadLang}.\r\n * @param lang the language code\r\n */\r\nNumbr.prototype.setLang = function(lang){\r\n  this.lang = lang;\r\n};\r\n\r\n/**\r\n * @returns {number}\r\n */\r\nNumbr.prototype.valueOf = function(){\r\n  return this.num;\r\n};\r\n\r\n/**\r\n * Access to the wrapped value\r\n * @returns {number}\r\n */\r\nNumbr.prototype.value = function(){\r\n  return this.num;\r\n};\r\n\r\n/**\r\n * Sets the wrapped value\r\n * @param {number} num\r\n */\r\nNumbr.prototype.set = function(num){\r\n  this.num = num;\r\n};\r\n\r\n/**\r\n * Returns a new Numbr object with the same value and language as this Numbr.\r\n * @returns {Numbr}\r\n */\r\nNumbr.prototype.clone = function(){\r\n  return new Numbr(this.num, this.lang);\r\n};\r\n\r\n/**\r\n * Returns a compiled format from the cache or compiles one on the fly.\r\n * @private\r\n * @param {string} fmt\r\n * @returns {CompiledFormat}\r\n */\r\nfunction compileWithCache(fmt){\r\n  var compiled = formatCache[fmt];\r\n  if(!compiled){\r\n    compiled = formatCache[fmt] = compileFormat(fmt);\r\n  }\r\n  return compiled;\r\n}\r\n\r\n/**\r\n * Compiles the format string.\r\n * @private\r\n * @param fmt\r\n * @returns {CompiledFormat}\r\n */\r\nfunction compileFormat(fmt){\r\n  var\r\n    state = new ConsumerState(),\r\n    steps = [],\r\n    opts = {},\r\n    pos = {};\r\n\r\n  opts.pos = pos;\r\n\r\n  for(var i = 0, len = fmt.length; i < len; ++i){\r\n    var\r\n      char = fmt[i],\r\n      consumers = fmtConsumers[char] || defaultConsumers,\r\n      res = consumeInput(consumers, state, fmt, i) || consumeInput(defaultConsumers, state, fmt, i);\r\n\r\n    if(res.consumed){\r\n      i += res.consumed;\r\n    }\r\n\r\n    if(res.step){\r\n      // Cache this step position following a natural order, so that the final output corresponds\r\n      // to the input string and not the internal weight order\r\n      pos[res.step.consumerId] = steps.push(res) - 1;\r\n\r\n      if(res.opts){\r\n        _.extend(opts, res.opts);\r\n      }\r\n    }\r\n  }\r\n\r\n  steps = _(steps)\r\n    .sortBy('weight')\r\n    .pluck('step')\r\n    .value();\r\n\r\n  var sortedPos = new Array(steps.length);\r\n\r\n  for(i = 0, len = steps.length; i < len; ++i){\r\n    sortedPos[i] = pos[steps[i].consumerId];\r\n  }\r\n\r\n  return new CompiledFormat(steps, opts, sortedPos);\r\n}\r\n\r\n/**\r\n * Finds an appropriate consumer object to swallow the current input cursor.\r\n *\r\n * @private\r\n * @param {Consumer[]} consumers An array of consumers\r\n * @param {ConsumerState} state A consumer state object\r\n * @param {string} fmt The format string\r\n * @param {number} pos The format string cursor\r\n * @returns {Step|null} Returns an appropriate step definition given by one of the consumers on the\r\n * supplied array, if any\r\n */\r\nfunction consumeInput(consumers, state, fmt, pos){\r\n  for(var i = 0, len = consumers.length; i < len; ++i){\r\n    var\r\n      consumer = consumers[i],\r\n      res = consumer.consume(state, fmt, pos);\r\n\r\n    if(res){\r\n      state.incConsumed(consumer.Id);\r\n      return res;\r\n    }\r\n  }\r\n}\r\n\r\n/**\r\n * Simple counter for used consumers during a compile operation.\r\n * This can be used by individual consumers to check for other consumers' state.\r\n * @private\r\n * @constructor\r\n */\r\nfunction ConsumerState(){\r\n  this.ranConsumers = {};\r\n}\r\n\r\n/**\r\n * Returns whether the given consumer id has been used previously during the compile operation.\r\n * @param id The consumer Id\r\n * @returns {boolean}\r\n */\r\nConsumerState.prototype.isConsumed = function(id){\r\n  return !!this.ranConsumers[id];\r\n};\r\n\r\n/**\r\n * Increments the usage count of the given consumer id\r\n * @param id The consumer Id\r\n */\r\nConsumerState.prototype.incConsumed = function(id){\r\n  if(this.ranConsumers[id]){\r\n    ++this.ranConsumers[id];\r\n  } else {\r\n    this.ranConsumers[id] = 1;\r\n  }\r\n};\r\n\r\n/**\r\n * Returns the total usage count for the given consumer id\r\n * @param id The consumer Id\r\n * @returns {number}\r\n */\r\nConsumerState.prototype.timesConsumed = function(id){\r\n  return this.ranConsumers[id] || 0;\r\n};\r\n\r\n/**\r\n * A wrapper object for compiled formats.\r\n * Objects of this class should not be created directly. Use {@link numbr.compile} instead.\r\n *\r\n * @param {Step[]} steps An array of step functions to be called during {@link CompiledFormat#run}\r\n * @param {object} opts A options object that will be passed to every step function as part of the run state\r\n * @param {number[]} sortedPos An array of output position indexes of each step in steps\r\n * @constructor\r\n */\r\nfunction CompiledFormat(steps, opts, sortedPos){\r\n  this.steps = steps;\r\n  this.opts = opts;\r\n  this.pos = opts.pos;\r\n  this.sortedPos = sortedPos;\r\n}\r\n\r\n/**\r\n * Runs all the transformation step functions using the given number and rounding function.\r\n *\r\n * @param num The number to format\r\n * @param {function} roundFn A rounding function\r\n * @param {string} lang The language code\r\n * @returns {string} the formatted number\r\n */\r\nCompiledFormat.prototype.run = function(num, roundFn, lang){\r\n  if(num === 0 && zeroFormat){\r\n    return zeroFormat;\r\n  }\r\n\r\n  var\r\n    len = this.steps.length,\r\n    i = 0,\r\n    state = {\r\n      num: num,\r\n      signPos: -1,\r\n      right: num % 1,\r\n      rightStr: '',\r\n      optionalDot: false,\r\n      roundFn : roundFn || Math.round,\r\n      lang: languages[lang || globalLang],\r\n      opts: this.opts,\r\n      pos: this.pos\r\n    },\r\n    output = new Array(len);\r\n\r\n  for(; i < len; ++i){\r\n    this.steps[i](state, output, this.sortedPos[i]);\r\n  }\r\n\r\n  return output.join('');\r\n};\r\n\r\n/**\r\n * Function wrapper for creating new Numbr instances, it also has useful static methods to\r\n * control the global module behaviour.\r\n *\r\n * All classes can be accessed via numbr.ClassName, e.g. numbr.Numbr, numbr.CompiledFormat, etc.\r\n * @namespace\r\n * @param {number} value\r\n * @param {string} [lang]\r\n * @returns {Numbr}\r\n */\r\nfunction numbr(value, lang){\r\n  return new Numbr(value, lang);\r\n}\r\n\r\n/**\r\n * Compiles the given string into a {@link CompiledFormat} object ready to be used.\r\n * @param {string} fmt\r\n * @returns {CompiledFormat}\r\n */\r\nnumbr.compile = function(fmt){\r\n  return compileFn(fmt);\r\n};\r\n\r\n/**\r\n * Sets the global zero format.\r\n * If defined, the zero format is used as the outout of {@link Numbr#format} whenever the wrapped value === 0.\r\n * @param fmt\r\n */\r\nnumbr.zeroFormat = function(fmt){\r\n  zeroFormat = _.isString(fmt)? fmt : null;\r\n};\r\n\r\n/**\r\n * Sets the default format.\r\n * The default format is used if {@link Numbr#format} is called without arguments. By default, the format is '0.0'.\r\n * @param {string} fmt\r\n */\r\nnumbr.defaultFormat = function(fmt){\r\n  defaultFormat = _.isString(fmt)? fmt : '0.0';\r\n};\r\n\r\n/**\r\n * Stores the given language definition with the code langCode.\r\n * @param {string} langCode\r\n * @param {object} langDef\r\n */\r\nnumbr.loadLang = function(langCode, langDef){\r\n  languages[langCode.toLowerCase()] = langDef;\r\n};\r\n\r\n/**\r\n * Access the global language code.\r\n * @returns {string}\r\n */\r\nnumbr.getGlobalLang = function(){\r\n  return globalLang;\r\n};\r\n\r\n/**\r\n * Sets the global language.\r\n * @param langCode\r\n */\r\nnumbr.setGlobalLang = function(langCode){\r\n  langCode = langCode.toLowerCase();\r\n\r\n  if(!languages[langCode]){\r\n    throw new Error('Unknown language : ' + langCode);\r\n  }\r\n\r\n  globalLang = langCode;\r\n};\r\n\r\n/**\r\n * Gets the global language, sets the global language or loads a language.\r\n * If called with no arguments, returns the global language.\r\n * If called with just the language code, it sets the global language.\r\n * If called with both arguments, the language is just loaded.\r\n *\r\n * @param {string} [langCode] The language code\r\n * @param {object} [langDef] A valid language definition\r\n */\r\nnumbr.language = function(langCode, langDef) {\r\n  if(!langCode) {\r\n    return globalLang;\r\n  }\r\n\r\n  if(langDef){\r\n    numbr.loadLang(langCode, langDef);\r\n  } else {\r\n    numbr.setGlobalLang(langCode);\r\n  }\r\n};\r\n\r\n/**\r\n * Enables or disables the format cache.\r\n * By default every format is compiled into a series of transformation functions that are cached and reused every\r\n * time {@link Numbr#format} is called.\r\n *\r\n * Disabling the cache may cause a significant performance hit and it is not recommended. Most applications will\r\n * probably use just a handful of formats, so the memory overhead is non-existent.\r\n *\r\n * @param {boolean} enabled Whether to enable or disable the cache\r\n */\r\nnumbr.cacheEnabled = function(enabled){\r\n  compileFn = enabled? compileWithCache : compileFormat;\r\n};\r\n\r\n/**\r\n * Sets the default consumer.\r\n * The default consumer is used when no other consumer is able to consume a slice of the input format string.\r\n * By default, this is {@link numbr.echoConsumer}.\r\n * @param {Consumer} consumer\r\n */\r\nnumbr.setDefaultConsumer = function(consumer){\r\n  consumer.Id = ++autoId;\r\n  defaultConsumers = [consumer];\r\n};\r\n\r\n/**\r\n * Adds a consumer to the list of global consumers.\r\n * Consumers are used to translate the string format input into actual transforming steps.\r\n * @param {Consumer} consumer\r\n */\r\nnumbr.addConsumer = function(consumer){\r\n  consumer.setId(++autoId);\r\n\r\n  consumer.token.split('').forEach(function(char){\r\n    var consumerArr = fmtConsumers[char] || [];\r\n    consumerArr.push(consumer);\r\n    fmtConsumers[char] = _.sortBy(consumerArr, 'priority');\r\n  });\r\n};\r\n\r\n/**\r\n * A simple consumer that echoes back as many characters as possible in one step.\r\n * This is the default consumer.\r\n * @type {Consumer}\r\n */\r\nnumbr.echoConsumer = new Consumer('', {\r\n  consume: function(state, input, pos){\r\n    for(var i = pos+1, len = input.length; i < len; ++i){\r\n      if(fmtConsumers[input[i]]){\r\n        break;\r\n      }\r\n    }\r\n\r\n    var\r\n      str = input.substring(pos, i),\r\n      fn = function(state, output, pos){\r\n        output[pos] = str;\r\n      };\r\n\r\n    fn.consumerId = ++autoId;\r\n\r\n    return new Step(fn, 2000, null, i - pos - 1);\r\n  }\r\n});\r\n\r\n/**\r\n * A simple consumer that consumes the single character is given and does nothing else.\r\n * You can set this consumer as the default by using {@link numbr.setDefaultConsumer}\r\n * @type {Consumer}\r\n */\r\nnumbr.noopConsumer = new Consumer('', {\r\n  consume: function(){\r\n    return {};\r\n  }\r\n});\r\n\r\nnumbr.Numbr = Numbr;\r\nnumbr.CompiledFormat = CompiledFormat;\r\nnumbr.Consumer = Consumer;\r\nnumbr.Step = Step;\r\nnumbr.standardConsumers = consumers;\r\n\r\n// Initializes the default and standard consumers\r\nnumbr.setDefaultConsumer(numbr.echoConsumer);\r\nconsumers.map(numbr.addConsumer);\r\n\r\nnumbr.loadLang('en', {\r\n  delimiters: {\r\n    thousands: ',',\r\n    decimal: '.'\r\n  },\r\n  abbreviations: {\r\n    thousand: 'k',\r\n    million: 'm',\r\n    billion: 'b',\r\n    trillion: 't'\r\n  },\r\n  ordinal: function(number) {\r\n    var b = number % 10;\r\n    return (~~(number % 100 / 10) === 1) ? 'th' :\r\n      (b === 1) ? 'st' :\r\n        (b === 2) ? 'nd' :\r\n          (b === 3) ? 'rd' : 'th';\r\n  },\r\n  currency: {\r\n    symbol: '$'\r\n  }\r\n});\r\n\r\nmodule.exports = numbr;"]}