# node-sass-filefunctions

> File information functions for use with node-sass

Latest version **1.0.0** (published 2017-06-08) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install node-sass-filefunctions
pnpm add node-sass-filefunctions
yarn add node-sass-filefunctions
bun add node-sass-filefunctions
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-06-08 |
| First published | 2017-06-08 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Julian Hall |
| Maintainers | jh3141 |
| Keywords | filename, path, sass, extension |

## Links

- npm: https://www.npmjs.com/package/node-sass-filefunctions
- npm.io page: https://npm.io/package/node-sass-filefunctions

## Dependencies (2)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [node-sass](https://npm.io/package/node-sass.md) ^4.5.3

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-06-08

## 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](https://www.npmjs.com/package/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```.

---
_Source: https://npm.io/package/node-sass-filefunctions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
