index.js
/**
 * Verify that number has the expected size and that it has a valid luhn signature
 * Special case for La Poste SIRET
 * @param {string} number
 * @param {number} size
 * @returns {boolean}
 */
Verify that number has the expected size and that it has a valid luhn signature
Special case for La Poste SIRET
@param {string} number
@param {number} size
@returns {boolean}
Verify that number has the expected size and that it has a valid luhn signature Special case for La Poste SIRET @param { string } number @param { number } size @returns { boolean }
function verify(number, size) {
    if (typeof number !== 'string') {
        number = String(number)
    }
    if (isNaN(number) || number.length !== size) {
        return false;
    }
    let bal = 0;
    let total = 0;
    if (size === 14 && number.slice(0, 9) === '356000000' && number !== '35600000000048') {
        for (let i = 0; i < size; i++) {
            total += parseInt(number.charAt(i), 10);
        }
        return total % 5 === 0;
    }
    for (let i = size-1; i >= 0; i--) {
        const step = (number.charCodeAt(i) - 48) * (bal + 1);
        total += (step > 9) ? step - 9 : step;
        bal = 1 - bal;
    }
    return total % 10 === 0;
}
function verify ( number , size ) { if ( typeof number !== 'string' ) { number = String ( number ) } if ( isNaN ( number ) || number . length !== size ) { return false ; } let bal = 0 ; let total = 0 ; if ( size === 14 && number . slice ( 0 , 9 ) === '356000000' && number !== '35600000000048' ) { for ( let i = 0 ; i < size ; i ++ ) { total += parseInt ( number . charAt ( i ) , 10 ) ; } return total % 5 === 0 ; } for ( let i = size - 1 ; i >= 0 ; i -- ) { const step = ( number . charCodeAt ( i ) - 48 ) * ( bal + 1 ) ; total += ( step > 9 ) ? step - 9 : step ; bal = 1 - bal ; } return total % 10 === 0 ; }
Verify that number has the expected size and that it has a valid luhn signature
 Special case for La Poste SIRET
 @param {string} number
 @param {number} size
 @returns {boolean}
Verify that number has the expected size and that it has a valid luhn signature Special case for La Poste SIRET @param { string } number @param { number } size @returns { boolean }
// Special case: La Poste has 12,564 Siret numbers, so we check against the sum of all numbers % 5 instead of luhn // 35600000000048 is the main SIRET number and is a normal number. // Luhn algorithm