If we have nested maps in SASS (an Angular Theme for example) we can log the contents of it with @debug
however it outputs everything in one line.
Anyone know if SASS has something that will pretty print the structure of nested maps?
So for example if we had:
JavaScript
x
14
14
1
$colors: (
2
"primary": (
3
"milk": #fff,
4
"cola": #000,
5
"mine-shaft": #232323,
6
),
7
"secondary": (
8
"pampas": #f4f1ef,
9
"pearl-brush": #e9e2dd,
10
"alto": #ddd,
11
),
12
);
13
14
We could do something like
JavaScript
1
2
1
@recursive-debug $colors
2
To log the structure of it.
Advertisement
Answer
I created a NPM package for this that is a SASS installable file.
JavaScript
1
2
1
npm i @fireflysemantics/sass-logger
2
https://www.npmjs.com/package/@fireflysemantics/sass-logger
This is from the usage section of the README.
JavaScript
1
16
16
1
This demo will create a Angular Material Palette $theme-primary and log the contents by first using the logger to structure the map data containing the result and then outputting that result with @debug.
2
3
@use '@angular/material' as mat;
4
@use '@fireflysemantics/sass-logger' as logger;
5
6
// ============================================
7
// Palettes: https://material.io/design/color/
8
// ============================================
9
$theme-primary: mat.define-palette(mat.$indigo-palette);
10
$result: logger.pretty-map($theme-primary);
11
@debug ($result);
12
13
$theme: mat.define-light-theme($theme-primary, $theme-primary, $theme-primary);
14
//$result: logger.pretty-map($theme);
15
16
This is a stackblitz demo of the package.