
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
postcss-plugin-utilities
Advanced tools
A list of utilities for creating PostCSS plugins
npm install postcss-plugin-utilities
Do calculations on css (uses mathjs)
Example:
let util = require('postcss-plugin-utilities'),
width = '1600px',
height = util.calc('x/16*9', width);
// height will be 900px
Returns either black or white depending on contrasting a color. Useful for calculating overlay text color for an unknown background-color.
Updates a selector with SASS like syntax
Example:
let util = require('postcss-plugin-utilities'),
selector = 'p, ul, ol',
newSelector = util.eachSelector(selector, '&:before');
// newSelector will be 'p:before, ul:before, ol:before'
Go through an array and filter the values as per set rules and falling back to defaults.
Example:
let util = require('postcss-plugin-utilities'),
values = ['20px', 'center', 'black'],
theObject = util.filterObject(values, {
// rules are set up using an object,
// the values being an array of correct values
// or a validation function
align: ['left', 'right', 'center'], // left, right or center are accepted values
blackOrWhite: [(testingValue) => { // a function can be passedin to validate
if(['black', 'white'].indexOf(testingValue) >= 0) { return true; }
return false;
}],
size: [util.isSize], // we can also link in functions for validation
shadow: [util.isBoxShadow]
}, {
// a set of defaults can be passed in as well
size: '30px',
shadow: '1px 1px 1px black'
});
// theObject will result in
// {
// align: 'center',
// blackOrWhite: 'black',
// size: '20px',
// shadow: '1px 1px 1px black'
// }
Get an object of RGB and possibly A values from a color string
Wrap filter object and return sides values the same way as margin and padding works in CSS
Example:
let util = require('postcss-plugin-utilities'),
values = ['20px', '10px'],
sides = util.getSides(values, {
'border-top': [util.isSize],
'border-right': [util.isSize],
'border-bottom': [util.isSize],
'border-left': [util.isSize]
});
// sides will equal to
// {
// 'border-top': '20px',
// 'border-right': '10px',
// 'border-bottom': '20px',
// 'border-left': '10px',
// }
Convert a hex color to RGB
Returns true if a value is a valid bezier
Return true if a value is a valid border
Return true if a value is a valid box-shadow
Return true if a value is a valid color
Return true if a value is a valid cursor
Return true if a value is a valid HTML element
Return true if a value is a valid number (unitless)
Return true if a value is a valid CSS property
Checks if a value matches a regex (uses exact-regex)
Return true if a value is a valid CSS size list (eg.: padding, margin)
Return true if a value is a valid CSS size
Return true if a value is a valid CSS animation step
Return true if a value is a valid text-shadow
Return true if a value is a valid time (eg.: 3s)
Check if a string is a transition value
Return true if a value is a valid CSS URL
Convert a named color to its hex value
Merge two arrays with the same properties to be overwritten with values (uses overwrite-object)
Recursively delete nodes
Convert an RGB value to its hex value
Parse a SASS function and call a JS function on it
Get the value of a sass variable
Check if sass variable exists
FAQs
A list of utilities for creating PostCSS plugins
The npm package postcss-plugin-utilities receives a total of 158 weekly downloads. As such, postcss-plugin-utilities popularity was classified as not popular.
We found that postcss-plugin-utilities 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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.