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

sass-cast

v0.5.6

Published

Convert Javascript objects to Sass objects and vice versa.

Downloads

251

Readme

sass-cast

Convert Javascript objects to Sass objects and vice versa. Based on sassport and node-sass-utils, updated to work with newer sass versions and the modern Sass API.

Usage

Table of Contents

toSass

Converts any Javascript object to an equivalent Sass value.

This method is recursive and will convert the values of any array or object, as well as the array or object itself.

Parameters

  • value any the value to be converted

  • options Object (optional, default {})

    • options.parseUnquotedStrings boolean whether to parse unquoted strings for colors or numbers with units (optional, default false)
    • options.resolveFunctions (boolean | Array<any>) if true, resolve functions and attempt to cast their return values. if an array, pass as arguments when resolving (optional, default false)
    • options.quotes boolean controls whether returned SassStrings are quoted. input strings that contain quotes will always return a quoted SassString even if this flag is false. (optional, default true)

Examples

const { toSass } = require('sass-cast');

const string = toSass('a simple string');
// quoted SassString => '"a simple string"'

const map = toSass({
  key: 'value',
  nested: {
    'complex//:key': [ null, 4 ],
  }
});
// SassMap => '("key": "value", "nested": ("complex//:key": (null, 4)))'

Returns Value a Sass value

fromSass

Converts Sass values to their Javascript equivalents.

Parameters

  • object Value a Sass value

  • options Object (optional, default {})

    • options.preserveUnits boolean By default, only the values of numbers are returned, not their units. If true, fromSass will return numbers as a two-item Array, i.e. [ value, unit ] (optional, default false)
    • options.rgbColors boolean By default, colors are returned as strings. If true, fromSass will return colors as an object with r, g, b, and a, properties. (optional, default false)
    • options.preserveQuotes boolean By default, quoted Sass strings return their inner text as a string. If true, fromSass will preserve the quotes in the returned string value. (optional, default false)

Examples

const { fromSass, toSass } = require('sass-cast');

const sassString = toSass('a sass string object');
const string = fromSass(sassString);
// 'a sass string object'

Returns any a Javascript value corresponding to the Sass input

sassFunctions

An object defining Sass utility functions.

Examples

Pass to sass using the JS API

const { sassFunctions } = require('sass-cast');
const sass = require('sass');

sass.compile('main.scss', { functions: sassFunctions });

require

Sass function for importing data from Javascript or JSON files. Calls the CommonJS require function under the hood.

Examples
// import config info from tailwindcss
$tw: require('./tailwind.config.js', $parseUnquotedStrings: true);
$tw-colors: map.get($tw, theme, extend, colors);
Parameters
  • $module SassString Path to the file or module. Relative paths are relative to the Node process running Sass compilation.
  • $properties SassList List of properties, if you only want to parse part of the module data. (optional, default ())
  • $parseUnquotedStrings SassBoolean Passed as an option to toSass. (optional, default false)
  • $resolveFunctions SassBoolean Passed as an option to toSass. (optional, default false)
  • $quotes SassBoolean Passed as an option to toSass. (optional, default true)

Returns Value a Sass value

legacy

Identical methods that interface with Sass's legacy Javascript API for older versions of Sass. Use require('sass-cast/legacy').

toSass

Converts any Javascript object to an equivalent legacy Sass object.

Parameters
  • value any the value to be converted

  • options Object (optional, default {})

    • options.parseUnquotedStrings boolean whether to parse unquoted strings for colors or numbers with units (optional, default false)
    • options.resolveFunctions (boolean | Array<any>) if true, resolve functions and attempt to cast their return values. if an array, pass as arguments when resolving (optional, default false)
    • options.quotes (string | null) the type of quotes to use when quoting Sass strings (single or double) (optional, default "'")

Returns LegacyObject a legacy Sass object

fromSass

Converts legacy Sass objects to their Javascript equivalents.

Parameters
  • object LegacyObject a legacy Sass object

  • options Object (optional, default {})

    • options.preserveUnits boolean By default, only the values of numbers are returned, not their units. If true, fromSass will return numbers as a two-item Array, i.e. [ value, unit ] (optional, default false)
    • options.rgbColors boolean By default, colors are returned as strings. If true, fromSass will return colors as an object with r, g, b, and a, properties. (optional, default false)
    • options.preserveQuotes boolean By default, quoted Sass strings return their inner text as a string. If true, fromSass will preserve the quotes in the returned string value. (optional, default false)

Returns any a Javascript value corresponding to the Sass input

sassFunctions

An object defining legacy Sass utility functions.

require

Legacy Sass function for importing data from Javascript or JSON files.

Parameters
  • $module
  • $properties
  • $parseUnquotedStrings
  • $resolveFunctions
  • $quotes
  • done