Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../assets/js
File: nfLocaleConverter.js
// const Intl = require('intl');
[0] Fix | Delete
[1] Fix | Delete
// class nfLocaleConverter {
[2] Fix | Delete
var nfLocaleConverter = function(newLocale, thousands_sep, decimal_sep) {
[3] Fix | Delete
[4] Fix | Delete
// constructor(newLocale = 'en-US', thousands_sep, decimal_sep) {
[5] Fix | Delete
if ('undefined' !== typeof newLocale && 0 < newLocale.length) {
[6] Fix | Delete
this.locale = newLocale.split('_').join('-');
[7] Fix | Delete
} else {
[8] Fix | Delete
this.locale = 'en-US';
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
this.thousands_sep = thousands_sep || ',';
[12] Fix | Delete
this.decimal_sep = decimal_sep || '.';
[13] Fix | Delete
// }
[14] Fix | Delete
[15] Fix | Delete
this.uniqueElememts = function( value, index, self ) {
[16] Fix | Delete
return self.indexOf(value) === index;
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
this.numberDecoder = function(num) {
[20] Fix | Delete
num = num.toString();
[21] Fix | Delete
// let thousands_sep = ',';
[22] Fix | Delete
var formatted = '';
[23] Fix | Delete
[24] Fix | Delete
// Account for negative numbers.
[25] Fix | Delete
var negative = false;
[26] Fix | Delete
[27] Fix | Delete
if ('-' === num.charAt(0)) {
[28] Fix | Delete
negative = true;
[29] Fix | Delete
num = num.replace( '-', '' );
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
// Account for a space as the thousands separator.
[33] Fix | Delete
// This pattern accounts for all whitespace characters (including thin space).
[34] Fix | Delete
num = num.replace( /\s/g, '' );
[35] Fix | Delete
num = num.replace( /&nbsp;/g, '' );
[36] Fix | Delete
[37] Fix | Delete
// Determine what our existing separators are.
[38] Fix | Delete
var myArr = num.split('');
[39] Fix | Delete
var separators = myArr.filter(function(el) {
[40] Fix | Delete
return !el.match(/[0-9]/);
[41] Fix | Delete
});
[42] Fix | Delete
[43] Fix | Delete
var final_separators = separators.filter(this.uniqueElememts);
[44] Fix | Delete
[45] Fix | Delete
switch( final_separators.length ) {
[46] Fix | Delete
case 0:
[47] Fix | Delete
formatted = num;
[48] Fix | Delete
break;
[49] Fix | Delete
case 1:
[50] Fix | Delete
var replacer = '';
[51] Fix | Delete
if ( 1 == separators.length ) {
[52] Fix | Delete
separator = separators.pop();
[53] Fix | Delete
var sides = num.split(separator);
[54] Fix | Delete
var last = sides.pop();
[55] Fix | Delete
if ( 3 == last.length && separator == this.thousands_sep ) {
[56] Fix | Delete
replacer = '';
[57] Fix | Delete
} else {
[58] Fix | Delete
replacer = '.';
[59] Fix | Delete
}
[60] Fix | Delete
} else {
[61] Fix | Delete
separator = final_separators.pop();
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
formatted = num.split(separator).join(replacer);
[65] Fix | Delete
break;
[66] Fix | Delete
case 2:
[67] Fix | Delete
var find_one = final_separators[0];
[68] Fix | Delete
var re_one;
[69] Fix | Delete
if('.' === find_one) {
[70] Fix | Delete
re_one = new RegExp('[.]', 'g');
[71] Fix | Delete
} else {
[72] Fix | Delete
re_one = new RegExp(find_one, 'g');
[73] Fix | Delete
}
[74] Fix | Delete
formatted = num.replace(re_one, '');
[75] Fix | Delete
[76] Fix | Delete
var find_two = final_separators[1];
[77] Fix | Delete
[78] Fix | Delete
var re_two;
[79] Fix | Delete
if('.' === find_two) {
[80] Fix | Delete
re_two = new RegExp('[.]', 'g');
[81] Fix | Delete
} else {
[82] Fix | Delete
re_two = new RegExp(find_two, 'g');
[83] Fix | Delete
}
[84] Fix | Delete
formatted = formatted.replace(re_two, '.' );
[85] Fix | Delete
break;
[86] Fix | Delete
default:
[87] Fix | Delete
return 'NaN';
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
if ( negative ) {
[91] Fix | Delete
formatted = '-' + formatted;
[92] Fix | Delete
}
[93] Fix | Delete
this.debug('Number Decoder ' + num + ' -> ' + formatted );
[94] Fix | Delete
return formatted;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
this.numberEncoder = function(num, percision) {
[98] Fix | Delete
num = this.numberDecoder(num);
[99] Fix | Delete
[100] Fix | Delete
return Intl.NumberFormat(this.locale, { minimumFractionDigits: percision, maximumFractionDigits: percision }).format(num);
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
this.debug = function(message) {
[104] Fix | Delete
if ( window.nfLocaleConverterDebug || false ) console.log(message);
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
// module.exports = nfLocaleConverter;
[109] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function