angular-package
PatreonTwitternpmGitHub
Sass
Sass
  • Introduction
  • ❤ Benefits
  • General concepts
  • Getting started
    • Skeleton
    • Installation
      • npm
    • Public API
    • Basic concepts
  • Class
    • Overview
    • ⚒ class.content()
    • ⚒ class.name()
    • ⚒ class.parent-first()
    • ⚒ variables
  • Color
    • Overview
    • Scheme
      • is
        • ⚒ is.dark()
        • ⚒ is.light()
        • ⚒ is.normal()
      • ⚒ scheme.is()
    • ⚒ color.alpha-var()
    • ⚒ color.color()
    • ⚒ color.hsla-color()
    • ⚒ color.hue-var()
    • ⚒ color.lightness-var()
    • ⚒ color.name()
    • ⚒ color.retrieve()
    • ⚒ color.saturation-var()
  • Comparison
    • Overview
    • Greater
      • greater.than()
      • greater.than-any()
      • greater.than-every()
    • Less
      • less.than()
      • less.than-any()
      • less.than-every()
    • comparison.compare()
    • comparison.compare-multiple()
  • Function
    • Overview
    • Call
      • ⚒ function.arglist()
      • ⚒ function.by-list()
    • ⚒ function.call()
    • ⚒ function.get()
    • ⚒ function.has()
    • ⚒ function.insert()
    • ⚒ function.is()
    • ⚒ function.name()
    • ⚒ function.pick()
    • ⚒ function.prefix()
    • ⚒ function.remove()
  • List
    • Overview
    • Get
      • get.bool()
      • get.list()
      • get.map()
      • get.number()
      • get.string()
      • get.type()
    • Has
      • has.bool()
      • has.list()
      • has.map()
      • has.number()
      • has.string()
      • has.type()
      • has.value()
    • Remove
      • remove.duplicate()
      • remove.list()
      • remove.map()
      • remove.nth()
      • remove.number()
      • remove.range()
      • remove.string()
      • remove.type()
      • remove.value()
    • list.append()
    • list.empty()
    • list.extract-map()
    • list.first()
    • list.from()
    • list.has()
    • list.index()
    • list.indexes()
    • list.insert-nth()
    • list.join()
    • list.last()
    • list.limit()
    • list.nth()
    • list.range()
    • ⚒ list.replace-string()
    • ⚒ list.replace()
    • list.select()
    • ⚒ list.swap()
    • ⚒ list.to-map()
    • list.to()
    • list.type()
  • Map
    • Overview
    • Pattern
      • pattern.is()
      • Variables
    • Pick
      • pick.key-substring()
      • pick.key-type()
      • pick.pattern()
      • pick.type()
      • pick.value-type()
    • map.deep-merge-key()
    • map.deep-merge()
    • map.get()
    • map.has-keys()
    • map.key-replace()
    • ⚒ map.merge-allowed()
    • map.pick()
    • map.remove-type()
    • map.remove()
    • map.retrieve()
    • map.set()
    • map.update()
    • map.values()
  • Math
    • Overview
    • Range
      • range.down()
      • range.up()
    • math.calculate()
    • math.range()
    • ⚒ math.sort()
    • math.strip-unit()
  • Meta
    • Overview
    • ⚒ meta.call-arglist()
    • ⚒ meta.of-type()
  • Object
    • Overview
    • ⚒ object.create()
    • ⚒ object.get()
    • ⚒ object.set()
  • Property
    • Overview
    • ⚒ property.property()
    • ⚒ property.name()
    • ⚒ property.set()
    • ⚒ property.value()
    • ⚒ property.variant()
  • Query
    • Overview
    • Operation
      • ⚒ operation.execute()
    • ⚒ query.execute()
  • Selector
    • Overview
    • ⚒ selector.class()
    • ⚒ selector.nest-content()
    • ⚒ selector.nest()
    • ⚒ selector.pseudo-class()
    • ⚒ selector.replace-parent()
  • String
    • Overview
    • string.index()
    • string.join()
    • string.replace-multiple()
    • string.replace()
    • string.split()
    • ⚒ string.to-map()
    • ⚒ string.unquote()
  • Translator v0.1.0
    • Overview
    • Dictionary
      • dictionary.get()
      • dictionary.is-global()
      • dictionary.merge()
      • dictionary.pick()
      • dictionary.set()
      • dictionary.translation()
      • dictionary.variables
    • Translate
      • translate.list()
      • translate.map()
      • translate.nth()
      • translate.string()
    • translator.dictionary()
    • translator.translate()
  • Translator v1.0.0
    • Overview
    • Dictionary
      • dictionary.get()
      • dictionary.merge()
      • dictionary.pick()
      • dictionary.set()
      • dictionary.translation()
      • dictionary.variables
    • ⚒ Translate
    • translator.dictionary()
    • translator.translate()
  • Values
    • Overview
    • values.combine()
  • Var
    • Overview
    • ⚒ var.adjust()
    • ⚒ var.css()
    • ⚒ var.get()
    • ⚒ var.is()
    • ⚒ var.name()
    • ⚒ var.negative()
    • ⚒ var.unit()
    • var.set()
  • Variant
    • Overview
  • Change log
    • Keep a changelog
    • CHANGELOG.md
    • v0.12.0-beta
  • GIT
    • Commit
    • Semantic Versioning
  • License
    • MIT
  • Social
    • Gettr
    • Twitter
    • YouTube
  • Contact
    • Chat
    • Email
    • Phone
  • Donate
    • Cryptocurrency
    • Fiat
Powered by GitBook
On this page
  • Parameters
  • Return
  • Examples

Was this helpful?

  1. Map

map.key-replace()

Previousmap.has-keys()Next⚒ map.merge-allowed()

Last updated 1 year ago

Was this helpful?

The map.key-replace() function returns the map with key replaced by .

// Sass.
@use 'sass:map';

// Functions.
@use '../string';

// The `map.key-replace()` function.
@function key-replace($map, $replace, $replacement) {
  @if type-of($map) == map {
    @each $key, $value in $map {
      $map: map.remove($map, $key);
      @if type-of($key) ==
        string and
        type-of($replace) ==
        string and
        type-of($replacement) ==
        string
      {
        @if string.index($key, $replace) {
          $key: string.replace($key, first, $replace, $replacement);
        }
      } @else if $key == $replace {
        $key: $replacement;
      }

      $map: map.merge(
        $map,
        (
          $key: $value,
        )
      );
    }
  }
  @return $map;
}

Parameters

$map

$replace

$replacement

Return

Examples

// Use.
@use '@angular-package/sass/map';

// Examples.
$-map: (
  key replace: (map: 1),
  key-replace: (map: 2),
);

// replace string key
@debug map.key-replace($-map, key-replace, new-key); // (key replace: (map: 1), new-key: (map: 2))
@debug map.key-replace(('bold king': 1, b: 2, c: 3), 'bold', 'hairy'); // ("hairy king": 1, b: 2, c: 3)
@debug map.key-replace(('bold king': 1, b: 2, c: 3), 'o', 'ooo'); // ("booold king": 1, b: 2, c: 3)
@debug map.key-replace((a: 1, b: 2, c: 3), 'a', 'd'); // (d: 1, b: 2, c: 3)

// replace string key with a list key
@debug map.key-replace($-map, key-replace, new key); // (key replace: (map: 1), new key: (map: 2))

// replace list key
@debug map.key-replace($-map, key replace, 'd'); // (d: 1, b: 2, c: 3)

A map in which a key is replaced with .

A key, or if string substring to replace with in .

The value to replace a key in .

The return value is a with replaced key by .

$replace
$replacement
$replace
$replacement
$replacement
$map
$replace
$map
$map
$replace
$replacement
https://github.com/angular-package/sass/blob/main/map/_map.key-replace.function.scss
// Sass.
@use 'sass:map';

// Functions.
@use '../string';

// Status: TODO: Check substring.
// The `map.key-replace()` function returns the map with key `$replace` replaced by `$replacement`.
// @param `$map` A map in which a `$replace` key is replaced with a `$replacement`.
// @param `$replace` A key, or if `string` substring to replace with `$replacement` in `$map`.
// @param `$replacement` The value to replace a `$replace` key in `$map`.
// @return The return value is a `$map` with replaced key `$replace` by `$replacement`.
@function key-replace($map, $replace, $replacement) {
  @if type-of($map) == map {
    @each $key, $value in $map {
      $merge: false;
      @if (type-of($key) == string and type-of($replace) == string and type-of($replacement) == string) or $key == $replace {
        $map: map.remove($map, $key);
        $merge: true;
      }
      @if type-of($key) == string and type-of($replace) == string and type-of($replacement) == string {
        @if string.index($key, $replace) {
          $key: string.replace($key, first, $replace, $replacement);
        }
      } @else if $key == $replace {
        $key: $replacement;
      }
      @if $merge {
        $map: map.merge($map, ($key: $value));
      }
    }
  }
  @return $map;
}

// Examples.
// $-map: (
//   key replace: (map: 1),
//   key-replace: (map: 2),
// );

// replace string key
// @debug key-replace($-map, key-replace, new-key); // (key replace: (map: 1), new-key: (map: 2))
// @debug key-replace(('bold king': 1, b: 2, c: 3), 'bold', 'hairy'); // ("hairy king": 1, b: 2, c: 3)
// @debug key-replace(('bold king': 1, b: 2, c: 3), 'o', 'ooo'); // ("booold king": 1, b: 2, c: 3)
// @debug key-replace((a: 1, b: 2, c: 3), 'a', 'd'); // (d: 1, b: 2, c: 3)

// replace string key with a list key
// @debug key-replace($-map, key-replace, new key); // (key replace: (map: 1), new key: (map: 2))

// replace list key
// @debug key-replace($-map, key replace, 'd'); // (d: 1, b: 2, c: 3)