Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-func

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-func

Handle CSS style functions with no worries

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
increased by11014.29%
Maintainers
1
Weekly downloads
 
Created
Source

css-func

Handle CSS style functions with no worries.

Build Status Coverage Status License

Install

npm i -S css-func

Usage

Examples on how it can be used

const cssfunc = require('css-func');

// get dom element
const element = document.getElementById('#element');

// different ways to specify function parameters
cssfunc(element, 'transform').add('translate', '10px'); // "translate(10px)"
cssfunc(element, 'transform').add('translate', ['10px']); // "translate(10px)"
cssfunc(element, 'transform').add('translate', ['10px', '20px']); //  "translate(10px, 20px)"

cssfunc(element, 'transform').add('rotate', '20deg'); // "rotate(20deg)"

console.log(element.style.transform); // "translate(10px, 20px) rotate(20deg)"

Custom variable that holds the cssfunc instance

const filters = cssfunc(element, 'filter');
filters.add('blur', '10px');
filters.add('grayscale', '100%');

filters.update('blur', '20px');
filters.delete('blur');

filters.exists('blur'); // false

filters.get(); // "grayscale(100%)"

API

get()

Gets the property from element

Examples
cssfunc(element, 'transform').get(); // "translate(10px, 20px) scale(1.1)"
Returns
  • string Element property value
add(fproperty, value[, autoUpdate=true])

Adds or updates a function

Parameters
NameTypeDescription
fpropertystringCSS function name 
valuestring arrayCSS function parameters 
autoUpdate=truebooleanTrue to automatically update function if aleady presentTrue to automatically add new function if not presentOptional
Examples
cssfunc(element, 'transform').add('rotate', '10px');
cssfunc(element, 'transform').add('translate', ['10px', '20px']);
cssfunc(element, 'transform').add('translateX', ['10px']);
Returns
  • boolean True if a function was added or updated
update(fproperty, value[, autoAdd=true])

Updates or adds a function

Parameters
NameTypeDescription
fpropertystringCSS function name 
valuestring arrayCSS function parameters 
autoAdd=truebooleanTrue to automatically add new function if not presentOptional
Examples
cssfunc(element, 'transform').update('rotate');
Returns
  • boolean True if a function was updated or added
delete(fproperty)

Delete functoin from element style property

Parameters
NameTypeDescription
fpropertystringCSS function name 
Examples
cssfunc(element, 'transform').delete('rotate');
Returns
  • boolean True if there was a function to delete
exists(fproperty)

Returns true if function exists

Parameters
NameTypeDescription
fpropertystringCSS function name 
Examples
cssfunc(element, 'transform').exists('rotate');
Returns
  • boolean True if function exists

License

MIT

Keywords

FAQs

Package last updated on 31 Dec 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc