function isSafeNumber(val) {
    var num = val;
    var type = typeof val;
    if (type === typeOfString) {
        var length = val.length;
        // Number.MIN_SAFE_INTEGER is 17 digits including the sign.
        // Anything longer cannot be safe.
        if (length === 0 || length > MIN_SAFE_INTEGER_DIGITS) {
            return false;
        }
        if (!safeNumberRegEx.test(val)) {
            return false;
        }
        // Number.MAX_SAFE_INTEGER is 16 digits.
        // Anything shorter must be safe.
        if (length < MAX_SAFE_INTEGER_DIGITS) {
            return true;
        }
        num = +val;
    } else if (type !== typeOfNumber) {
        return false;
    }
    // Number.isSafeInteger(num) in es6.
    return num % 1 === 0 && abs(num) <= MAX_SAFE_INTEGER;
}
Return true if argument is a number or can be cast to a number which
roundtrips to the same string.
@private