Skip to content

Commit

Permalink
Fix export of compareSpecificity (#333)
Browse files Browse the repository at this point in the history
fixes #323
  • Loading branch information
bartveneman authored Jun 10, 2023
1 parent 1a0900b commit d4a8d6f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
16 changes: 10 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
"mangle": {
"regex": "^_[^_]"
}
}
}
2 changes: 1 addition & 1 deletion src/context-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ContextCollection {
* @type {Map<string, {
* total: number,
* totalUnique: number,
* unique: {[string]: number},
* unique: {[k: string]: number},
* uniquenessRatio: number
* }>}
*/
Expand Down
25 changes: 19 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import parse from 'css-tree/parser'
import walk from 'css-tree/walker'
import { calculate } from '@bramus/specificity/core'
import { isSupportsBrowserhack, isMediaBrowserhack } from './atrules/atrules.js'
import { getComplexity, isAccessibility, compareSpecificity } from './selectors/utils.js'
import { getComplexity, isAccessibility } from './selectors/utils.js'
import { colorFunctions, colorKeywords, namedColors, systemColors } from './values/colors.js'
import { destructure, isSystemFont } from './values/destructure-font-shorthand.js'
import { isValueKeyword } from './values/values.js'
Expand All @@ -28,7 +28,7 @@ function ratio(part, total) {
* Analyze CSS
* @param {string} css
*/
function analyze(css) {
export function analyze(css) {
let start = Date.now()

/**
Expand Down Expand Up @@ -749,7 +749,20 @@ function analyze(css) {
}
}

export {
analyze,
compareSpecificity,
}
/**
* Compare specificity A to Specificity B
* @param {Specificity} a - Specificity A
* @param {Specificity} b - Specificity B
* @returns {number} sortIndex - 0 when a==b, 1 when a<b, -1 when a>b
*/
export function compareSpecificity(a, b) {
if (a[0] === b[0]) {
if (a[1] === b[1]) {
return b[2] - a[2]
}

return b[1] - a[1]
}

return b[0] - a[0]
}
18 changes: 0 additions & 18 deletions src/selectors/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,6 @@ import walk from 'css-tree/walker'
import { startsWith, strEquals } from '../string-utils.js'
import { hasVendorPrefix } from '../vendor-prefix.js'

/**
* Compare specificity A to Specificity B
* @param {[number,number,number]} a - Specificity A
* @param {[number,number,number]} b - Specificity B
* @returns {number} sortIndex - 0 when a==b, 1 when a<b, -1 when a>b
*/
export function compareSpecificity(a, b) {
if (a[0] === b[0]) {
if (a[1] === b[1]) {
return b[2] - a[2]
}

return b[1] - a[1]
}

return b[0] - a[0]
}

/**
*
* @param {import('css-tree').SelectorList} selectorListAst
Expand Down

0 comments on commit d4a8d6f

Please sign in to comment.