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KAFrB,EAAc,EADd,EAAa,EAAc,KAMN,aAAf,GAA8B,EAAgB,eAGxB,SAAf,GAAsD,MAA7B,EAAgB,SACpD,EAAgB,GAAc,IAE9B,EAAgB,IAAc,EAL9B,EAAgB,GAAc,SASzB,GAAoB,aAAf,EAA4B,CACvC,KAAK,GAAe,GAAK,EAAc,GAGtC,MAAM,IAAI,MAAM,GAFhB,EAAgB,GAAc,CAMhC,MAAO,GAAoB,YAAf,GAA2C,YAAf,GAA2C,SAAf,GAAwC,SAAf,EAAwB,CACpH,GAA4B,mBAAhB,EAGX,MAAM,IAAI,MAAM,GAFhB,EAAgB,GAAc,CAMhC,KAAO,CAEN,GAA4B,iBAAhB,EAGX,MAAM,IAAI,MAAM,GAFhB,EAAgB,GAAc,CAIhC,CASD,OAJA,EAAgB,EAAiB,OAAQ,YACzC,EAAgB,EAAiB,SAAU,YAC3C,EAAgB,EAAiB,SAAU,kBAEpC,CACR,CA4BW,CAAS,GAGnB,KAAK,GAAK,SAAW,GACpB,OAAO,EAAQ,EAAS,EAAU,EACnC,EAGA,KAAK,KAAO,SAAW,GACtB,OAAO,EAAQ,EAAS,EAAY,EACrC,EACD,CAKD,CA9UA","file":"/gh/leongersen/wnumb@1.0.2/wNumb.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /gh/leongersen/wnumb@1.0.2/wNumb.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","(function(){\n\n\t'use strict';\n\nvar\n/** @const */ FormatOptions = [\n\t'decimals',\n\t'thousand',\n\t'mark',\n\t'prefix',\n\t'postfix',\n\t'encoder',\n\t'decoder',\n\t'negativeBefore',\n\t'negative',\n\t'edit',\n\t'undo'\n];\n\n// General\n\n\t// Reverse a string\n\tfunction strReverse ( a ) {\n\t\treturn a.split('').reverse().join('');\n\t}\n\n\t// Check if a string starts with a specified prefix.\n\tfunction strStartsWith ( input, match ) {\n\t\treturn input.substring(0, match.length) === match;\n\t}\n\n\t// Check is a string ends in a specified postfix.\n\tfunction strEndsWith ( input, match ) {\n\t\treturn input.slice(-1 * match.length) === match;\n\t}\n\n\t// Throw an error if formatting options are incompatible.\n\tfunction throwEqualError( F, a, b ) {\n\t\tif ( (F[a] || F[b]) && (F[a] === F[b]) ) {\n\t\t\tthrow new Error(a);\n\t\t}\n\t}\n\n\t// Check if a number is finite and not NaN\n\tfunction isValidNumber ( input ) {\n\t\treturn typeof input === 'number' && isFinite( input );\n\t}\n\n\t// Provide rounding-accurate toFixed method.\n\tfunction toFixed ( value, decimals ) {\n\t\tvar scale = Math.pow(10, decimals);\n\t\treturn ( Math.round(value * scale) / scale).toFixed( decimals );\n\t}\n\n\n// Formatting\n\n\t// Accept a number as input, output formatted string.\n\tfunction formatTo ( decimals, thousand, mark, prefix, postfix, encoder, decoder, negativeBefore, negative, edit, undo, input ) {\n\n\t\tvar originalInput = input, inputIsNegative, inputPieces, inputBase, inputDecimals = '', output = '';\n\n\t\t// Apply user encoder to the input.\n\t\t// Expected outcome: number.\n\t\tif ( encoder ) {\n\t\t\tinput = encoder(input);\n\t\t}\n\n\t\t// Stop if no valid number was provided, the number is infinite or NaN.\n\t\tif ( !isValidNumber(input) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Rounding away decimals might cause a value of -0\n\t\t// when using very small ranges. Remove those cases.\n\t\tif ( decimals !== false && parseFloat(input.toFixed(decimals)) === 0 ) {\n\t\t\tinput = 0;\n\t\t}\n\n\t\t// Formatting is done on absolute numbers,\n\t\t// decorated by an optional negative symbol.\n\t\tif ( input < 0 ) {\n\t\t\tinputIsNegative = true;\n\t\t\tinput = Math.abs(input);\n\t\t}\n\n\t\t// Reduce the number of decimals to the specified option.\n\t\tif ( decimals !== false ) {\n\t\t\tinput = toFixed( input, decimals );\n\t\t}\n\n\t\t// Transform the number into a string, so it can be split.\n\t\tinput = input.toString();\n\n\t\t// Break the number on the decimal separator.\n\t\tif ( input.indexOf('.') !== -1 ) {\n\t\t\tinputPieces = input.split('.');\n\n\t\t\tinputBase = inputPieces[0];\n\n\t\t\tif ( mark ) {\n\t\t\t\tinputDecimals = mark + inputPieces[1];\n\t\t\t}\n\n\t\t} else {\n\n\t\t// If it isn't split, the entire number will do.\n\t\t\tinputBase = input;\n\t\t}\n\n\t\t// Group numbers in sets of three.\n\t\tif ( thousand ) {\n\t\t\tinputBase = strReverse(inputBase).match(/.{1,3}/g);\n\t\t\tinputBase = strReverse(inputBase.join( strReverse( thousand ) ));\n\t\t}\n\n\t\t// If the number is negative, prefix with negation symbol.\n\t\tif ( inputIsNegative && negativeBefore ) {\n\t\t\toutput += negativeBefore;\n\t\t}\n\n\t\t// Prefix the number\n\t\tif ( prefix ) {\n\t\t\toutput += prefix;\n\t\t}\n\n\t\t// Normal negative option comes after the prefix. Defaults to '-'.\n\t\tif ( inputIsNegative && negative ) {\n\t\t\toutput += negative;\n\t\t}\n\n\t\t// Append the actual number.\n\t\toutput += inputBase;\n\t\toutput += inputDecimals;\n\n\t\t// Apply the postfix.\n\t\tif ( postfix ) {\n\t\t\toutput += postfix;\n\t\t}\n\n\t\t// Run the output through a user-specified post-formatter.\n\t\tif ( edit ) {\n\t\t\toutput = edit ( output, originalInput );\n\t\t}\n\n\t\t// All done.\n\t\treturn output;\n\t}\n\n\t// Accept a sting as input, output decoded number.\n\tfunction formatFrom ( decimals, thousand, mark, prefix, postfix, encoder, decoder, negativeBefore, negative, edit, undo, input ) {\n\n\t\tvar originalInput = input, inputIsNegative, output = '';\n\n\t\t// User defined pre-decoder. Result must be a non empty string.\n\t\tif ( undo ) {\n\t\t\tinput = undo(input);\n\t\t}\n\n\t\t// Test the input. Can't be empty.\n\t\tif ( !input || typeof input !== 'string' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// If the string starts with the negativeBefore value: remove it.\n\t\t// Remember is was there, the number is negative.\n\t\tif ( negativeBefore && strStartsWith(input, negativeBefore) ) {\n\t\t\tinput = input.replace(negativeBefore, '');\n\t\t\tinputIsNegative = true;\n\t\t}\n\n\t\t// Repeat the same procedure for the prefix.\n\t\tif ( prefix && strStartsWith(input, prefix) ) {\n\t\t\tinput = input.replace(prefix, '');\n\t\t}\n\n\t\t// And again for negative.\n\t\tif ( negative && strStartsWith(input, negative) ) {\n\t\t\tinput = input.replace(negative, '');\n\t\t\tinputIsNegative = true;\n\t\t}\n\n\t\t// Remove the postfix.\n\t\t// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice\n\t\tif ( postfix && strEndsWith(input, postfix) ) {\n\t\t\tinput = input.slice(0, -1 * postfix.length);\n\t\t}\n\n\t\t// Remove the thousand grouping.\n\t\tif ( thousand ) {\n\t\t\tinput = input.split(thousand).join('');\n\t\t}\n\n\t\t// Set the decimal separator back to period.\n\t\tif ( mark ) {\n\t\t\tinput = input.replace(mark, '.');\n\t\t}\n\n\t\t// Prepend the negative symbol.\n\t\tif ( inputIsNegative ) {\n\t\t\toutput += '-';\n\t\t}\n\n\t\t// Add the number\n\t\toutput += input;\n\n\t\t// Trim all non-numeric characters (allow '.' and '-');\n\t\toutput = output.replace(/[^0-9\\.\\-.]/g, '');\n\n\t\t// The value contains no parse-able number.\n\t\tif ( output === '' ) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Covert to number.\n\t\toutput = Number(output);\n\n\t\t// Run the user-specified post-decoder.\n\t\tif ( decoder ) {\n\t\t\toutput = decoder(output);\n\t\t}\n\n\t\t// Check is the output is valid, otherwise: return false.\n\t\tif ( !isValidNumber(output) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\n// Framework\n\n\t// Validate formatting options\n\tfunction validate ( inputOptions ) {\n\n\t\tvar i, optionName, optionValue,\n\t\t\tfilteredOptions = {};\n\n\t\tfor ( i = 0; i < FormatOptions.length; i+=1 ) {\n\n\t\t\toptionName = FormatOptions[i];\n\t\t\toptionValue = inputOptions[optionName];\n\n\t\t\tif ( optionValue === undefined ) {\n\n\t\t\t\t// Only default if negativeBefore isn't set.\n\t\t\t\tif ( optionName === 'negative' && !filteredOptions.negativeBefore ) {\n\t\t\t\t\tfilteredOptions[optionName] = '-';\n\t\t\t\t// Don't set a default for mark when 'thousand' is set.\n\t\t\t\t} else if ( optionName === 'mark' && filteredOptions.thousand !== '.' ) {\n\t\t\t\t\tfilteredOptions[optionName] = '.';\n\t\t\t\t} else {\n\t\t\t\t\tfilteredOptions[optionName] = false;\n\t\t\t\t}\n\n\t\t\t// Floating points in JS are stable up to 7 decimals.\n\t\t\t} else if ( optionName === 'decimals' ) {\n\t\t\t\tif ( optionValue >= 0 && optionValue < 8 ) {\n\t\t\t\t\tfilteredOptions[optionName] = optionValue;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(optionName);\n\t\t\t\t}\n\n\t\t\t// These options, when provided, must be functions.\n\t\t\t} else if ( optionName === 'encoder' || optionName === 'decoder' || optionName === 'edit' || optionName === 'undo' ) {\n\t\t\t\tif ( typeof optionValue === 'function' ) {\n\t\t\t\t\tfilteredOptions[optionName] = optionValue;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(optionName);\n\t\t\t\t}\n\n\t\t\t// Other options are strings.\n\t\t\t} else {\n\n\t\t\t\tif ( typeof optionValue === 'string' ) {\n\t\t\t\t\tfilteredOptions[optionName] = optionValue;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(optionName);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Some values can't be extracted from a\n\t\t// string if certain combinations are present.\n\t\tthrowEqualError(filteredOptions, 'mark', 'thousand');\n\t\tthrowEqualError(filteredOptions, 'prefix', 'negative');\n\t\tthrowEqualError(filteredOptions, 'prefix', 'negativeBefore');\n\n\t\treturn filteredOptions;\n\t}\n\n\t// Pass all options as function arguments\n\tfunction passAll ( options, method, input ) {\n\t\tvar i, args = [];\n\n\t\t// Add all options in order of FormatOptions\n\t\tfor ( i = 0; i < FormatOptions.length; i+=1 ) {\n\t\t\targs.push(options[FormatOptions[i]]);\n\t\t}\n\n\t\t// Append the input, then call the method, presenting all\n\t\t// options as arguments.\n\t\targs.push(input);\n\t\treturn method.apply('', args);\n\t}\n\n\t/** @constructor */\n\tfunction wNumb ( options ) {\n\n\t\tif ( !(this instanceof wNumb) ) {\n\t\t\treturn new wNumb ( options );\n\t\t}\n\n\t\tif ( typeof options !== \"object\" ) {\n\t\t\treturn;\n\t\t}\n\n\t\toptions = validate(options);\n\n\t\t// Call 'formatTo' with proper arguments.\n\t\tthis.to = function ( input ) {\n\t\t\treturn passAll(options, formatTo, input);\n\t\t};\n\n\t\t// Call 'formatFrom' with proper arguments.\n\t\tthis.from = function ( input ) {\n\t\t\treturn passAll(options, formatFrom, input);\n\t\t};\n\t}\n\n\t/** @export */\n\twindow.wNumb = wNumb;\n\n}());\n"]}