1 declare module "specificity" {
3 namespace specificity {
5 * Specificity arrays always have 4 numbers (integers) for quick comparison
6 * comparing from left to right, the next number only has to be checked if
7 * two numbers of the same index are equal.
9 type SpecificityArray = [number, number, number, number];
12 * A result of parsing a selector into an array of parts.
13 * Calculating a specificity array is a matter of summing
14 * over all the parts and adding the values to the right
15 * bucket in a specificity array.
21 type: "a" | "b" | "c";
26 * Returned by the calculate function. Represents the results
27 * of parsing and calculating the specificity of a selector.
29 * @interface Specificity
31 interface Specificity {
34 specificityArray: SpecificityArray;
38 * Calculates the specificity for the given selector string.
39 * If the string contains a comma, each selector will be parsed
42 * @returns A list of specificity objects one for each selector in the
45 function calculate(selector: string): Array<Specificity>;
48 * Compares two selectors. If a string, the string cannot contain a comma.
50 * @returns A value less than 0 if selector a is less specific than selector b.
51 * A value more than 0 if selector a is more specific than selector b.
52 * 0 if the two selectors have the same specificity.
54 function compare(a: string | SpecificityArray, b: string | SpecificityArray): -1 | 0 | 1;