Here is a function which does that, it can probably be written much shorter and better but this is what I came up with:
const formatNumber = (number, decimals = 2, floatSeparator = '.', separator = ',') => {
    let stringified = number.toString();
    let [ decimal, float ] = stringified.split('.');
    let result = "";
    if(decimal.length > 3) {
        decimal = decimal.split("").reverse();
        for(let i = 0; i < decimal.length; i++) {
            result += decimal[i];
            if((i + 1)%3 === 0 && i !== decimal.length - 1) {
                result += separator;
            }
        }
    }
    result = result.split("").reverse().join("");
    if(float) {
        result += floatSeparator;
        if(float.length >= decimals) {
            for(let i = 0; i < decimals; i++) {
                result += float[i];
            }
        }
        else {
            for(let i = 0; i < decimals; i++) {
                if(i < float.length) {
                    result += float[i];
                }
                else {
                    result += '0';
                }
            }
        }
    }
    return result;
}
let n1 = 1000;
let n2 = 1000.5;
console.log(formatNumber(n1)); // 1,000
console.log(formatNumber(n2)); // 1,000.50