Javascript: How to convert an existing callback API to promises

Promise returning functions should never throw, they should return rejections instead. Throwing from a promise returning function will force you to use both a } catch { and a .catch. People using promisified APIs do not expect promises to throw.

// Before promises
function divisionAPI (number, divider, successCallback, errorCallback) {
    if (divider == 0){
        return errorCallback( new Error("Division by zero") )
    }    
        
    successCallback( number / divider )
}


// After promises
function divisionAPI (number, divider) {

    return new Promise(function (fulfilled, rejected) {
        if (divider == 0) {
            return rejected( new Error("Division by zero") )
        }
        fulfilled( number / divider )
     })
}