extension/script.js
/**
 * Extracts a twitter-formatted number from any locale that does not use a dot as the decimal separator.
 * @param text {string} The text to parse
 * @param amplifiers {[number | null, number | null]} Amplifier strings used for abbreviated numbers.
 * @return {number} The extracted value.
 */
Extracts a twitter-formatted number from any locale that does not use a dot as the decimal separator.
@param text {string} The text to parse
@param amplifiers {[number | null, number | null]} Amplifier strings used for abbreviated numbers.
@return {number} The extracted value.
Extracts a twitter - formatted number from any locale that does not use a dot as the decimal separator . @param text { string } The text to parse @param amplifiers { [ number | null number | null ] } Amplifier strings used for abbreviated numbers . @return { number } The extracted value .
function extractNumberFormatGeneral(text, amplifiers) {
    text = text.replace(/[\.\s]/g, "");
    const amplifierMap = {
        [amplifiers[0]]: 1000,
        [amplifiers[1]]: 1000000
    };
    const amplifiersString = amplifiers.filter(el => !!el).join("|");
    const matchResults = new RegExp(`([0-9]+(,[0-9]+)?)(${amplifiersString})?`, "g")
        .exec(text);
    let num = parseFloat(matchResults[1].replace(/,/g, "."));
    const amplifier = amplifierMap[matchResults[3]];
    if (amplifier) num *= amplifier;
    return num;
}
function extractNumberFormatGeneral ( text , amplifiers ) { text = text . replace ( / [\.\s] / g , "" ) ; const amplifierMap = { [ amplifiers [ 0 ] ] : 1000 , [ amplifiers [ 1 ] ] : 1000000 } ; const amplifiersString = amplifiers . filter ( el => ! ! el ) . join ( "|" ) ; const matchResults = new RegExp ( ` ${ amplifiersString } ` , "g" ) . exec ( text ) ; let num = parseFloat ( matchResults [ 1 ] . replace ( / , / g , "." ) ) ; const amplifier = amplifierMap [ matchResults [ 3 ] ] ; if ( amplifier ) num *= amplifier ; return num ; }
Extracts a twitter-formatted number from any locale that does not use a dot as the decimal separator.
Extracts a twitter - formatted number from any locale that does not use a dot as the decimal separator .