Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
specimen
Advanced tools
Changelog
0.2.0 - 13 Jun 2013
undefined
.Readme
A CSS selector specificity calculator.
npm install specimen
var specimen = require('specimen');
specimen('#home #warning p.message');
//=> [0, 2, 1, 1]
specimen('#home #warning p.message, .footer a[rel=me]:hover');
//=> [ [0,2,1,1], [0,0,3,1] ]
specimen([
'#home #warning p.message',
'.footer a[rel=me]:hover'
]);
//=> [ [0,2,1,1], [0,0,3,1] ]
Calculates the specificity of one or more CSS selectors. The selectors
argument is a string containing one or more selectors, or an array of selector
strings.
Returns an array representing the specificity, or undefined
if a non-string
was given.
For multiple selectors, whether passed as string or array, an array of
specificities is returned. Returns undefined
if all values in the array would
have been undefined
.
Specificity is represented as a four element array where each element corresponds to a selector category.
The selector categories are, in order of most to least specific:
A a selector is split up into chunks and sorted into selector categories. The
categories are tallied, and the result is specificity: [i, a, b, c]
.
specimen('#home #warning p.message');
//=> [0, 2, 1, 1]
Specimen calculates selector specificity only; it cannot know the specificity
of inline styles. It also cannot account for the use of !important
.
Specimen will attempt to calculate the CSS selector specificty of any string.
A result of [0, 0, 0, 0]
means the string is probably not a CSS selector, or
contains only the universal selector "*"
which has no affect on specificity.
Specimen is based heavily on keeganstreet/specificity.
I needed a small specificity module for another project and Keegan Street's
specificity
fit the bill perfectly. But I also needed a small project to help
curb my fear of programming. I decided I didn't need the additional information
that specificity
provides. I settled on a simpler API and specimen
was born.
FAQs
CSS selector specificity calculator
The npm package specimen receives a total of 7 weekly downloads. As such, specimen popularity was classified as not popular.
We found that specimen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.