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

sassy-functions

v1.0.0

Published

๐ŸŽ‰ The little toolbox to use functions across all Sass versions

Downloads

2

Readme

๐Ÿค” Why?

In order to improve modular namespacing, Sass 4 will only accept first-class functions as argument for call() so functions will be called in their own context. This allow developers to make their Sass packages more modular while still being able to call functions given by the user. As a first step, Sass 3.5 added get-function() to get a first-class function from its name and throw a warning if a function name string is passed to call().

We are now encouraged to use get-function(), but this would break our packages for older Sass versions. SassyFunctions is there to allow you to process first-hand functions and function name strings the same way and continue to support all Sass versions.

build status dev dependencies npm

๐Ÿ‘ท How to install

$ npm i -D sassy-functions

Then in Sass:

@import '/path/to/node_modules/sassy-functions/scss/sassy-functions';

Or with Eyeglass

@import 'sassy-functions';

๐Ÿ‘ฉโ€๐Ÿ’ป How to use

Package maintainers, safely use any function reference or name coming from anywhere!

// Let's say you provide a "map-on-my-list" function to iterate with given function on a list...
@function map-on-my-list($list, $func) {
  $newlist: ();

  @each $v in $list {
    $newlist: append($newlist, sf-call($func, $v));
  }
  
  @return $newlist;
}

Package users, safely pass your own function names to anywhere!

// Let's say you have a "to-upper-case" function and want to map a list on it...
$my-list: ('hello', 'world');
$uppercased-list: map-on-my-list($my-list, sf-get-function(to-upper-case));

โœจ There is more! See the API to discover all the functions of the SassyFunctions toolbox.

๐Ÿ“˜ API

  • sf-is-function($value)

    Return if a given value is a function name or reference.

    For example it returns true for:

    // A native Sass function name string
    $res: sf-is-function(rgba);
    // Your own function name string
    $res: sf-is-function('my-function');
    // An inexistant function name (any string can be a function name)
    $res: sf-is-function('xqxqqxhnxqh');
    // A first-class function (in Sass > 3.5)
    $res: sf-is-function(get-function(rgba));

    And it will returns false for:

    // Any value that is not a string or a first-class function
    $res: sf-is-function(0);
    $res: sf-is-function(());
  • sf-is-callable($value)

    Return if a given value can be called.

    For example it returns true for:

    // A native Sass function name string
    $res: sf-is-function(rgba);
    // Your own function name string
    $res: sf-is-function('my-function');
    // A first-class function (in Sass > 3.5)
    $res: sf-is-function(get-function(rgba));

    And it will returns false for:

    // Any value that is not a string or a first-class function
    $res: sf-is-function(0);
    $res: sf-is-function(());
    // A function name that cannot be found
    $res: sf-is-function('xqxqqxhnxqh');
  • sf-assert-function($value)

    Check if a given value is a function name or reference and throw an error otherwise. See sf-is-function for informations on the expected value.

    You can use it to check for your user arguments like:

    @function example($callback) {
      $_: sf-assert-function($callback);
    
      // ...your code with $callback secured..
    }
  • sf-assert-callable($value)

    Check if a given value can be called and throw the appropriate error otherwise. See sf-is-callable for informations on the expected value.

    You can use it to check for your user arguments like:

    @function example($callback) {
      $_: sf-assert-callable($callback);
    
      // ...your code with $callback secured..
      $res: call($callback);
    }

    If $value is not a function, it will throw an error with the appropriate message according to the Sass version used, with migration guidelines if relevant.

  • sf-get-function($func)

    Return a reference to the given function or a function name string so it is callable in the current Sass version. For Sass < 3.5, return the passed argument. For Sass >= 3.5, return a function reference if a function name string was passed.

    For example, use sf-get-function to get a function you can call no matter which Sass version is running.

    @function example($callback) {
      $safe-function: sf-get-function($callback);
    
      // ...your code with $safe-function secured..
    }
  • sf-call($func, $args...)

    Polyfill for the call function supporting both function names and references. Calls the given function/name $func with all the following arguments $args...). If the function cannot be called, throw the appropriate error depending on the user environement.

    For example, use sf-call to call a user-provided callback no matter which Sass version is running.

    @function example($callback) {
      // ...do your stuff...
      $value: random();
    
      // ...then call the callback.
      $res: sf-call($callback, $value);
    }

๐Ÿ‘ฉโ€๐Ÿ”ฌ Testing

You can install SassyFunctions locally and test it with:

# Clone the repo
git clone [email protected]:ncoden/sassy-functions.git
cd sassy-functions

# Install dependencies
npm install

# Run tests
npm test

Copyright ยฉ 2018, Nicolas Coden. Released under the MIT license.