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

node-sass-filefunctions

v1.0.0

Published

File information functions for use with node-sass

Downloads

3

Readme

node-sass-filefunctions - Filename and path handling for SASS/SCSS

Ever wanted to automatically generate styles based on available assets? This package provides the facilities for identifying the assets in your work directory and manipulating their filenames in the ways you will need to produce viable CSS class descriptions for them.

Usage

These functions are implemented as a plugin to node-sass. To integrate them, you need to provide the functions option to the node-sass processing function, for example:

const sass = require ('node-sass');
const sassFileFunctions = require ('node-sass-filefunctions');
...
var result = sass.renderSync ({
    data: "... SASS or SCSS content goes here ...",
    functions: sassFileFunctions.nodeSassFileFunctions ()
});

In case you are already using some custom functions for node-sass, the retrieval function can accept an object containing a collection of functions that are used to extend the object it returns:

var myOtherFunctions = { "frobnicate($foo)": do_sass_frobinication };

var result = sass.renderSync ({
    data: "... SASS or SCSS content goes here ...",
    functions: sassFileFunctions.nodeSassFileFunctions (myOtherFunctions)
});

The functions

The functions provided are:

glob($pattern, $dir: null)

Expand wildcards (e.g. "*" and "?" for matching unknown characters, "**" for matching parent directories, "[abc]" for character classes, and "{a,b,c}" for alternation) into matching filenames. The path separator is always returned as "/". If $dir is specified, it is the directory to run the expansion in (the process current working directory is the default).

Returns a list of strings, one for each match. Uses the glob package; more documentation on the behaviour of the patterns is available there.

For example:

@each $file in glob('../assets/*.png') {
    .bg-#{basename($file, ".png")} { background-image: url('#{$file}'); }
}

basename($path, $ext: null)

Returns the basename of the path (i.e., the filename part without directories). If the optional parameter "$ext" is specified, it contains an extension that is stripped out of the name if present.

For example, basename("../assets/checkerboard.png", ".png") gives the result checkerboard.

dirname($path)

Similar to basename, but returns the directories rather than the filename.

For example, dirname("../assets/checkerboard.png") gives the result ../assets.

extname($path)

Returns only the extension part (if any) of a path name, including the leading dot. If the path name has no extension, returns the empty string.

For example, extname("../assets/checkerboard.png") gives the result .png.

joinPath($path1, $path2)

Joins two paths together. In case the resulting path contains backslash characters (e.g. because the operation is performed under Windows), these are converted to forward slashes (as they are most likely to be used in a URL, and this is the form of separator expected in this case).

For example, joinPath ("../assets", "lo-res/checkerboard.png") gives the result ../assets/lo-res/checkerboard.png.

resolvePath($path1, $path2)

Merges two paths together and returns the canonical path name of the combined path. Note that if neither path is absolute, the first will be resolved as relative to the current working directory. In most cases, this is not useful, so you should generally ensure that $path1 is absolute. As for joinPath, path separators are returned as forward slashes, even on systems where backslash is the default.

For example, resolvePath ("/assets/lo-res", "../checkerboard.png") gives the result /assets/checkerboard.png.