Extends sass built-in modules with additional useful functions.
Add sass-extend to your scss project and import the modules you want to use using @use
, just like native sass modules.
If you are using native sass modules within the same namespace, use an alias for sass-extend to prevent namespace conflicts.
These are the modules included in sass-extend.
@use "sass-extend/string";
Function used to replaces a substring in a string.
string.replace($string, $search, $replace: "")
The following snippet shows an example on how to use it.
@use "sass-extend/string";
$string: "Lorem ipsum";
$replaced-string: string.replace($string, "ipsum", "dolor sit"); // Lorem dolor sit
To use with an unquoted string, you need to interpolate it.
@use "sass-extend/string";
$hex: #f5f5f5;
$hex-digits: string.replace(#{$hex}, "#", ""); // f5f5f5
@use "sass-extend/math";
Function used to remove the unit from a CSS value (number).
math.strip-unit($number)
The following snippet shows an example on how to use it.
@use "sass-extend/math";
$strip-unit: math.strip-unit(16px); // 16
It is also possible to import all modues at once. To do so, import sass-extend
directly.
@use "sass-extend";
All modules will be namespaced with sass-extend
instead of the module category name. It is possible to change the namespace adding an alias to the import.
@use "sass-extend" as se;
This repository includes a demo used to test the functions. Run the demo using the following command. The output will be logged in the terminal.
npm run demo
Guidelines for working in this repository.
Install dependencies.
npm install
This project uses Prettier to format the code. To format all files, run the following command.
npm run prettier
This project uses Stylelint to lint the scss. The settings is based on stylelint-config-standard-scss
. To run the lint, run the following command.
npm run stylelint