Comparing version 0.3.0 to 0.4.0
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.FPMoney=e():t.FPMoney=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=3)}([function(t,e,n){"use strict";function r(t,e){void 0===e&&(e=2);for(var n=t.toString(),r="1",o=0;o<e;o++)r+="0";var i=parseInt(r,10),s=(parseFloat(n)*i).toString();return parseInt(s,10).toString()}e.__esModule=!0,e.currencies={USD:{symbol:"$",fraction:2},EUR:{symbol:"€",fraction:2},GBP:{symbol:"£",fraction:2},INR:{symbol:"₹",fraction:2},CRC:{symbol:"₡",fraction:2},VND:{symbol:"₫",fraction:0},HUF:{symbol:"Ft",fraction:2},ILS:{symbol:"₪",fraction:2},CNY:{symbol:"¥",fraction:2},KRW:{symbol:"₩",fraction:0},NGN:{symbol:"₦",fraction:2},PYG:{symbol:"₲",fraction:0},PHP:{symbol:"₱",fraction:2},PLN:{symbol:"zł",fraction:2},THB:{symbol:"฿",fraction:2},UAH:{symbol:"₴",fraction:2},JPY:{symbol:"¥",fraction:0}},e.lowestCommonToFormat=function(t,e){void 0===e&&(e=2),t=t.toString();for(var n="1",r=0;r<e;r++)n+="0";var o=parseInt(n,10);return-1!==t.indexOf(".")&&(t=(parseFloat(t)*o).toString()),0===e?parseInt(t,10).toString():(parseInt(t,10)/o).toFixed(e)},e.formatToLowestCommon=r;var o=function(){function t(t){var n;this.value="",this.display="",this.format="",this.currency="USD",this.locale=this.getLocale(),this.showSelection=!0,this.validate(t),n="string"==typeof t.container?document.querySelector(t.container):t.container,this.container=n,t.currency&&(this.currency=t.currency.toUpperCase()),t.locale&&(this.locale=t.locale),t.value&&(this.value=r(t.value,e.currencies[this.currency].fraction)),void 0!==t.showSelection&&(this.showSelection=t.showSelection),this.onChange=t.onChange?this.onChange=t.onChange:function(){},this.currencyDiv=document.createElement("div"),this.input=document.createElement("input"),this.select=document.createElement("select"),this.render(),this.setCurrency(this.currency)}return t.prototype.setCurrency=function(t){t=t.toUpperCase(),this.currency=t,this.currencyDiv.innerHTML=e.currencies[t].symbol;for(var n=e.currencies[t].fraction,r="",o=0;o<n;o++)r+="0";this.input.placeholder="0"+(0===n?"":"."+r),this.select.value=t,this.updateOutput()},t.prototype.setLocale=function(t){this.locale=t,this.updateOutput()},t.prototype.displayValue=function(){var t=e.currencies[this.currency.toUpperCase()].fraction;return new Intl.NumberFormat(this.locale,{localeMatcher:"best fit",style:"currency",currency:this.currency.toUpperCase(),currencyDisplay:"symbol",minimumFractionDigits:t,maximumFractionDigits:t}).format(parseFloat(this.formatValue()))},t.prototype.formatValue=function(){var t=""===this.value?"0":this.value,n=e.currencies[this.currency.toUpperCase()].fraction;if(0===n)return t;for(var r="1",o=0;o<n;o++)r+="0";var i=parseInt(r,10);return(parseInt(t,10)/i).toFixed(n)},t.prototype.destroy=function(){this.container.innerHTML=""},t.prototype.validate=function(t){if(!("string"==typeof t.container?document.querySelector(t.container):t.container))throw new Error("Could not find container")},t.prototype.updateInputDisplay=function(){if(""!==this.value){var t=this.display.replace(e.currencies[this.currency.toUpperCase()].symbol,""),n=this.currency;n.split("").forEach(function(e,r){t=t.replace(n.substring(0,n.length-r),"")}),t=t.trim(),this.input.value=t}else this.input.value=""},t.prototype.updateOutput=function(){this.value=""===this.value?"":parseInt(this.value,10).toString(),this.format=this.formatValue(),this.display=this.displayValue(),this.updateInputDisplay(),this.onChange({value:this.value,display:this.display,format:this.format,currency:this.currency,locale:this.locale})},t.prototype.render=function(){var t=this;for(var n in this.container.classList.add("fpm"),this.currencyDiv.classList.add("fpm-currency"),this.input.classList.add("fpm-value"),this.select.classList.add("fpm-select"),this.input.addEventListener("keydown",function(e){t.inputKeydown(e)},!1),this.input.addEventListener("click",function(e){t.input.focus(),t.moveCursorToEnd(t.input)},!1),e.currencies)if(e.currencies.hasOwnProperty(n)){var r=document.createElement("option");r.value=n,r.text=n.toUpperCase(),this.select.appendChild(r)}this.select.addEventListener("change",function(){t.setCurrency(t.select.value)}),this.container.appendChild(this.currencyDiv),this.container.appendChild(this.input),this.showSelection&&this.container.appendChild(this.select)},t.prototype.inputKeydown=function(t){t.preventDefault();var e=t.keyCode||t.which;return 8===e||46===e?(this.value=this.value.substring(0,this.value.length-1),void this.updateOutput()):e>=48&&e<=57?(this.value+=String.fromCharCode(e),void this.updateOutput()):void 0},t.prototype.moveCursorToEnd=function(t){if("number"==typeof t.selectionStart)t.selectionStart=t.selectionEnd=t.value.length;else if(void 0!==t.createTextRange){t.focus();var e=t.createTextRange();e.collapse(!1),e.select()}},t.prototype.getLocale=function(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language?navigator.language:"en"},t}();e.default=o},,,function(t,e,n){"use strict";n.r(e);var r=function(){var t=this.$createElement;return(this._self._c||t)("div",{ref:"fpmoney"})};r._withStripped=!0;var o=n(0),i=n.n(o);var s=function(t,e,n,r,o,i,s,a){var c,u="function"==typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=n,u._compiled=!0),r&&(u.functional=!0),i&&(u._scopeId="data-v-"+i),s?(c=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},u._ssrRegister=c):o&&(c=a?function(){o.call(this,this.$root.$options.shadowRoot)}:o),c)if(u.functional){u._injectStyles=c;var l=u.render;u.render=function(t,e){return c.call(e),l(t,e)}}else{var p=u.beforeCreate;u.beforeCreate=p?[].concat(p,c):[c]}return{exports:t,options:u}}({name:"fp-money",props:{value:[String,Number],currency:String,locale:String,onChange:Function,showSelection:{type:Boolean,default:!0}},data:()=>({fpmoney:null}),mounted(){this.init()},updated(){this.fpmoney&&this.fpmoney.destroy(),this.init()},methods:{init(){const t={container:this.$refs.fpmoney};this.value&&(t.value=this.value),this.currency&&(t.currency=this.currency),this.locale&&(t.locale=this.locale),t.showSelection=this.showSelection,this.onChange&&(t.onChange=this.onChange),this.fpmoney=new i.a(t)}}},r,[],!1,null,null,null);s.options.__file="component.vue";e.default=s.exports}]).default}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FPMoney=t():e.FPMoney=t()}(window,function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t,n){"use strict";t.__esModule=!0;var i=n(1);t.currencies=i.currencies,t.intToFraction=i.intToFraction,t.fractionToInt=i.fractionToInt,t.displayValue=i.displayValue,t.getLocale=i.getLocale;var r=function(){function e(e){var t;this.value="",this.display="",this.format="",this.currencies=JSON.parse(JSON.stringify(i.currencies)),this.currency="",this.locale=i.getLocale(),this.maxValue=0,this.showSelection=!0,this.validate(e),t="string"==typeof e.container?document.querySelector(e.container):e.container,this.container=t,e.currencies&&(this.currencies=e.currencies),e.currency?this.currency=e.currency.toUpperCase():this.currency=Object.keys(this.currencies)[0],e.locale&&(this.locale=e.locale),e.value&&(this.value=i.fractionToInt(e.value,this.currencies[this.currency].fraction).toString()),e.maxValue&&(this.maxValue=i.fractionToInt(e.maxValue,this.currencies[this.currency].fraction)),void 0!==e.showSelection&&(this.showSelection=e.showSelection),this.onChange=e.onChange?this.onChange=e.onChange:function(){},this.currencyDiv=document.createElement("div"),this.input=document.createElement("input"),this.select=document.createElement("select"),this.render(),this.setCurrency(this.currency)}return e.prototype.setCurrency=function(e){e=e.toUpperCase(),this.currency=e,this.currencyDiv.innerHTML=this.currencies[e].symbol;for(var t=this.currencies[e].fraction,n="",i=0;i<t;i++)n+="0";this.input.placeholder="0"+(0===t?"":"."+n),this.select.value=e,this.updateOutput()},e.prototype.setLocale=function(e){this.locale=e,this.updateOutput()},e.prototype.destroy=function(){this.container.innerHTML=""},e.prototype.validate=function(e){if(!("string"==typeof e.container?document.querySelector(e.container):e.container))throw new Error("Could not find container")},e.prototype.updateOutput=function(){if(""!==this.value){var e=parseInt(this.value,10);0!==this.maxValue&&e>this.maxValue&&(e=this.maxValue),this.value=e.toString()}this.format=i.intToFraction(this.value,this.currencies[this.currency].fraction).toFixed(this.currencies[this.currency].fraction),this.display=i.displayValue(this.value,this.currency,this.currencies[this.currency].fraction,this.locale),this.updateInputDisplay(),this.onChange({value:this.value,display:this.display,format:this.format,currency:this.currency,locale:this.locale})},e.prototype.updateInputDisplay=function(){if(""!==this.value){var e=this.display.replace(this.currencies[this.currency.toUpperCase()].symbol,""),t=this.currency;e=e.replace(t,""),t.split("").forEach(function(n,i){e=e.replace(t.substring(0,t.length-i),"")}),e=e.trim(),this.input.value=e}else this.input.value=""},e.prototype.render=function(){var e=this;for(var t in this.container.classList.add("fpm"),this.currencyDiv.classList.add("fpm-currency"),this.input.classList.add("fpm-value"),this.select.classList.add("fpm-select"),this.input.addEventListener("keydown",function(t){e.inputKeydown(t)},!1),this.input.addEventListener("click",function(t){e.input.focus(),e.moveCursorToEnd(e.input)},!1),this.currencies)if(this.currencies.hasOwnProperty(t)){var n=document.createElement("option");n.value=t,n.text=t.toUpperCase(),this.select.appendChild(n)}this.select.addEventListener("change",function(){e.setCurrency(e.select.value)}),this.container.appendChild(this.currencyDiv),this.container.appendChild(this.input),this.showSelection&&this.container.appendChild(this.select)},e.prototype.inputKeydown=function(e){var t=e.keyCode||e.which;8===t||46===t?(e.preventDefault(),this.value=this.value.substring(0,this.value.length-1),this.updateOutput()):t>=48&&t<=57||t>=96&&t<=105?(e.preventDefault(),this.value+=e.key,this.updateOutput()):9===t||13===t||e.preventDefault()},e.prototype.moveCursorToEnd=function(e){if("number"==typeof e.selectionStart)e.selectionStart=e.selectionEnd=e.value.length;else if(void 0!==e.createTextRange){e.focus();var t=e.createTextRange();t.collapse(!1),t.select()}},e}();t.default=r},function(e,t,n){"use strict";function i(e,t){void 0===t&&(t=2),""===(e=e.toString())&&(e="0");for(var n="1",i=0;i<t;i++)n+="0";var r=parseInt(n,10);return-1!==e.indexOf(".")&&(e=(parseFloat(e)*r).toString()),0===t?parseInt(e,10):parseFloat((parseInt(e,10)/r).toFixed(t))}function r(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language?navigator.language:"en-US"}t.__esModule=!0,t.currencies={USD:{symbol:"$",fraction:2},EUR:{symbol:"€",fraction:2},GBP:{symbol:"£",fraction:2},INR:{symbol:"₹",fraction:2},CRC:{symbol:"₡",fraction:2},VND:{symbol:"₫",fraction:0},HUF:{symbol:"Ft",fraction:2},ILS:{symbol:"₪",fraction:2},CNY:{symbol:"¥",fraction:2},KRW:{symbol:"₩",fraction:0},NGN:{symbol:"₦",fraction:2},PYG:{symbol:"₲",fraction:0},PHP:{symbol:"₱",fraction:2},PLN:{symbol:"zł",fraction:2},THB:{symbol:"฿",fraction:2},UAH:{symbol:"₴",fraction:2},JPY:{symbol:"¥",fraction:0}},t.intToFraction=i,t.fractionToInt=function(e,t){void 0===t&&(t=2);for(var n=e.toString(),i="1",r=0;r<t;r++)i+="0";var o=parseInt(i,10),s=Math.round(parseFloat(n)*o).toString();return parseInt(s,10)},t.displayValue=function(e,t,n,o){return void 0===o&&(o=r()),new Intl.NumberFormat(o,{localeMatcher:"best fit",style:"currency",currency:t.toUpperCase(),currencyDisplay:"symbol",minimumFractionDigits:n,maximumFractionDigits:n}).format(i(e,n))},t.getLocale=r},,,function(e,t,n){"use strict";n.r(t);var i=function(){var e=this.$createElement;return(this._self._c||e)("div",{ref:"fpmoney"})};i._withStripped=!0;var r=n(0),o=n.n(r);var s=function(e,t,n,i,r,o,s,c){var a,u="function"==typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=n,u._compiled=!0),i&&(u.functional=!0),o&&(u._scopeId="data-v-"+o),s?(a=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),r&&r.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(s)},u._ssrRegister=a):r&&(a=c?function(){r.call(this,this.$root.$options.shadowRoot)}:r),a)if(u.functional){u._injectStyles=a;var l=u.render;u.render=function(e,t){return a.call(t),l(e,t)}}else{var h=u.beforeCreate;u.beforeCreate=h?[].concat(h,a):[a]}return{exports:e,options:u}}({name:"fp-money",props:{value:[String,Number],currencies:Object,currency:String,locale:String,maxValue:Number,onChange:Function,showSelection:{type:Boolean,default:!0}},data:()=>({fpmoney:null}),mounted(){this.init()},updated(){this.fpmoney&&this.fpmoney.destroy(),this.init()},methods:{init(){const e={container:this.$refs.fpmoney};this.value&&(e.value=this.value),this.currencies&&(e.currencies=this.currencies),this.currency&&(e.currency=this.currency),this.locale&&(e.locale=this.locale),this.maxValue&&(e.maxValue=this.maxValue),e.showSelection=this.showSelection,this.onChange&&(e.onChange=this.onChange),this.fpmoney=new o.a(e)}}},i,[],!1,null,null,null);s.options.__file="component.vue";t.default=s.exports}]).default}); |
@@ -1,9 +0,3 @@ | ||
interface Currencies { | ||
[currency: string]: Currency; | ||
} | ||
interface Currency { | ||
symbol: string; | ||
fraction: number; | ||
} | ||
export declare const currencies: Currencies; | ||
import { Currencies, currencies, intToFraction, fractionToInt, displayValue, getLocale } from './currencies'; | ||
export { currencies, intToFraction, fractionToInt, displayValue, getLocale }; | ||
export interface Values { | ||
@@ -19,9 +13,9 @@ value: string; | ||
value?: string | number; | ||
currencies?: Currencies; | ||
currency?: string; | ||
locale?: string; | ||
maxValue?: number; | ||
showSelection?: boolean; | ||
onChange: (values: Values) => void; | ||
} | ||
export declare function lowestCommonToFormat(val: string | number, fraction?: number): string; | ||
export declare function formatToLowestCommon(val: string | number, fraction?: number): string; | ||
export default class FPMoney { | ||
@@ -35,4 +29,6 @@ container: HTMLDivElement; | ||
format: string; | ||
currencies: Currencies; | ||
currency: string; | ||
locale: string; | ||
maxValue: number; | ||
showSelection: boolean; | ||
@@ -43,13 +39,9 @@ onChange: (values: Values) => void; | ||
setLocale(locale: string): void; | ||
displayValue(): string; | ||
formatValue(): string; | ||
destroy(): void; | ||
private validate; | ||
private updateOutput; | ||
private updateInputDisplay; | ||
private updateOutput; | ||
private render; | ||
private inputKeydown; | ||
private moveCursorToEnd; | ||
private getLocale; | ||
} | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.FPMoney=e():t.FPMoney=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";function r(t,e){void 0===e&&(e=2);for(var n=t.toString(),r="1",o=0;o<e;o++)r+="0";var i=parseInt(r,10),a=(parseFloat(n)*i).toString();return parseInt(a,10).toString()}e.__esModule=!0,e.currencies={USD:{symbol:"$",fraction:2},EUR:{symbol:"€",fraction:2},GBP:{symbol:"£",fraction:2},INR:{symbol:"₹",fraction:2},CRC:{symbol:"₡",fraction:2},VND:{symbol:"₫",fraction:0},HUF:{symbol:"Ft",fraction:2},ILS:{symbol:"₪",fraction:2},CNY:{symbol:"¥",fraction:2},KRW:{symbol:"₩",fraction:0},NGN:{symbol:"₦",fraction:2},PYG:{symbol:"₲",fraction:0},PHP:{symbol:"₱",fraction:2},PLN:{symbol:"zł",fraction:2},THB:{symbol:"฿",fraction:2},UAH:{symbol:"₴",fraction:2},JPY:{symbol:"¥",fraction:0}},e.lowestCommonToFormat=function(t,e){void 0===e&&(e=2),t=t.toString();for(var n="1",r=0;r<e;r++)n+="0";var o=parseInt(n,10);return-1!==t.indexOf(".")&&(t=(parseFloat(t)*o).toString()),0===e?parseInt(t,10).toString():(parseInt(t,10)/o).toFixed(e)},e.formatToLowestCommon=r;var o=function(){function t(t){var n;this.value="",this.display="",this.format="",this.currency="USD",this.locale=this.getLocale(),this.showSelection=!0,this.validate(t),n="string"==typeof t.container?document.querySelector(t.container):t.container,this.container=n,t.currency&&(this.currency=t.currency.toUpperCase()),t.locale&&(this.locale=t.locale),t.value&&(this.value=r(t.value,e.currencies[this.currency].fraction)),void 0!==t.showSelection&&(this.showSelection=t.showSelection),this.onChange=t.onChange?this.onChange=t.onChange:function(){},this.currencyDiv=document.createElement("div"),this.input=document.createElement("input"),this.select=document.createElement("select"),this.render(),this.setCurrency(this.currency)}return t.prototype.setCurrency=function(t){t=t.toUpperCase(),this.currency=t,this.currencyDiv.innerHTML=e.currencies[t].symbol;for(var n=e.currencies[t].fraction,r="",o=0;o<n;o++)r+="0";this.input.placeholder="0"+(0===n?"":"."+r),this.select.value=t,this.updateOutput()},t.prototype.setLocale=function(t){this.locale=t,this.updateOutput()},t.prototype.displayValue=function(){var t=e.currencies[this.currency.toUpperCase()].fraction;return new Intl.NumberFormat(this.locale,{localeMatcher:"best fit",style:"currency",currency:this.currency.toUpperCase(),currencyDisplay:"symbol",minimumFractionDigits:t,maximumFractionDigits:t}).format(parseFloat(this.formatValue()))},t.prototype.formatValue=function(){var t=""===this.value?"0":this.value,n=e.currencies[this.currency.toUpperCase()].fraction;if(0===n)return t;for(var r="1",o=0;o<n;o++)r+="0";var i=parseInt(r,10);return(parseInt(t,10)/i).toFixed(n)},t.prototype.destroy=function(){this.container.innerHTML=""},t.prototype.validate=function(t){if(!("string"==typeof t.container?document.querySelector(t.container):t.container))throw new Error("Could not find container")},t.prototype.updateInputDisplay=function(){if(""!==this.value){var t=this.display.replace(e.currencies[this.currency.toUpperCase()].symbol,""),n=this.currency;n.split("").forEach(function(e,r){t=t.replace(n.substring(0,n.length-r),"")}),t=t.trim(),this.input.value=t}else this.input.value=""},t.prototype.updateOutput=function(){this.value=""===this.value?"":parseInt(this.value,10).toString(),this.format=this.formatValue(),this.display=this.displayValue(),this.updateInputDisplay(),this.onChange({value:this.value,display:this.display,format:this.format,currency:this.currency,locale:this.locale})},t.prototype.render=function(){var t=this;for(var n in this.container.classList.add("fpm"),this.currencyDiv.classList.add("fpm-currency"),this.input.classList.add("fpm-value"),this.select.classList.add("fpm-select"),this.input.addEventListener("keydown",function(e){t.inputKeydown(e)},!1),this.input.addEventListener("click",function(e){t.input.focus(),t.moveCursorToEnd(t.input)},!1),e.currencies)if(e.currencies.hasOwnProperty(n)){var r=document.createElement("option");r.value=n,r.text=n.toUpperCase(),this.select.appendChild(r)}this.select.addEventListener("change",function(){t.setCurrency(t.select.value)}),this.container.appendChild(this.currencyDiv),this.container.appendChild(this.input),this.showSelection&&this.container.appendChild(this.select)},t.prototype.inputKeydown=function(t){t.preventDefault();var e=t.keyCode||t.which;return 8===e||46===e?(this.value=this.value.substring(0,this.value.length-1),void this.updateOutput()):e>=48&&e<=57?(this.value+=String.fromCharCode(e),void this.updateOutput()):void 0},t.prototype.moveCursorToEnd=function(t){if("number"==typeof t.selectionStart)t.selectionStart=t.selectionEnd=t.value.length;else if(void 0!==t.createTextRange){t.focus();var e=t.createTextRange();e.collapse(!1),e.select()}},t.prototype.getLocale=function(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language?navigator.language:"en"},t}();e.default=o}]).default}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.FPMoney=e():t.FPMoney=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";e.__esModule=!0;var i=n(1);e.currencies=i.currencies,e.intToFraction=i.intToFraction,e.fractionToInt=i.fractionToInt,e.displayValue=i.displayValue,e.getLocale=i.getLocale;var r=function(){function t(t){var e;this.value="",this.display="",this.format="",this.currencies=JSON.parse(JSON.stringify(i.currencies)),this.currency="",this.locale=i.getLocale(),this.maxValue=0,this.showSelection=!0,this.validate(t),e="string"==typeof t.container?document.querySelector(t.container):t.container,this.container=e,t.currencies&&(this.currencies=t.currencies),t.currency?this.currency=t.currency.toUpperCase():this.currency=Object.keys(this.currencies)[0],t.locale&&(this.locale=t.locale),t.value&&(this.value=i.fractionToInt(t.value,this.currencies[this.currency].fraction).toString()),t.maxValue&&(this.maxValue=i.fractionToInt(t.maxValue,this.currencies[this.currency].fraction)),void 0!==t.showSelection&&(this.showSelection=t.showSelection),this.onChange=t.onChange?this.onChange=t.onChange:function(){},this.currencyDiv=document.createElement("div"),this.input=document.createElement("input"),this.select=document.createElement("select"),this.render(),this.setCurrency(this.currency)}return t.prototype.setCurrency=function(t){t=t.toUpperCase(),this.currency=t,this.currencyDiv.innerHTML=this.currencies[t].symbol;for(var e=this.currencies[t].fraction,n="",i=0;i<e;i++)n+="0";this.input.placeholder="0"+(0===e?"":"."+n),this.select.value=t,this.updateOutput()},t.prototype.setLocale=function(t){this.locale=t,this.updateOutput()},t.prototype.destroy=function(){this.container.innerHTML=""},t.prototype.validate=function(t){if(!("string"==typeof t.container?document.querySelector(t.container):t.container))throw new Error("Could not find container")},t.prototype.updateOutput=function(){if(""!==this.value){var t=parseInt(this.value,10);0!==this.maxValue&&t>this.maxValue&&(t=this.maxValue),this.value=t.toString()}this.format=i.intToFraction(this.value,this.currencies[this.currency].fraction).toFixed(this.currencies[this.currency].fraction),this.display=i.displayValue(this.value,this.currency,this.currencies[this.currency].fraction,this.locale),this.updateInputDisplay(),this.onChange({value:this.value,display:this.display,format:this.format,currency:this.currency,locale:this.locale})},t.prototype.updateInputDisplay=function(){if(""!==this.value){var t=this.display.replace(this.currencies[this.currency.toUpperCase()].symbol,""),e=this.currency;t=t.replace(e,""),e.split("").forEach(function(n,i){t=t.replace(e.substring(0,e.length-i),"")}),t=t.trim(),this.input.value=t}else this.input.value=""},t.prototype.render=function(){var t=this;for(var e in this.container.classList.add("fpm"),this.currencyDiv.classList.add("fpm-currency"),this.input.classList.add("fpm-value"),this.select.classList.add("fpm-select"),this.input.addEventListener("keydown",function(e){t.inputKeydown(e)},!1),this.input.addEventListener("click",function(e){t.input.focus(),t.moveCursorToEnd(t.input)},!1),this.currencies)if(this.currencies.hasOwnProperty(e)){var n=document.createElement("option");n.value=e,n.text=e.toUpperCase(),this.select.appendChild(n)}this.select.addEventListener("change",function(){t.setCurrency(t.select.value)}),this.container.appendChild(this.currencyDiv),this.container.appendChild(this.input),this.showSelection&&this.container.appendChild(this.select)},t.prototype.inputKeydown=function(t){var e=t.keyCode||t.which;8===e||46===e?(t.preventDefault(),this.value=this.value.substring(0,this.value.length-1),this.updateOutput()):e>=48&&e<=57||e>=96&&e<=105?(t.preventDefault(),this.value+=t.key,this.updateOutput()):9===e||13===e||t.preventDefault()},t.prototype.moveCursorToEnd=function(t){if("number"==typeof t.selectionStart)t.selectionStart=t.selectionEnd=t.value.length;else if(void 0!==t.createTextRange){t.focus();var e=t.createTextRange();e.collapse(!1),e.select()}},t}();e.default=r},function(t,e,n){"use strict";function i(t,e){void 0===e&&(e=2),""===(t=t.toString())&&(t="0");for(var n="1",i=0;i<e;i++)n+="0";var r=parseInt(n,10);return-1!==t.indexOf(".")&&(t=(parseFloat(t)*r).toString()),0===e?parseInt(t,10):parseFloat((parseInt(t,10)/r).toFixed(e))}function r(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language?navigator.language:"en-US"}e.__esModule=!0,e.currencies={USD:{symbol:"$",fraction:2},EUR:{symbol:"€",fraction:2},GBP:{symbol:"£",fraction:2},INR:{symbol:"₹",fraction:2},CRC:{symbol:"₡",fraction:2},VND:{symbol:"₫",fraction:0},HUF:{symbol:"Ft",fraction:2},ILS:{symbol:"₪",fraction:2},CNY:{symbol:"¥",fraction:2},KRW:{symbol:"₩",fraction:0},NGN:{symbol:"₦",fraction:2},PYG:{symbol:"₲",fraction:0},PHP:{symbol:"₱",fraction:2},PLN:{symbol:"zł",fraction:2},THB:{symbol:"฿",fraction:2},UAH:{symbol:"₴",fraction:2},JPY:{symbol:"¥",fraction:0}},e.intToFraction=i,e.fractionToInt=function(t,e){void 0===e&&(e=2);for(var n=t.toString(),i="1",r=0;r<e;r++)i+="0";var o=parseInt(i,10),c=Math.round(parseFloat(n)*o).toString();return parseInt(c,10)},e.displayValue=function(t,e,n,o){return void 0===o&&(o=r()),new Intl.NumberFormat(o,{localeMatcher:"best fit",style:"currency",currency:e.toUpperCase(),currencyDisplay:"symbol",minimumFractionDigits:n,maximumFractionDigits:n}).format(i(t,n))},e.getLocale=r}]).default}); |
@@ -1,2 +0,2 @@ | ||
(function(e){function t(t){for(var a,o,l=t[0],c=t[1],s=t[2],p=0,h=[];p<l.length;p++)o=l[p],i[o]&&h.push(i[o][0]),i[o]=0;for(a in c)Object.prototype.hasOwnProperty.call(c,a)&&(e[a]=c[a]);u&&u(t);while(h.length)h.shift()();return r.push.apply(r,s||[]),n()}function n(){for(var e,t=0;t<r.length;t++){for(var n=r[t],a=!0,l=1;l<n.length;l++){var c=n[l];0!==i[c]&&(a=!1)}a&&(r.splice(t--,1),e=o(o.s=n[0]))}return e}var a={},i={app:0},r=[];function o(t){if(a[t])return a[t].exports;var n=a[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=e,o.c=a,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)o.d(n,a,function(t){return e[t]}.bind(null,a));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/";var l=window["webpackJsonp"]=window["webpackJsonp"]||[],c=l.push.bind(l);l.push=t,l=l.slice();for(var s=0;s<l.length;s++)t(l[s]);var u=c;r.push([0,"chunk-vendors"]),n()})({0:function(e,t,n){e.exports=n("cd49")},"078e":function(e,t,n){"use strict";var a=n("b13f"),i=n.n(a);i.a},"0df1":function(e,t,n){"use strict";var a=n("e637"),i=n.n(a);i.a},4286:function(e,t,n){},8325:function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpFNTE3OEEyQTk5QTAxMUUyOUExNUJDMTA0NkE4OTA0RCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpFNTE3OEEyQjk5QTAxMUUyOUExNUJDMTA0NkE4OTA0RCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkU1MTc4QTI4OTlBMDExRTI5QTE1QkMxMDQ2QTg5MDREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkU1MTc4QTI5OTlBMDExRTI5QTE1QkMxMDQ2QTg5MDREIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+m4QGuQAAAyRJREFUeNrEl21ojWEYx895TDPbMNlBK46IUiNmPvHBSUjaqc0H8pF5+aDUKPEBqU2NhRQpX5Rv5jWlDIWlMCv7MMSWsWwmb3tpXub4XXWdPHvc9/Gc41nu+nedc7/8r/99PffLdYdDPsvkwsgkTBwsA/PADJCnzX2gHTwBt8Hl7p537/3whn04XoDZDcpBlk+9P8AFcAghzRkJwPF4zGGw0Y9QS0mAM2AnQj77FqCzrtcwB1Hk81SYojHK4DyGuQ6mhIIrBWB9Xm7ug/6B/nZrBHBegrkFxoVGpnwBMSLR9EcEcC4qb8pP14BWcBcUgewMnF3T34VqhWMFkThLJAalwnENOAKiHpJq1FZgI2AT6HZtuxZwR9GidSHtI30jOrbawxlVX78/AbNfhHlomEUJJI89O2MqeE79T8/nk8nMBm/dK576hZgmA3cp/R4l9/UeSxiHLVIlNm4nFfT0bxyuIj7LHRTKai+zdJobwMKzcZSJb0ePV5PKN+BqAAKE47UlMnERELMM3EdYP/yrd+XYb2mOiYBiQ8OQnoRBlXrl9JZix7D1pHTazu4MoyBcnYamqAjIMTR8G4FT8LuhLsexXYYjICBiqhQBvYb6fLZIJCjPypVvaOoVAW2WcasCnL2Nq82xHJNSqlCeFcDshaPK0twkAhosjZL31QYw+1rlMpWGMArl23SBsZZO58F2tlJXmjOXS+s4WGvpMiBJT/I2PInZ6lIs9/hBsNS1hS6BG0DSqmYEDRlCXQrmy50P1oDRKTSegmNbUsA0zDMwRhPJXeCE3vWLPQMvan6X8AgIa1vcR4AkGZkDR4ejJ1UHpsaVI0g2LInpOsNFUud1rhxSV+fzC9Woz2EZkWQuja7/B+jUrgtIMpy9YCW4n4K41YfzRneW5E1KJTe4B2Zq1Q5EHEtj4U3AfEzR5SVY4l7QYQPJdN2as7RKBF0BPZqqH4VgMAMBL8Byxr7y8zCZiDlnOcEKIPmUpgB5Z2ww5RdOiiRiNajUmWda5IG6WbhsyY2fx6m8gLcoJDJFkH219M3We1+cnda93pfycZpIJEL/s/wSYADmOAwAQgdpBAAAAABJRU5ErkJggg=="},b13f:function(e,t,n){},bc8c:function(e,t,n){},c30d:function(e,t,n){"use strict";var a=n("4286"),i=n.n(a);i.a},cd49:function(e,t,n){"use strict";n.r(t);n("cadf"),n("551c"),n("097d"),n("dc22");var a=n("2b0e"),i=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"container"},[n("div",{staticClass:"bluebar"}),n("div",{staticClass:"greenbar"}),n("div",{staticClass:"orangebar"}),n("div",{staticClass:"app"},[n("Header"),n("transition",{attrs:{mode:"out-in",name:"slide-left"}},[n("router-view")],1)],1)])},r=[],o=function(){var e=this,t=e.$createElement,a=e._self._c||t;return a("div",{staticClass:"header"},[a("div",{staticClass:"title"},[e._v("FluidPay Money Formatter")]),a("div",{staticClass:"menu"},[a("router-link",{attrs:{to:"/"}},[e._v("Home")]),a("router-link",{attrs:{to:"/vue"}},[e._v("Vue")]),a("a",{attrs:{target:"_blank",href:"http://github.com/fluidpay/fp-money"}},[a("img",{attrs:{height:"20",alt:"Github Logomark",src:n("8325")}})])],1)])},l=[],c=a["a"].extend({}),s=c,u=(n("0df1"),n("2877")),p=Object(u["a"])(s,o,l,!1,null,null,null);p.options.__file="header.vue";var h=p.exports,f=a["a"].extend({name:"app",components:{Header:h}}),v=f,d=(n("c30d"),Object(u["a"])(v,i,r,!1,null,null,null));d.options.__file="App.vue";var m=d.exports,y=n("8c4f"),g=function(){var e=this,t=e.$createElement;e._self._c;return e._m(0)},b=[function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"basic"},[n("div",{attrs:{id:"example"}}),n("pre",[e._v(" "),n("code",{staticClass:"language-bash"},[e._v("\n npm install fp-money\n ")]),e._v("\n ")]),n("pre",[e._v(" "),n("code",{staticClass:"language-html"},[e._v('\n <div id="example"></div>\n ')]),e._v("\n ")]),n("pre",[e._v(" "),n("code",{staticClass:"language-javascript"},[e._v("\n import FPMoney from 'fp-money'\n import 'fp-money/dist/fp-money.css'\n\n new FPMoney({\n container: document.querySelector('#example'),\n // value: 86753.09, // optional - default ''\n // currency: 'usd', // optional - default 'usd'\n // locale: 'en-us', // optional - default navigator.language\n // showSelection: true, // optional - default true\n onChange: (values) => {\n console.log(values)\n // {\n // value: \"8675309\",\n // display: \"$86,753.09\",\n // format: \"86753.09\",\n // currency: \"USD\",\n // locale: \"en-US\"\n // }\n }\n })\n ")]),e._v("\n ")])])}],A=(n("28a5"),n("ac6a"),n("a481"),n("c665")),w=n("aa9a"),E=(n("6b54"),{USD:{symbol:"$",fraction:2},EUR:{symbol:"€",fraction:2},GBP:{symbol:"£",fraction:2},INR:{symbol:"₹",fraction:2},CRC:{symbol:"₡",fraction:2},VND:{symbol:"₫",fraction:0},HUF:{symbol:"Ft",fraction:2},ILS:{symbol:"₪",fraction:2},CNY:{symbol:"¥",fraction:2},KRW:{symbol:"₩",fraction:0},NGN:{symbol:"₦",fraction:2},PYG:{symbol:"₲",fraction:0},PHP:{symbol:"₱",fraction:2},PLN:{symbol:"zł",fraction:2},THB:{symbol:"฿",fraction:2},UAH:{symbol:"₴",fraction:2},JPY:{symbol:"¥",fraction:0}});function C(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=e.toString(),a="1",i=0;i<t;i++)a+="0";var r=parseInt(a,10),o=(parseFloat(n)*r).toString();return parseInt(o,10).toString()}var S=function(){function e(t){var n;Object(A["a"])(this,e),this.value="",this.display="",this.format="",this.currency="USD",this.locale=this.getLocale(),this.showSelection=!0,this.validate(t),n="string"===typeof t.container?document.querySelector(t.container):t.container,this.container=n,t.currency&&(this.currency=t.currency.toUpperCase()),t.locale&&(this.locale=t.locale),t.value&&(this.value=C(t.value,E[this.currency].fraction)),void 0!==t.showSelection&&(this.showSelection=t.showSelection),this.onChange=t.onChange?this.onChange=t.onChange:function(){},this.currencyDiv=document.createElement("div"),this.input=document.createElement("input"),this.select=document.createElement("select"),this.render(),this.setCurrency(this.currency)}return Object(w["a"])(e,[{key:"setCurrency",value:function(e){e=e.toUpperCase(),this.currency=e,this.currencyDiv.innerHTML=E[e].symbol;for(var t=E[e].fraction,n="",a=0;a<t;a++)n+="0";this.input.placeholder="0"+(0===t?"":"."+n),this.select.value=e,this.updateOutput()}},{key:"setLocale",value:function(e){this.locale=e,this.updateOutput()}},{key:"displayValue",value:function(){var e=E[this.currency.toUpperCase()].fraction,t=new Intl.NumberFormat(this.locale,{localeMatcher:"best fit",style:"currency",currency:this.currency.toUpperCase(),currencyDisplay:"symbol",minimumFractionDigits:e,maximumFractionDigits:e});return t.format(parseFloat(this.formatValue()))}},{key:"formatValue",value:function(){var e=""===this.value?"0":this.value,t=E[this.currency.toUpperCase()].fraction;if(0===t)return e;for(var n="1",a=0;a<t;a++)n+="0";var i=parseInt(n,10);return(parseInt(e,10)/i).toFixed(t)}},{key:"destroy",value:function(){this.container.innerHTML=""}},{key:"validate",value:function(e){var t;if(t="string"===typeof e.container?document.querySelector(e.container):e.container,!t)throw new Error("Could not find container")}},{key:"updateInputDisplay",value:function(){if(""!==this.value){var e=this.display.replace(E[this.currency.toUpperCase()].symbol,""),t=this.currency;t.split("").forEach(function(n,a){e=e.replace(t.substring(0,t.length-a),"")}),e=e.trim(),this.input.value=e}else this.input.value=""}},{key:"updateOutput",value:function(){this.value=""===this.value?"":parseInt(this.value,10).toString(),this.format=this.formatValue(),this.display=this.displayValue(),this.updateInputDisplay(),this.onChange({value:this.value,display:this.display,format:this.format,currency:this.currency,locale:this.locale})}},{key:"render",value:function(){var e=this;for(var t in this.container.classList.add("fpm"),this.currencyDiv.classList.add("fpm-currency"),this.input.classList.add("fpm-value"),this.select.classList.add("fpm-select"),this.input.addEventListener("keydown",function(t){e.inputKeydown(t)},!1),this.input.addEventListener("click",function(t){e.input.focus(),e.moveCursorToEnd(e.input)},!1),E)if(E.hasOwnProperty(t)){var n=document.createElement("option");n.value=t,n.text=t.toUpperCase(),this.select.appendChild(n)}this.select.addEventListener("change",function(){e.setCurrency(e.select.value)}),this.container.appendChild(this.currencyDiv),this.container.appendChild(this.input),this.showSelection&&this.container.appendChild(this.select)}},{key:"inputKeydown",value:function(e){e.preventDefault();var t=e.keyCode||e.which;return 8===t||46===t?(this.value=this.value.substring(0,this.value.length-1),void this.updateOutput()):t>=48&&t<=57?(this.value+=String.fromCharCode(t),void this.updateOutput()):void 0}},{key:"moveCursorToEnd",value:function(e){if("number"===typeof e.selectionStart)e.selectionStart=e.selectionEnd=e.value.length;else if("undefined"!==typeof e.createTextRange){e.focus();var t=e.createTextRange();t.collapse(!1),t.select()}}},{key:"getLocale",value:function(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language?navigator.language:"en"}}]),e}(),M=a["a"].extend({mounted:function(){new S({container:document.querySelector("#example"),value:86753.09,onChange:function(e){console.log(e)}})}}),I=M,D=(n("078e"),Object(u["a"])(I,g,b,!1,null,null,null));D.options.__file="home.vue";var k=D.exports,R=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"vue"},[n("fpmoney",{attrs:{id:"example",value:"85555",onChange:e.change}}),e._m(0),e._m(1)],1)},j=[function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("pre",[e._v(" "),n("code",{staticClass:"language-javascript"},[e._v("\n import fpmoney from 'fp-money/dist/fp-money-vue.js'\n\n export default {\n components: { fpmoney },\n methods: {\n change(values: Values) {\n console.log(values)\n }\n }\n }\n ")]),e._v("\n ")])},function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("pre",[e._v(" "),n("code",{staticClass:"language-html"},[e._v('\n <fpmoney value="85555" :onChange="change" />\n ')]),e._v("\n ")])}],T=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"fpmoney"})},B=[],x=(n("c5f6"),{name:"fp-money",props:{value:[String,Number],currency:String,locale:String,onChange:Function,showSelection:{type:Boolean,default:!0}},data:function(){return{fpmoney:null}},mounted:function(){this.init()},updated:function(){this.fpmoney&&this.fpmoney.destroy(),this.init()},methods:{init:function(){var e={container:this.$refs.fpmoney};this.value&&(e.value=this.value),this.currency&&(e.currency=this.currency),this.locale&&(e.locale=this.locale),e.showSelection=this.showSelection,this.onChange&&(e.onChange=this.onChange),this.fpmoney=new S(e)}}}),U=x,_=Object(u["a"])(U,T,B,!1,null,null,null);_.options.__file="component.vue";var Z=_.exports,J=a["a"].extend({components:{fpmoney:Z},methods:{change:function(e){console.log(e)}}}),O=J,N=(n("d57a"),Object(u["a"])(O,R,j,!1,null,null,null));N.options.__file="vue.vue";var L=N.exports;a["a"].use(y["a"]);var P=new y["a"]({mode:"history",routes:[{path:"/",component:k},{path:"/vue",component:L}]}),G=n("c197"),Y=n.n(G),W=n("6f35"),F=n.n(W);n("e391"),n("7362");new F.a({"remove-trailing":!0,"remove-indent":!0,"left-trim":!0,"right-trim":!0}),a["a"].mixin({updated:function(){Y.a.highlightAll()}}),a["a"].config.productionTip=!1,new a["a"]({router:P,render:function(e){return e(m)}}).$mount("#app")},d57a:function(e,t,n){"use strict";var a=n("bc8c"),i=n.n(a);i.a},dc22:function(e,t,n){},e637:function(e,t,n){}}); | ||
(function(e){function t(t){for(var i,o,c=t[0],s=t[1],l=t[2],p=0,h=[];p<c.length;p++)o=c[p],a[o]&&h.push(a[o][0]),a[o]=0;for(i in s)Object.prototype.hasOwnProperty.call(s,i)&&(e[i]=s[i]);u&&u(t);while(h.length)h.shift()();return r.push.apply(r,l||[]),n()}function n(){for(var e,t=0;t<r.length;t++){for(var n=r[t],i=!0,c=1;c<n.length;c++){var s=n[c];0!==a[s]&&(i=!1)}i&&(r.splice(t--,1),e=o(o.s=n[0]))}return e}var i={},a={app:0},r=[];function o(t){if(i[t])return i[t].exports;var n=i[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,o),n.l=!0,n.exports}o.m=e,o.c=i,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},o.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)o.d(n,i,function(t){return e[t]}.bind(null,i));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="/";var c=window["webpackJsonp"]=window["webpackJsonp"]||[],s=c.push.bind(c);c.push=t,c=c.slice();for(var l=0;l<c.length;l++)t(c[l]);var u=s;r.push([0,"chunk-vendors"]),n()})({0:function(e,t,n){e.exports=n("cd49")},"078e":function(e,t,n){"use strict";var i=n("b13f"),a=n.n(i);a.a},"0df1":function(e,t,n){"use strict";var i=n("e637"),a=n.n(i);a.a},"3b63":function(e,t,n){},4286:function(e,t,n){},8325:function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpFNTE3OEEyQTk5QTAxMUUyOUExNUJDMTA0NkE4OTA0RCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpFNTE3OEEyQjk5QTAxMUUyOUExNUJDMTA0NkE4OTA0RCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkU1MTc4QTI4OTlBMDExRTI5QTE1QkMxMDQ2QTg5MDREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkU1MTc4QTI5OTlBMDExRTI5QTE1QkMxMDQ2QTg5MDREIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+m4QGuQAAAyRJREFUeNrEl21ojWEYx895TDPbMNlBK46IUiNmPvHBSUjaqc0H8pF5+aDUKPEBqU2NhRQpX5Rv5jWlDIWlMCv7MMSWsWwmb3tpXub4XXWdPHvc9/Gc41nu+nedc7/8r/99PffLdYdDPsvkwsgkTBwsA/PADJCnzX2gHTwBt8Hl7p537/3whn04XoDZDcpBlk+9P8AFcAghzRkJwPF4zGGw0Y9QS0mAM2AnQj77FqCzrtcwB1Hk81SYojHK4DyGuQ6mhIIrBWB9Xm7ug/6B/nZrBHBegrkFxoVGpnwBMSLR9EcEcC4qb8pP14BWcBcUgewMnF3T34VqhWMFkThLJAalwnENOAKiHpJq1FZgI2AT6HZtuxZwR9GidSHtI30jOrbawxlVX78/AbNfhHlomEUJJI89O2MqeE79T8/nk8nMBm/dK576hZgmA3cp/R4l9/UeSxiHLVIlNm4nFfT0bxyuIj7LHRTKai+zdJobwMKzcZSJb0ePV5PKN+BqAAKE47UlMnERELMM3EdYP/yrd+XYb2mOiYBiQ8OQnoRBlXrl9JZix7D1pHTazu4MoyBcnYamqAjIMTR8G4FT8LuhLsexXYYjICBiqhQBvYb6fLZIJCjPypVvaOoVAW2WcasCnL2Nq82xHJNSqlCeFcDshaPK0twkAhosjZL31QYw+1rlMpWGMArl23SBsZZO58F2tlJXmjOXS+s4WGvpMiBJT/I2PInZ6lIs9/hBsNS1hS6BG0DSqmYEDRlCXQrmy50P1oDRKTSegmNbUsA0zDMwRhPJXeCE3vWLPQMvan6X8AgIa1vcR4AkGZkDR4ejJ1UHpsaVI0g2LInpOsNFUud1rhxSV+fzC9Woz2EZkWQuja7/B+jUrgtIMpy9YCW4n4K41YfzRneW5E1KJTe4B2Zq1Q5EHEtj4U3AfEzR5SVY4l7QYQPJdN2as7RKBF0BPZqqH4VgMAMBL8Byxr7y8zCZiDlnOcEKIPmUpgB5Z2ww5RdOiiRiNajUmWda5IG6WbhsyY2fx6m8gLcoJDJFkH219M3We1+cnda93pfycZpIJEL/s/wSYADmOAwAQgdpBAAAAABJRU5ErkJggg=="},"94b9":function(e,t,n){"use strict";var i=n("3b63"),a=n.n(i);a.a},b13f:function(e,t,n){},bc8c:function(e,t,n){},c30d:function(e,t,n){"use strict";var i=n("4286"),a=n.n(i);a.a},cd49:function(e,t,n){"use strict";n.r(t);n("cadf"),n("551c"),n("097d"),n("dc22");var i=n("2b0e"),a=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"container"},[n("div",{staticClass:"bluebar"}),n("div",{staticClass:"greenbar"}),n("div",{staticClass:"orangebar"}),n("div",{staticClass:"app"},[n("Header"),n("transition",{attrs:{mode:"out-in",name:"slide-left"}},[n("router-view")],1)],1)])},r=[],o=function(){var e=this,t=e.$createElement,i=e._self._c||t;return i("div",{staticClass:"header"},[i("div",{staticClass:"title"},[e._v("FluidPay Money Formatter")]),i("div",{staticClass:"menu"},[i("router-link",{attrs:{to:"/"}},[e._v("Home")]),i("router-link",{attrs:{to:"/functions"}},[e._v("Functions")]),i("router-link",{attrs:{to:"/vue"}},[e._v("Vue")]),i("a",{attrs:{target:"_blank",href:"http://github.com/fluidpay/fp-money"}},[i("img",{attrs:{height:"20",alt:"Github Logomark",src:n("8325")}})])],1)])},c=[],s=i["a"].extend({}),l=s,u=(n("0df1"),n("2877")),p=Object(u["a"])(l,o,c,!1,null,null,null);p.options.__file="header.vue";var h=p.exports,f=i["a"].extend({name:"app",components:{Header:h}}),v=f,d=(n("c30d"),Object(u["a"])(v,a,r,!1,null,null,null));d.options.__file="App.vue";var m=d.exports,y=n("8c4f"),g=function(){var e=this,t=e.$createElement;e._self._c;return e._m(0)},b=[function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"basic"},[n("div",{attrs:{id:"example"}}),n("pre",[e._v(" "),n("code",{staticClass:"language-bash"},[e._v("\n npm install fp-money\n ")]),e._v("\n ")]),n("pre",[e._v(" "),n("code",{staticClass:"language-html"},[e._v('\n <div id="example"></div>\n ')]),e._v("\n ")]),n("pre",[e._v(" "),n("code",{staticClass:"language-javascript"},[e._v("\n import FPMoney from 'fp-money'\n import 'fp-money/dist/fp-money.css'\n\n new FPMoney({\n container: document.querySelector('#example'),\n // value: 86753.09, // optional - default ''\n // currencies: Object // optional - {USD: {symbol: '$', fraction:2}}\n // currency: 'USD', // optional - default 'USD'\n // locale: 'en-us', // optional - default navigator.language\n // maxValue: 999, // optional - default no limit\n // showSelection: true, // optional - default true\n\n onChange: (values) => {\n console.log(values)\n // {\n // value: \"8675309\",\n // display: \"$86,753.09\",\n // format: \"86753.09\",\n // currency: \"USD\",\n // locale: \"en-US\"\n // }\n }\n })\n ")]),e._v("\n ")])])}],A=(n("28a5"),n("a481"),n("6b54"),n("ac6a"),n("456d"),n("c665")),S=n("aa9a"),C={USD:{symbol:"$",fraction:2},EUR:{symbol:"€",fraction:2},GBP:{symbol:"£",fraction:2},INR:{symbol:"₹",fraction:2},CRC:{symbol:"₡",fraction:2},VND:{symbol:"₫",fraction:0},HUF:{symbol:"Ft",fraction:2},ILS:{symbol:"₪",fraction:2},CNY:{symbol:"¥",fraction:2},KRW:{symbol:"₩",fraction:0},NGN:{symbol:"₦",fraction:2},PYG:{symbol:"₲",fraction:0},PHP:{symbol:"₱",fraction:2},PLN:{symbol:"zł",fraction:2},THB:{symbol:"฿",fraction:2},UAH:{symbol:"₴",fraction:2},JPY:{symbol:"¥",fraction:0}};function E(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;e=e.toString(),""===e&&(e="0");for(var n="1",i=0;i<t;i++)n+="0";var a=parseInt(n,10);return-1!==e.indexOf(".")&&(e=(parseFloat(e)*a).toString()),0===t?parseInt(e,10):parseFloat((parseInt(e,10)/a).toFixed(t))}function w(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=e.toString(),i="1",a=0;a<t;a++)i+="0";var r=parseInt(i,10),o=Math.round(parseFloat(n)*r).toString();return parseInt(o,10)}function _(e,t,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:x(),a=new Intl.NumberFormat(i,{localeMatcher:"best fit",style:"currency",currency:t.toUpperCase(),currencyDisplay:"symbol",minimumFractionDigits:n,maximumFractionDigits:n});return a.format(E(e,n))}function x(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language?navigator.language:"en-US"}var I=function(){function e(t){var n;Object(A["a"])(this,e),this.value="",this.display="",this.format="",this.currencies=JSON.parse(JSON.stringify(C)),this.currency="",this.locale=x(),this.maxValue=0,this.showSelection=!0,this.validate(t),n="string"===typeof t.container?document.querySelector(t.container):t.container,this.container=n,t.currencies&&(this.currencies=t.currencies),t.currency?this.currency=t.currency.toUpperCase():this.currency=Object.keys(this.currencies)[0],t.locale&&(this.locale=t.locale),t.value&&(this.value=w(t.value,this.currencies[this.currency].fraction).toString()),t.maxValue&&(this.maxValue=w(t.maxValue,this.currencies[this.currency].fraction)),void 0!==t.showSelection&&(this.showSelection=t.showSelection),this.onChange=t.onChange?this.onChange=t.onChange:function(){},this.currencyDiv=document.createElement("div"),this.input=document.createElement("input"),this.select=document.createElement("select"),this.render(),this.setCurrency(this.currency)}return Object(S["a"])(e,[{key:"setCurrency",value:function(e){e=e.toUpperCase(),this.currency=e,this.currencyDiv.innerHTML=this.currencies[e].symbol;for(var t=this.currencies[e].fraction,n="",i=0;i<t;i++)n+="0";this.input.placeholder="0"+(0===t?"":"."+n),this.select.value=e,this.updateOutput()}},{key:"setLocale",value:function(e){this.locale=e,this.updateOutput()}},{key:"destroy",value:function(){this.container.innerHTML=""}},{key:"validate",value:function(e){var t;if(t="string"===typeof e.container?document.querySelector(e.container):e.container,!t)throw new Error("Could not find container")}},{key:"updateOutput",value:function(){if(""!==this.value){var e=parseInt(this.value,10);0!==this.maxValue&&e>this.maxValue&&(e=this.maxValue),this.value=e.toString()}this.format=E(this.value,this.currencies[this.currency].fraction).toFixed(this.currencies[this.currency].fraction),this.display=_(this.value,this.currency,this.currencies[this.currency].fraction,this.locale),this.updateInputDisplay(),this.onChange({value:this.value,display:this.display,format:this.format,currency:this.currency,locale:this.locale})}},{key:"updateInputDisplay",value:function(){if(""!==this.value){var e=this.display.replace(this.currencies[this.currency.toUpperCase()].symbol,""),t=this.currency;e=e.replace(t,""),t.split("").forEach(function(n,i){e=e.replace(t.substring(0,t.length-i),"")}),e=e.trim(),this.input.value=e}else this.input.value=""}},{key:"render",value:function(){var e=this;for(var t in this.container.classList.add("fpm"),this.currencyDiv.classList.add("fpm-currency"),this.input.classList.add("fpm-value"),this.select.classList.add("fpm-select"),this.input.addEventListener("keydown",function(t){e.inputKeydown(t)},!1),this.input.addEventListener("click",function(t){e.input.focus(),e.moveCursorToEnd(e.input)},!1),this.currencies)if(this.currencies.hasOwnProperty(t)){var n=document.createElement("option");n.value=t,n.text=t.toUpperCase(),this.select.appendChild(n)}this.select.addEventListener("change",function(){e.setCurrency(e.select.value)}),this.container.appendChild(this.currencyDiv),this.container.appendChild(this.input),this.showSelection&&this.container.appendChild(this.select)}},{key:"inputKeydown",value:function(e){var t=e.keyCode||e.which;8===t||46===t?(e.preventDefault(),this.value=this.value.substring(0,this.value.length-1),this.updateOutput()):t>=48&&t<=57||t>=96&&t<=105?(e.preventDefault(),this.value+=e.key,this.updateOutput()):9===t||13===t||e.preventDefault()}},{key:"moveCursorToEnd",value:function(e){if("number"===typeof e.selectionStart)e.selectionStart=e.selectionEnd=e.value.length;else if("undefined"!==typeof e.createTextRange){e.focus();var t=e.createTextRange();t.collapse(!1),t.select()}}}]),e}(),M=i["a"].extend({mounted:function(){new I({container:document.querySelector("#example"),value:86753.09,onChange:function(e){console.log(e)}})}}),T=M,D=(n("078e"),Object(u["a"])(T,g,b,!1,null,null,null));D.options.__file="home.vue";var j=D.exports,k=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"main functions"},[e._m(0),n("div",{staticClass:"section"},[n("div",{staticClass:"item"},[e._v("fractionToInt(value, fraction): 86753.09 - "+e._s(e.fractionToInt(86753.09,2)))]),n("div",{staticClass:"item"},[e._v("intToFraction(value, fraction): 8675309 - "+e._s(e.intToFraction(8675309,2)))]),n("div",{staticClass:"item"},[e._v("displayValue(value, currency, fraction, locale): 86753.09 - "+e._s(e.displayValue(86753.09,"usd",2,"en-us")))]),n("div",{staticClass:"item"},[e._v("getLocale(): "+e._s(e.getLocale()))])])])},R=[function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("pre",[e._v(" "),n("code",{staticClass:"language-javascript"},[e._v("\n import {\n currencies, // Array of object currencies\n fractionToInt, \n intToFraction, \n displayValue, \n getLocale // Will output a string based upon your local language\n } from 'fp-money'\n ")]),e._v("\n ")])}],O=i["a"].extend({data:function(){return{}},methods:{fractionToInt:function(e,t){return w(e,t)},intToFraction:function(e,t){return E(e,t)},displayValue:function(e,t,n,i){return _(e,t,n,i)},getLocale:function(){return x()}}}),B=O,U=(n("94b9"),Object(u["a"])(B,k,R,!1,null,null,null));U.options.__file="functions.vue";var J=U.exports,N=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"vue"},[n("fpmoney",{attrs:{id:"example",value:"85555",onChange:e.change}}),e._m(0),e._m(1)],1)},Z=[function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("pre",[e._v(" "),n("code",{staticClass:"language-javascript"},[e._v("\n import fpmoney from 'fp-money/dist/fp-money-vue.js'\n\n export default {\n components: { fpmoney },\n methods: {\n change(values: Values) {\n console.log(values)\n }\n }\n }\n ")]),e._v("\n ")])},function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("pre",[e._v(" "),n("code",{staticClass:"language-html"},[e._v('\n <fpmoney value="85555" :onChange="change" />\n ')]),e._v("\n ")])}],L=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{ref:"fpmoney"})},F=[],P=(n("c5f6"),{name:"fp-money",props:{value:[String,Number],currencies:Object,currency:String,locale:String,maxValue:Number,onChange:Function,showSelection:{type:Boolean,default:!0}},data:function(){return{fpmoney:null}},mounted:function(){this.init()},updated:function(){this.fpmoney&&this.fpmoney.destroy(),this.init()},methods:{init:function(){var e={container:this.$refs.fpmoney};this.value&&(e.value=this.value),this.currencies&&(e.currencies=this.currencies),this.currency&&(e.currency=this.currency),this.locale&&(e.locale=this.locale),this.maxValue&&(e.maxValue=this.maxValue),e.showSelection=this.showSelection,this.onChange&&(e.onChange=this.onChange),this.fpmoney=new I(e)}}}),G=P,W=Object(u["a"])(G,L,F,!1,null,null,null);W.options.__file="component.vue";var Y=W.exports,V=i["a"].extend({components:{fpmoney:Y},methods:{change:function(e){console.log(e)}}}),H=V,Q=(n("d57a"),Object(u["a"])(H,N,Z,!1,null,null,null));Q.options.__file="vue.vue";var X=Q.exports;i["a"].use(y["a"]);var z=new y["a"]({mode:"history",routes:[{path:"/",component:j},{path:"/functions",component:J},{path:"/vue",component:X}]}),q=n("c197"),K=n.n(q),$=n("6f35"),ee=n.n($);n("e391"),n("7362");new ee.a({"remove-trailing":!0,"remove-indent":!0,"left-trim":!0,"right-trim":!0}),i["a"].mixin({updated:function(){K.a.highlightAll()}}),i["a"].config.productionTip=!1,new i["a"]({router:z,render:function(e){return e(m)}}).$mount("#app")},d57a:function(e,t,n){"use strict";var i=n("bc8c"),a=n.n(i);a.a},dc22:function(e,t,n){},e637:function(e,t,n){}}); | ||
//# sourceMappingURL=app.js.map |
{ | ||
"name": "fp-money", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "FluidPay input formatter and currency selector", |
import Vue from 'vue' | ||
import Router from 'vue-router' | ||
import HomePage from '@/docs/home.vue' | ||
import FunctionsPage from '@/docs/functions.vue' | ||
import VuePage from '@/docs/vue.vue' | ||
@@ -12,4 +13,5 @@ | ||
{ path: '/', component: HomePage }, | ||
{ path: '/functions', component: FunctionsPage }, | ||
{ path: '/vue', component: VuePage } | ||
] | ||
}) |
@@ -1,30 +0,5 @@ | ||
interface Currencies { | ||
[currency: string]: Currency | ||
} | ||
import { Currencies, currencies, intToFraction, fractionToInt, displayValue, getLocale } from './currencies' | ||
interface Currency { | ||
symbol: string | ||
fraction: number | ||
} | ||
export { currencies, intToFraction, fractionToInt, displayValue, getLocale } | ||
export const currencies: Currencies = { | ||
USD: { symbol: '$', fraction: 2 }, | ||
EUR: { symbol: '€', fraction: 2 }, | ||
GBP: { symbol: '£', fraction: 2 }, | ||
INR: { symbol: '₹', fraction: 2 }, | ||
CRC: { symbol: '₡', fraction: 2 }, | ||
VND: { symbol: '₫', fraction: 0 }, | ||
HUF: { symbol: 'Ft', fraction: 2 }, | ||
ILS: { symbol: '₪', fraction: 2 }, | ||
CNY: { symbol: '¥', fraction: 2 }, | ||
KRW: { symbol: '₩', fraction: 0 }, | ||
NGN: { symbol: '₦', fraction: 2 }, | ||
PYG: { symbol: '₲', fraction: 0 }, | ||
PHP: { symbol: '₱', fraction: 2 }, | ||
PLN: { symbol: 'zł', fraction: 2 }, | ||
THB: { symbol: '฿', fraction: 2 }, | ||
UAH: { symbol: '₴', fraction: 2 }, | ||
JPY: { symbol: '¥', fraction: 0 } | ||
} | ||
export interface Values { | ||
@@ -41,4 +16,6 @@ value: string | ||
value?: string | number | ||
currencies?: Currencies | ||
currency?: string | ||
locale?: string | ||
maxValue?: number | ||
showSelection?: boolean | ||
@@ -48,33 +25,2 @@ onChange: (values: Values) => void | ||
export function lowestCommonToFormat(val: string | number, fraction: number = 2): string { | ||
val = val.toString() | ||
// Create divide first | ||
let divide = '1' | ||
for (let i = 0; i < fraction; i++) { divide += '0'} | ||
const divideInt = parseInt(divide, 10) | ||
// If val includes . lets multiply it first | ||
if (val.indexOf('.') !== -1) { | ||
val = (parseFloat(val) * divideInt).toString() | ||
} | ||
// If fraction is 0 parseInt and return it | ||
if (fraction === 0) { return parseInt(val, 10).toString() } | ||
return (parseInt(val, 10) / divideInt).toFixed(fraction) | ||
} | ||
export function formatToLowestCommon(val: string | number, fraction: number = 2): string { | ||
const valStr = val.toString() | ||
let multi = '1' | ||
for (let i = 0; i < fraction; i++) { multi += '0'} | ||
const multiInt = parseInt(multi, 10) | ||
const valFloat = (parseFloat(valStr) * multiInt).toString() | ||
return parseInt(valFloat, 10).toString() | ||
} | ||
export default class FPMoney { | ||
@@ -90,4 +36,6 @@ public container: HTMLDivElement | ||
public format: string = '' | ||
public currency: string = 'USD' | ||
public locale: string = this.getLocale() | ||
public currencies: Currencies = JSON.parse(JSON.stringify(currencies)) | ||
public currency: string = '' // default is set in the constructor | ||
public locale: string = getLocale() | ||
public maxValue: number = 0 | ||
public showSelection: boolean = true | ||
@@ -111,5 +59,7 @@ | ||
// Set values | ||
if (info.currency) {this.currency = info.currency.toUpperCase()} | ||
if (info.currencies) {this.currencies = info.currencies} | ||
if (info.currency) {this.currency = info.currency.toUpperCase()} else {this.currency = Object.keys(this.currencies)[0]} | ||
if (info.locale) {this.locale = info.locale} | ||
if (info.value) {this.value = formatToLowestCommon(info.value, currencies[this.currency].fraction)} | ||
if (info.value) {this.value = fractionToInt(info.value, this.currencies[this.currency].fraction).toString()} | ||
if (info.maxValue) {this.maxValue = fractionToInt(info.maxValue, this.currencies[this.currency].fraction)} | ||
if (info.showSelection !== undefined) {this.showSelection = info.showSelection} | ||
@@ -135,6 +85,6 @@ | ||
// Currency display | ||
this.currencyDiv.innerHTML = currencies[currency].symbol | ||
this.currencyDiv.innerHTML = this.currencies[currency].symbol | ||
// Input display | ||
const fraction = currencies[currency].fraction | ||
const fraction = this.currencies[currency].fraction | ||
let multi = '' | ||
@@ -160,32 +110,2 @@ for (let i = 0; i < fraction; i++) { | ||
public displayValue(): string { | ||
const fraction = currencies[this.currency.toUpperCase()].fraction | ||
const formatter = new Intl.NumberFormat(this.locale, { | ||
localeMatcher: 'best fit', | ||
style: 'currency', | ||
currency: this.currency.toUpperCase(), | ||
currencyDisplay: 'symbol', | ||
minimumFractionDigits: fraction, | ||
maximumFractionDigits: fraction | ||
}) | ||
return formatter.format(parseFloat(this.formatValue())) | ||
} | ||
public formatValue(): string { | ||
const val = (this.value === '' ? '0' : this.value) // Lets make sure value is at least a | ||
const fraction = currencies[this.currency.toUpperCase()].fraction | ||
if (fraction === 0) { return val } | ||
let divide = '1' | ||
for (let i = 0; i < fraction; i++) { | ||
divide += '0' | ||
} | ||
const divideInt = parseInt(divide, 10) | ||
return (parseInt(val, 10) / divideInt).toFixed(fraction) | ||
} | ||
public destroy() { | ||
@@ -206,20 +126,13 @@ // Clean out container | ||
private updateInputDisplay() { | ||
if (this.value === '') { this.input.value = ''; return } | ||
private updateOutput() { | ||
if (this.value !== '') { | ||
let val = parseInt(this.value, 10) | ||
// Limit if max | ||
if (this.maxValue !== 0 && val > this.maxValue) {val = this.maxValue} | ||
this.value = val.toString() | ||
} | ||
// Clean display output | ||
let clean = this.display.replace(currencies[this.currency.toUpperCase()].symbol, '') // Remove symbol | ||
const cur = this.currency | ||
cur.split('').forEach((c, i) => { | ||
clean = clean.replace(cur.substring(0, cur.length - i), '') | ||
}) | ||
clean = clean.trim() // Remove whitespace | ||
this.input.value = clean | ||
} | ||
this.format = intToFraction(this.value, this.currencies[this.currency].fraction).toFixed(this.currencies[this.currency].fraction) | ||
this.display = displayValue(this.value, this.currency, this.currencies[this.currency].fraction, this.locale) | ||
private updateOutput() { | ||
this.value = (this.value === '' ? '' : parseInt(this.value, 10).toString()) | ||
this.format = this.formatValue() | ||
this.display = this.displayValue() | ||
this.updateInputDisplay() | ||
@@ -237,2 +150,16 @@ | ||
private updateInputDisplay() { | ||
if (this.value === '') { this.input.value = ''; return } | ||
// Clean display output | ||
let clean = this.display.replace(this.currencies[this.currency.toUpperCase()].symbol, '') // Remove symbol | ||
const cur = this.currency | ||
clean = clean.replace(cur, '') | ||
cur.split('').forEach((c, i) => { | ||
clean = clean.replace(cur.substring(0, cur.length - i), '') | ||
}) | ||
clean = clean.trim() // Remove whitespace | ||
this.input.value = clean | ||
} | ||
private render() { | ||
@@ -253,4 +180,4 @@ // Add classes | ||
// Add options to select | ||
for (const c in currencies) { | ||
if (currencies.hasOwnProperty(c)) { | ||
for (const c in this.currencies) { | ||
if (this.currencies.hasOwnProperty(c)) { | ||
const option = document.createElement('option') | ||
@@ -276,9 +203,8 @@ option.value = c | ||
private inputKeydown(evt: KeyboardEvent) { | ||
evt.preventDefault() // Disable normal operations | ||
const charCode = evt.keyCode || evt.which | ||
// If delete | ||
if (charCode === 8 || charCode === 46) { | ||
// Add key to value | ||
if (charCode === 8 || charCode === 46) { // If delete | ||
evt.preventDefault() // Disable normal operations | ||
// Remove key from value | ||
this.value = this.value.substring(0, this.value.length - 1) | ||
@@ -288,13 +214,15 @@ | ||
this.updateOutput() | ||
return | ||
} | ||
} else if ((charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105)) { // If hitting 0-9 | ||
evt.preventDefault() // Disable normal operations | ||
// If hitting 0-9 | ||
if (charCode >= 48 && charCode <= 57) { | ||
// Add key to value | ||
this.value += String.fromCharCode(charCode) | ||
this.value += evt.key | ||
// Update display in input field | ||
this.updateOutput() | ||
return | ||
} else if (charCode === 9 || charCode === 13) { | ||
// Tab or enter let it operate normally | ||
} else { | ||
// Disable normal operations | ||
evt.preventDefault() | ||
} | ||
@@ -313,13 +241,2 @@ } | ||
} | ||
// Try to identify the users locale - default en | ||
private getLocale(): string { | ||
if (navigator.languages !== undefined) { | ||
return navigator.languages[0] | ||
} else if (navigator.language) { | ||
return navigator.language | ||
} else { | ||
return 'en' | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1126672
51
3188