Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
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.
css-custom-properties
Advanced tools
Readme
This module provides utilities to work with CSS custom properties in Javascript.
Install the package with the following command
npm install --save css-custom-properties
Example:
// Import using ES5 syntax
var CssCustomProperties = require('css-custom-properties');
// Import using ES6 syntax
import CssCustomProperties from 'css-custom-properties';
// Set a CSS variable
CssCustomProperties.set({
'my-var': '16px',
'my-other-var': 0.5,
});
// Get a CSS variable's value
console.log(CssCustomProperties.get('my-var'));
// => '16px'
// Get all CSS variables
console.log(CssCustomProperties.getAll());
// => {'my-var': '16px', 'my-other-var': 0.5}
// Check if a CSS variable has been set
console.log(CssCustomProperties.has('my-var'));
// => true
// Remove a CSS variable
console.log(CssCustomProperties.unset('my-var'));
// => '16px'
// Check if a CSS variable has been set
console.log(CssCustomProperties.has('my-var'));
// => false
The package exposes the following methods.
This method sets CSS variables on a DOM element.
Arguments
:root
element.Returns
collection
.Example
var variables = CssCustomProperties.set({
'my-var': '16px',
'my-other-var': 0.5,
'--my-prefixed-var': 'red',
});
console.log(variables);
// => {'my-var': '16px', 'my-other-var': 0.5, 'my-prefixed-var': 'red'}
This method gets a CSS variable's value on a DOM element.
Arguments
:root
element.Returns
variable
's value, else undefined
.Example
var myVar = CssCustomProperties.get('my-var');
console.log(myVar);
// => '16px'
var myNonExistantVar = CssCustomProperties.get('my-non-existant-var');
console.log(myNonExistantVar);
// => undefined
This method gets all CSS variables on a DOM element.
Arguments
:root
element.Returns
Example
CssCustomProperties.set({
'my-var': '16px',
'my-other-var': 0.5,
});
CssCustomProperties.set({
'another-one': 0,
});
var allVars = CssCustomProperties.getAll();
console.log(allVars);
// => {'my-var': '16px', 'my-other-var': 0.5, 'another-one': 0}
This method gets all CSS variables on a DOM element. Like getAll()
but with prefixed variable names.
Arguments
:root
element.Returns
Example
CssCustomProperties.set({
'my-var': '16px',
'my-other-var': 0.5,
});
CssCustomProperties.set({
'another-one': 0,
});
var allVars = CssCustomProperties.getAll();
console.log(allVars);
// => {'--my-var': '16px', '--my-other-var': 0.5, '--another-one': 0}
This method checks if a CSS variable exists on a DOM element.
Arguments
:root
element.Returns
true
if CSS variable exists on element
, else false
.Example
var myVarExists = CssCustomProperties.has('my-var');
console.log(myVarExists);
// => true
var myNonExistantVarExists = CssCustomProperties.get('my-non-existant-var');
console.log(myNonExistantVarExists);
// => false
This method removes a CSS variable from a DOM element.
Arguments
:root
element.Returns
Example
var variables = CssCustomProperties.set({
'my-var': '16px',
'my-other-var': 0.5,
});
var removedVar = CssCustomProperties.unset('my-other-var');
// => 0.5
var allVars = CssCustomProperties.getAll();
console.log(allVars);
// => {'my-var': '16px'}
This method removes all CSS variable from a DOM element.
Arguments
:root
element.Returns
Example
var variables = CssCustomProperties.set({
'my-var': '16px',
'my-other-var': 0.5,
});
var removedVars = CssCustomProperties.unsetAll();
// => {'my-var': '16px', 'my-other-var': 0.5}
var allVars = CssCustomProperties.getAll();
console.log(allVars);
// => {}
Adds the "--" prefix if it doesn't already exists.
Arguments
Returns
Example
CssCustomProperties.prefix('var');
// => '--var'
CssCustomProperties.prefix(['var', '--other-var']);
//=> ['--var', '--other-var']
CssCustomProperties.prefix({
'--var': 10,
'other-var': 'green',
});
//=> {'--var': 10, '--other-var': 'green'}
Trim the "--" prefix, if it exists.
Arguments
Returns
Example
CssCustomProperties.unprefix('--var');
// => 'var'
CssCustomProperties.unprefix(['var', '--other-var']);
//=> ['var', 'other-var']
CssCustomProperties.unprefix({
'--var': 10,
'other-var': 'green',
});
//=> {'var': 10, 'other-var': 'green'}
FAQs
Work with CSS Custom Properties in Javascript
The npm package css-custom-properties receives a total of 16 weekly downloads. As such, css-custom-properties popularity was classified as not popular.
We found that css-custom-properties 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.
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.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.