npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

css-func

v1.0.0

Published

Handle CSS style functions with no worries

Downloads

47

Readme

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

| Name | Type | Description | | | -------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------ | ---------- | | fproperty | string | CSS function name |   | | value | string array | CSS function parameters |   | | autoUpdate=true | boolean | True to automatically update function if aleady presentTrue to automatically add new function if not present | Optional |

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

| Name | Type | Description | | | ----------------- | ---------------- | ----------------------------------------------------- | ---------- | | fproperty | string | CSS function name |   | | value | string array | CSS function parameters |   | | autoAdd=true | boolean | True to automatically add new function if not present | Optional |

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

| Name | Type | Description | | | --------- | -------- | ----------------- | ------ | | fproperty | string | CSS 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

| Name | Type | Description | | | --------- | -------- | ----------------- | ------ | | fproperty | string | CSS function name |   |

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

License

MIT