{"library":"node-sass-utils","title":"Node Sass Utilities","description":"node-sass-utils provides a collection of helper functions designed to simplify working with Sass values within JavaScript functions exposed to `node-sass` (and `dart-sass`, aka `sass` on npm). It addresses the complexity of handling Sass data types (like strings, numbers, booleans, lists, and maps) in a JavaScript environment. The library is currently at version 1.1.3. While its primary integration point was `node-sass`, it has been tested and confirmed to work with `dart-sass`, providing a bridge for utility functions regardless of the underlying Sass compiler implementation. This allows developers to write more robust and type-safe custom Sass functions in JavaScript. Key differentiators include methods for type assertion (`assertType`), type checking (`typeOf`, `isNull`, `isFalsy`), string manipulation (`sassString`, `unquote`), and crucial type casting utilities (`castToSass`, `castToJs`) for seamless data exchange between JavaScript and Sass. It is important to note its CommonJS module format and the specific initialization pattern requiring the Sass object.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install node-sass-utils"],"cli":null},"imports":["const sass = require('sass');\nconst sassUtils = require('node-sass-utils')(sass);","const sass = require('sass');\nconst sassUtils = require('node-sass-utils')(sass);\nconst { SassDimension } = sassUtils;","const sass = require('sass');\nconst sassUtils = require('node-sass-utils')(sass);\nconst { castToSass } = sassUtils;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const sass = require(\"sass\"); // Using 'sass' (Dart Sass) for modern usage\nconst sassUtils = require(\"node-sass-utils\")(sass);\n\nfunction mySassFunction(colorValue, stringValue) {\n  sassUtils.assertType(colorValue, \"color\");\n  const jsColor = sassUtils.castToJs(colorValue); // Convert Sass Color to JS representation\n  console.log(`Received Sass Color (JS): ${jsColor}`);\n\n  const unquotedString = sassUtils.unquote(stringValue); // Unquote the Sass string\n  console.log(`Unquoted Sass String: \"${sassUtils.sassString(unquotedString)}\"`);\n\n  const jsNumber = 42;\n  const sassNumber = sassUtils.castToSass(jsNumber); // Cast JS number to Sass number\n  return sass.types.List([sassNumber, unquotedString, colorValue], sass.types.List.SEPARATOR_SPACE);\n}\n\nsass.render({\n  data: `\n        @function my-func($color, $str) {\n          @return my-func($color, $str);\n        }\n        $result: my-func(#f0f, \"hello world\");\n        div {\n          content: inspect($result);\n        }\n      `,\n  functions: {\n    \"my-func($color, $str)\": mySassFunction\n  }\n}, (err, result) => {\n  if (err) {\n    console.error(\"Sass compilation error:\", err);\n  } else {\n    console.log(\"Compiled CSS:\\n\", result.css.toString());\n  }\n});","lang":"javascript","description":"This example demonstrates initializing `node-sass-utils` with the `sass` (Dart Sass) compiler, using `assertType` for validation, `castToJs` to convert Sass types to JavaScript, `unquote` for string manipulation, and `castToSass` to convert JavaScript values back to Sass types within a custom Sass function.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}