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-module-config

v1.1.2

Published

A Sass module for defining immutable configuration singletons.

Downloads

11

Readme

sass-module-config

Release Version License

This Sass module is for defining immutable configuration singletons.

Install

Install the package:

npm install sass-module-config

Use the package like any other Sass module:

@use 'sass-module-config';

Depending on your setup, you may need to use the module by its full path:

// This is only an example
@use '../node_modules/sass-module-config';

One Setting

$config (Map), defaults to an empty map.

  • A map which is expected to be configured when using the module.
  • The map many contain values of any type, including other maps.
  • There is no limit to the depth of this map.

Usage

The following example will define a private variable for the configuration. The variable is then used to configure the $config variable of the sass-module-config module. The $config variable is also hidden to ensure only the sass-module-config's functions are used to get configuration values.

// config.scss
$-config: (
  header: (
    width: 100%,
    height: 200px
  ),
  color: (
    text: #ddd,
    background: (
      &: #222,
      light: #fff
    )
  )
);

@forward 'sass-module-config'
  hide $config
  with ($config: $-config);

// main.scss
@use 'config';

body {
  color: config.get('color' 'text');
  background: config.get('color' 'background');
  header {
    width: config.get('header' 'width');
    height: config.get('header' 'height');
    background: config.get('color' 'background' 'light');
  }
}

Notice: The ampersand (&) indicates the default value for the map on which it is defined. The use of ampersand is no different than using null as the map key.

Public API

@function get($names)

Gets a configured value by the specified names.

@param {String | List} $names - A list of configuration names that indicate the value to be selected. @return {*} - The configured value. @throw - The configuration for `get(#{$names})` has not been defined.

Helpers

Two helpers have been provided to improve type checking and organisation of color and size values. These may be accessed at the sass-module-config/helpers namespace.

@function color($names)

Gets a configured color or color map by the specified names.

@param {String | List} $names - A list of configuration names that indicate the color to be selected. @return {Color | Map} - The configured color. @throw - The configuration for `color(#{$names})` has not been defined. @throw - No color or color map was found for `color(#{$names})`.

@function size($names)

Gets a configured size or size map by the specified names.

@param {String | List} $names - A list of configuration names that indicate the size to be selected. @return {Number | Map} - The configured size. @throw - The configuration for `size(#{$names})` has not been defined. @throw - No size or size map was found for `size(#{$names})`.

Example with Helpers

// config.scss
$-config: (
  size: (
    header: (
      width: 100%,
      height: 200px
    )
  ),
  color: (
    text: #ddd,
    background: (
      &: #222,
      light: #fff
    )
  )
);

@forward 'sass-module-config'
  hide $config
  with ($config: $-config);

@forward 'sass-module-config/helpers'

// main.scss
@use 'config';

body {
  color: config.color('text');
  background: config.color('background');
  header {
    width: config.size('header' 'width');
    height: config.size('header' 'height');
    background: config.color('background' 'light');
  }
}