non-destructive-map-merge

A non-destructive-map-merge function for Sass

Usage no npm install needed!

<script type="module">
  import nonDestructiveMapMerge from 'https://cdn.skypack.dev/non-destructive-map-merge';
</script>

README

non-destructive-map-merge

A non-destructive-map-merge function for Sass

Credit: https://medium.com/@pentzzsolt/a-non-destructive-map-merge-function-for-sass-f91637f87b2e#.ekepo95qi

Example

$global-colors: (
    neutral: (
        x-light: #f1f1f1,
    ),
    primary: #df2,
    secondary: (
        base: (
            old: red,
            new: green
        )
    ),
    tertiary: (
        base: yellow
    )
);

$local-colors: (
    neutral: grey,
    primary: (
        light: #738bd3,
        base: #042f75
    ),
    secondary: (
        light: #ffa75b
    ),
    tertiary: (
        light: (
            first: orange,
            second: purple
        ),
    ),
    success: (
        base: #007b39
    )
);

$colors: non-destructive-map-merge($global-colors, $local-colors);

//Expected result:
//$colors: (
//	neutral: grey,
//		primary: (
//			light: #738bd3,
//			base: #042f75
//		),
//		secondary: (
//			base: (
//				old: red,
//				new: green
//			),
//		light: #ffa75b
//	),
//	tertiary: (
//		base: yellow,
//		light: (
//			first: orange,
//			second: purple
//		)
//	),
//	success: (
//		base: #007b39
//	)
//);