pick.type()
The pick.type()  or map.pick-type() function picks the properties with values and/or keys of type.
// Sass.
@use 'sass:list';
@use 'sass:map';
// Functions.
@use 'pick.key-type.function' as *;
@use 'pick.value-type.function' as *;
// Modules.
@use '../../string';
// The `pick.type()` or `map.pick-type()` function.
@function type($map, $field-type...) {
  $result: ();
  @each $pattern in $field-type {
    @if type-of($pattern) == string {
      @if string.index($pattern, 'value:') or string.index($pattern, 'key:') {
        $pattern: string.split(string.unquote($pattern), ':');
        $type: string.split(list.nth($pattern, 2), ',');
        $result: map.deep-merge(
          $result,
          if(
            list.nth($pattern, 1) == key,
            key-type($map, $type...),
            value-type($map, $type...)
          )
        );
      }
    }
  }
  @return $result;
}https://github.com/angular-package/sass/blob/main/map/pick/_pick.type.function.scss
// Sass.
@use 'sass:list';
@use 'sass:map';
// Functions.
@use '../../list/list.append.function' as *;
@use 'pick.key-type.function' as *;
@use 'pick.value-type.function' as *;
// Modules.
@use '../../string';
// Status: DONE
// The `pick.type()` function picks the properties with values and/or keys of the specified type.
// @param `$map` A map from which properties with values and/or keys of a certain type are picked.
// @param `$field-type` Required key as pattern `field:type` where field can be `value` or `key` and type
// bool, calculation, color, function, list, map, null, number or string, to pick properties with the value and/or key of the specified type.
// @arbitrary `$field-types...` Additional keys as pattern to pick from `$map`.
// @return The return value is a copy of `$map` with values and/or keys associated with types.
@function type($map, $field-type, $field-types...) {
  $result: ();
  @each $pattern in append((), $field-type, comma, $field-types...) {
    @if type-of($pattern) == string {
      @if string.index($pattern, 'value:') or string.index($pattern, 'key:') {
        $pattern: string.split(string.unquote($pattern), ':');
        $type: string.split(list.nth($pattern, 2), ',');
        $result: map.deep-merge($result, if(list.nth($pattern, 1) == key, key-type($map, $type...), value-type($map, $type...)));
      }
    }
  }
  @return $result;
}
// Examples.
// $-theme: (
//   dark: (
//     'dark.palette': (),
//     basic large: (
//       '': border,
//       dark: border dark,
//       light: border light
//     ),
//   ),
//   basic: (
//     'default.palette': (),
//     'gray.palette': (
//       'gray': 'gray' color,
//       'gray' dark: 'gray' dark,
//       'gray' light: 'gray' light
//     ),
//     'bg.palette': (
//       bg: bg color,
//       bg dark: bg dark,
//       bg light: bg light
//     ),
//     basic large: (
//       '': border,
//       dark: border dark,
//       light: border light
//     ),
//     extended small: (
//       '': primary,
//       dark: primary dark,
//       light: primary light
//     ),
//     [primary]: (
//       primary dark: primary dark,
//     ),
//     (key1, key2): (
//       primary: primary1
//     ),
//     key1: primary,
//     // calculation
//     calc(400px + 10%): calculation,
//     // bool
//     false: bool,
//     // color
//     #fff: color,
//     // function
//     get-function(append): function,
//     // map
//     (a: 1, b: 2): map,
//     // null
//     null: null,
//     // number
//     15: number,
//     // string
//     firstname: string,
//   )
// );
// pattern: key and/or value type
// @debug type(map.get($-theme, basic), 'key:list', 'value:string');
// @debug type(map.get($-theme, basic), 'value:string,list');
// @debug type(map.get($-theme, basic), 'key:string,list');
// @debug type(map.get($-theme, basic), 'key,value:list,string'); // TODO
Parameters
$map
$mapA map from which properties with values and/or keys of a certain type are picked.
$field-type...
$field-type...A pattern field:type where field can be value or key and type bool, calculation, color, function, list, map, null, number or string, to pick properties with the value and/or key of the specified type.
Return
The return value is a copy of $map with values and/or keys associated with types.
Examples
// Use.
@use '@angular-package/sass/map';
// Examples.
Last updated
Was this helpful?