index.js
function getSpecificity(text, parsed) {
    var expressions = parsed || parse(text),
        spec = [ 0, 0, 0, 0 ],
        nots = [],
        i,
        expression,
        pseudos,
        p,
        ii,
        not,
        jj;

    for (i = 0; i < expressions.length; i++) {
        expression = expressions[i];
        pseudos = expression.pseudos;

        // id awards a point in the second column
        if (expression.id) {
            spec[1]++;
        }

        // classes and attributes award a point each in the third column
        if (expression.attributes) {
            spec[2] += expression.attributes.length;
        }
        if (expression.classList) {
            spec[2] += expression.classList.length;
        }

        // tag awards a point in the fourth column
        if (expression.tag && expression.tag !== '*') {
            spec[3]++;
        }

        // pseudos award a point each in the fourth column
        if (pseudos) {
            spec[3] += pseudos.length;

            for (p = 0; p < pseudos.length; p++) {
                if (pseudos[p].key === 'not') {
                    nots.push(pseudos[p].value);
                    spec[3]--;
                }
            }
        }
    }

    for (ii = nots.length; ii--;) {
        not = getSpecificity(nots[ii]);
        for (jj = 4; jj--;) {
            spec[jj] += not[jj];
        }
    }

    return spec;
}
function getSpecificity(text, parsed) {
    var expressions = parsed || parse(text),
        spec = [ 0, 0, 0, 0 ],
        nots = [],
        i,
        expression,
        pseudos,
        p,
        ii,
        not,
        jj;

    for (i = 0; i < expressions.length; i++) {
        expression = expressions[i];
        pseudos = expression.pseudos;

        // id awards a point in the second column
        if (expression.id) {
            spec[1]++;
        }

        // classes and attributes award a point each in the third column
        if (expression.attributes) {
            spec[2] += expression.attributes.length;
        }
        if (expression.classList) {
            spec[2] += expression.classList.length;
        }

        // tag awards a point in the fourth column
        if (expression.tag && expression.tag !== '*') {
            spec[3]++;
        }

        // pseudos award a point each in the fourth column
        if (pseudos) {
            spec[3] += pseudos.length;

            for (p = 0; p < pseudos.length; p++) {
                if (pseudos[p].key === 'not') {
                    nots.push(pseudos[p].value);
                    spec[3]--;
                }
            }
        }
    }

    for (ii = nots.length; ii--;) {
        not = getSpecificity(nots[ii]);
        for (jj = 4; jj--;) {
            spec[jj] += not[jj];
        }
    }

    return spec;
}
function getSpecificity ( text , parsed ) { var expressions = parsed || parse ( text ) , spec = [ 0 , 0 , 0 , 0 ] , nots = [ ] , i , expression , pseudos , p , ii , not , jj ; for ( i = 0 ; i < expressions . length ; i ++ ) { expression = expressions [ i ] ; pseudos = expression . pseudos ; // id awards a point in the second column if ( expression . id ) { spec [ 1 ] ++ ; } // classes and attributes award a point each in the third column if ( expression . attributes ) { spec [ 2 ] += expression . attributes . length ; } if ( expression . classList ) { spec [ 2 ] += expression . classList . length ; } // tag awards a point in the fourth column if ( expression . tag && expression . tag !== '*' ) { spec [ 3 ] ++ ; } // pseudos award a point each in the fourth column if ( pseudos ) { spec [ 3 ] += pseudos . length ; for ( p = 0 ; p < pseudos . length ; p ++ ) { if ( pseudos [ p ] . key === 'not' ) { nots . push ( pseudos [ p ] . value ) ; spec [ 3 ] -- ; } } } } for ( ii = nots . length ; ii -- ; ) { not = getSpecificity ( nots [ ii ] ) ; for ( jj = 4 ; jj -- ; ) { spec [ jj ] += not [ jj ] ; } } return spec ; }
Returns specificity based on selector text and tokens.

@param {String} selector
@param {Array} tokens
@api private.
Returns specificity based on selector text and tokens .