Skip to content

Releases: bramus/specificity

2.3.0 (2023.04.08)

08 Apr 09:58
Compare
Choose a tag to compare

Changes & Additions

  • ✨ Add view-transition specificity calculation
  • 🐛 Do not throw when :is/:any/:matches do not contain children
  • 🐛 Fix case sensitivity issue

Thanks to @bartveneman for contributing these changes and additions.

2.2.0 (2022.12.14)

14 Dec 20:44
Compare
Choose a tag to compare

Changes & Additions

  • ✨ Support ::slotted()
  • ✨ Support :host() and :host-context()

2.1.0 (2022.04.01)

01 Apr 21:07
Compare
Choose a tag to compare

Changes & Additions

  • ✨ Also accept single CSSTree Selector ASTs as input into calculate

2.0.0 (2022.03.30)

29 Mar 22:09
Compare
Choose a tag to compare

The main change in this next iteration of @bramus/specificity is that everything is now exposed as part of a newly introduced Specificity class. The class represents specificity value, and also holds several static methods to calculate and work with specificities.

@bramus/specificity example

Changes & Additions

  • ✨ Introduce and use a Specificity class
  • ✨ Support SelectorLists
  • ♻️ Import only selector-parser from css-tree (reducing bundle size)
  • ✨ Expose new utility functions for comparing, sorting, and filtering (static or standalone)
  • ✨ Add Type Definitions
  • ✨ Expose the CLI script
  • 🚑 Fix CJS build

Code Example

import Specificity from '@bramus/specificity';

// ✨ Calculate specificity for each Selector in the given Selector List
const specificities = Specificity.calculate('header:where(#top) nav li:nth-child(2n), #doormat');

// 🚚 The values in the array are instances of the Specificity class
const specificity = specificities[0]; // Instance of Specificity

// 🛠 From an instance you can get the value in various formats
specificity.value; // { a: 0, b: 1, c: 3 }
specificity.a; // 0
specificity.b; // 1
specificity.c; // 3
specificity.toString(); // "(0,1,3)"
specificity.toArray(); // [0, 1, 3]
specificity.toObject(); // { a: 0, b: 1, c: 3 }

// 💡 From an instance you can also get the selector (as a String)
specificity.selectorString(); // "header:where(#top) nav li:nth-child(2n)"

// 💻 These instances also play nice with JSON.stringify()
console.log(JSON.stringify(specificity));
// {
//    "selector": 'header:where(#top) nav li:nth-child(2n)',
//    "asObject": { "a": 0, "b": 1, "c": 3 },
//    "asArray": [0, 1, 3],
//    "asString": "(0,1,3)",
// }

// 🔀 Need to compare against another instance? That's possible!
specificity.isEqualTo(specificities[1])); // false
specificity.isGreaterThan(specificities[1])); // false
specificity.isLessThan(specificities[1])); // true

2.0.0-beta.11 (2022.03.22)

22 Mar 21:21
Compare
Choose a tag to compare
Pre-release

Changing since 2.0.0-beta.9

  • REFACTOR: No longer expose calculate or any of the utility methods from the main file. Instead, provide them as static methods on Specificity which is now the default export.
  • REFACTOR: All utility methods that required one single array before, now work with an arbitrary number of arguments
  • REFACTOR: Rename ascending/descending to sortAsc/sortDesc
  • REMOVE: No longer expose standalone sort

2.0.0-beta.9 (2022.03.11)

11 Mar 18:30
Compare
Choose a tag to compare
Pre-release

Changes since 2.0.0-beta.8

  • ♻️ Rename Specificity.equals to Specificity.isEqualTo

2.0.0-beta.8 (2022.03.11)

11 Mar 11:51
Compare
Choose a tag to compare
Pre-release

Changes since 2.0.0-beta.7

  • 🚑 Fix typings
  • 🐛 Include "bin" in package-lock.json

2.0.0-beta.7 (2022.03.10)

10 Mar 20:41
Compare
Choose a tag to compare
Pre-release

Changes since 2.0.0-beta.2:

  • ✨ Types: Specificity: Allow selector to be a string
  • ✨ Don't unnecessarily try parsing AST if no selectorList is given
  • ✨ Add Type Definitions
  • ✨ Expose the CLI script
  • ♻️ Rework export structure, adding subpath exports along the way
  • ♻️ Internal Code Refactors

2.0.0-beta.2 (2022.03.06)

06 Mar 13:35
Compare
Choose a tag to compare
Pre-release
  • REFACTOR: Rename lowest/highest to min/max

2.0.0-beta.1 (2022.02.28)

28 Feb 09:58
Compare
Choose a tag to compare
Pre-release
  • REFACTOR: Import only selector-parser from css-tree (reducing bundle size)