mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-22 04:21:44 +00:00
chore: drop NumberPolyfill
it is no longer used from anywhere and we now have a much better and more flexible LocaleUtils
This commit is contained in:
parent
04183a6271
commit
1eeb1a34f9
@ -1,157 +0,0 @@
|
|||||||
.pragma library
|
|
||||||
// polyfill.number.toLocaleDateString
|
|
||||||
// Copied from: https://github.com/willsp/polyfill-Number.toLocaleString-with-Locales
|
|
||||||
// Got this from MDN:
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Example:_Checking_for_support_for_locales_and_options_arguments
|
|
||||||
function toLocaleStringSupportsLocales() {
|
|
||||||
var number = 0;
|
|
||||||
try {
|
|
||||||
number.toLocaleString("i");
|
|
||||||
} catch (e) {
|
|
||||||
return e.name === "RangeError";
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var replaceSeparators = function(sNum, separators) {
|
|
||||||
var sNumParts = sNum.split('.');
|
|
||||||
if (separators && separators.thousands) {
|
|
||||||
sNumParts[0] = sNumParts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + separators.thousands);
|
|
||||||
}
|
|
||||||
sNum = sNumParts.join(separators.decimal);
|
|
||||||
|
|
||||||
return sNum;
|
|
||||||
};
|
|
||||||
|
|
||||||
var mapMatch = function(map, locale) {
|
|
||||||
var match = locale;
|
|
||||||
var language = locale && locale.toLowerCase().match(/^\w+/);
|
|
||||||
|
|
||||||
if (!map.hasOwnProperty(locale)) {
|
|
||||||
if (map.hasOwnProperty(language)) {
|
|
||||||
match = language;
|
|
||||||
} else {
|
|
||||||
match = "en";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return map[match];
|
|
||||||
};
|
|
||||||
|
|
||||||
var dotThousCommaDec = function(sNum) {
|
|
||||||
var separators = {
|
|
||||||
decimal: ',',
|
|
||||||
thousands: '.'
|
|
||||||
};
|
|
||||||
|
|
||||||
return replaceSeparators(sNum, separators);
|
|
||||||
};
|
|
||||||
|
|
||||||
var commaThousDotDec = function(sNum) {
|
|
||||||
var separators = {
|
|
||||||
decimal: '.',
|
|
||||||
thousands: ','
|
|
||||||
};
|
|
||||||
|
|
||||||
return replaceSeparators(sNum, separators);
|
|
||||||
};
|
|
||||||
|
|
||||||
var spaceThousCommaDec = function(sNum) {
|
|
||||||
var seperators = {
|
|
||||||
decimal: ',',
|
|
||||||
thousands: '\u00A0'
|
|
||||||
};
|
|
||||||
|
|
||||||
return replaceSeparators(sNum, seperators);
|
|
||||||
};
|
|
||||||
|
|
||||||
var apostrophThousDotDec = function(sNum) {
|
|
||||||
var seperators = {
|
|
||||||
decimal: '.',
|
|
||||||
thousands: '\u0027'
|
|
||||||
};
|
|
||||||
|
|
||||||
return replaceSeparators(sNum, seperators);
|
|
||||||
};
|
|
||||||
|
|
||||||
var transformForLocale = {
|
|
||||||
en: commaThousDotDec,
|
|
||||||
'en-GB': commaThousDotDec,
|
|
||||||
'en-US': commaThousDotDec,
|
|
||||||
it: dotThousCommaDec,
|
|
||||||
fr: spaceThousCommaDec,
|
|
||||||
de: dotThousCommaDec,
|
|
||||||
"de-DE": dotThousCommaDec,
|
|
||||||
"de-AT": dotThousCommaDec,
|
|
||||||
"de-CH": apostrophThousDotDec,
|
|
||||||
"de-LI": apostrophThousDotDec,
|
|
||||||
"de-BE": dotThousCommaDec,
|
|
||||||
"nl": dotThousCommaDec,
|
|
||||||
"nl-BE": dotThousCommaDec,
|
|
||||||
"nl-NL": dotThousCommaDec,
|
|
||||||
ro: dotThousCommaDec,
|
|
||||||
"ro-RO": dotThousCommaDec,
|
|
||||||
ru: spaceThousCommaDec,
|
|
||||||
"ru-RU": spaceThousCommaDec,
|
|
||||||
hu: spaceThousCommaDec,
|
|
||||||
"hu-HU": spaceThousCommaDec,
|
|
||||||
"da-DK": dotThousCommaDec,
|
|
||||||
"nb-NO": spaceThousCommaDec
|
|
||||||
};
|
|
||||||
|
|
||||||
var currencyFormatMap = {
|
|
||||||
en: "pre",
|
|
||||||
'en-GB': "pre",
|
|
||||||
'en-US': "pre",
|
|
||||||
it: "post",
|
|
||||||
fr: "post",
|
|
||||||
de: "post",
|
|
||||||
"de-DE": "post",
|
|
||||||
"de-AT": "prespace",
|
|
||||||
"de-CH": "prespace",
|
|
||||||
"de-LI": "post",
|
|
||||||
"de-BE": "post",
|
|
||||||
"nl": "post",
|
|
||||||
"nl-BE": "post",
|
|
||||||
"nl-NL": "post",
|
|
||||||
ro: "post",
|
|
||||||
"ro-RO": "post",
|
|
||||||
ru: "post",
|
|
||||||
"ru-RU": "post",
|
|
||||||
hu: "post",
|
|
||||||
"hu-HU": "post",
|
|
||||||
"da-DK": "post",
|
|
||||||
"nb-NO": "post"
|
|
||||||
};
|
|
||||||
|
|
||||||
function toLocaleString(val, locale, options) {
|
|
||||||
if (locale && locale.length < 2)
|
|
||||||
throw new RangeError("Invalid language tag: " + locale);
|
|
||||||
|
|
||||||
var sNum;
|
|
||||||
|
|
||||||
if (options && (options.minimumFractionDigits || options.minimumFractionDigits === 0)) {
|
|
||||||
sNum = Number(val).toFixed(options.minimumFractionDigits);
|
|
||||||
} else {
|
|
||||||
sNum = Number(val).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
sNum = mapMatch(transformForLocale, locale)(sNum, options);
|
|
||||||
|
|
||||||
if(options && options.currency) {
|
|
||||||
sNum = convertToInternationalCurrencySystem(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sNum;
|
|
||||||
};
|
|
||||||
|
|
||||||
function convertToInternationalCurrencySystem (val) {
|
|
||||||
// Nine 0's - Billions
|
|
||||||
return Math.abs(Number(val)) >= 1.0e+9
|
|
||||||
? (Math.abs(Number(val)) / 1.0e+9).toFixed(2) + "B"
|
|
||||||
// Six 0's - Millions
|
|
||||||
: Math.abs(Number(val)) >= 1.0e+6
|
|
||||||
? (Math.abs(Number(val)) / 1.0e+6).toFixed(2) + "M"
|
|
||||||
: Math.abs(Number(val));
|
|
||||||
}
|
|
||||||
|
|
@ -3,4 +3,3 @@ module shared
|
|||||||
DelegateModelGeneralized 1.0 DelegateModelGeneralized.qml
|
DelegateModelGeneralized 1.0 DelegateModelGeneralized.qml
|
||||||
LoadingAnimation 1.0 LoadingAnimation.qml
|
LoadingAnimation 1.0 LoadingAnimation.qml
|
||||||
MacTrafficLights 1.0 MacTrafficLights.qml
|
MacTrafficLights 1.0 MacTrafficLights.qml
|
||||||
NumberPolyFill 1.0 PolyfillNumberToLocaleString.js
|
|
||||||
|
@ -132,14 +132,6 @@ QtObject {
|
|||||||
return addr.substring(0, 2 + numberOfChars) + "..." + addr.substring(addr.length - numberOfChars);
|
return addr.substring(0, 2 + numberOfChars) + "..." + addr.substring(addr.length - numberOfChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toLocaleString(val, locale, options) {
|
|
||||||
if (typeof(val) === "object") {
|
|
||||||
console.log("Wrong type for val: " + JSON.stringify(val))
|
|
||||||
return NaN
|
|
||||||
}
|
|
||||||
return NumberPolyFill.toLocaleString(val, locale, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isOnlyEmoji(inputText) {
|
function isOnlyEmoji(inputText) {
|
||||||
var emoji_regex = /^(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|[\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c[\ude32-\ude3a]|[\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff]|\s)+$/;
|
var emoji_regex = /^(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|[\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|[\ud83c[\ude32-\ude3a]|[\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff]|\s)+$/;
|
||||||
return emoji_regex.test(inputText);
|
return emoji_regex.test(inputText);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user