Skip to content

Commit

Permalink
refactor: move and rename error-to-string function
Browse files Browse the repository at this point in the history
  • Loading branch information
gracetxgao committed Dec 13, 2024
1 parent 4adf2ce commit d712c5d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
13 changes: 13 additions & 0 deletions libs/design/scss/core/error/error-to-string.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$use-string: false !default;

@function error-to-string($message, $override: $use-string) {
@if $override {
@return $message;
} @else {
@error $message;
}
}

@mixin set-use-string($state: true) {
$use-string: $state !global;
}
13 changes: 0 additions & 13 deletions libs/design/scss/core/map/map-get/map-get-error.scss

This file was deleted.

4 changes: 2 additions & 2 deletions libs/design/scss/core/map/map-get/map-get.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@use 'sass:map';
@use './map-get-error';
@use '../../error/error-to-string';

//
// Return a the value of a nested key in a map if it exists.
Expand All @@ -14,7 +14,7 @@
@function daff-map-get($map, $keys...) {
@each $key in $keys {
@if not map.has-key($map, $key) {
@return map-get-error.map-get-error("The map doesn't contain the $key: `#{$key}`'");
@return error-to-string.error-to-string("The map doesn't contain the $key: `#{$key}`'");
}
$map: map.get($map, $key);
}
Expand Down
6 changes: 3 additions & 3 deletions libs/design/scss/core/map/map-get/map-get.spec.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@use 'true' as *;
@use './map-get' as *;
@use './map-get-error';
@use '../../error/error-to-string';

@include describe('map-get') {
$nested-map: (
Expand Down Expand Up @@ -28,7 +28,7 @@

$empty-map: ();

@include map-get-error.set-debug(true);
@include error-to-string.set-use-string(true);

@include it('returns the value of the nested key if it exists in the map') {
@include assert-equal(daff-map-get($map, 'nested', 'string'), '1');
Expand Down Expand Up @@ -61,5 +61,5 @@
);
}

@include map-get-error.set-debug(false);
@include error-to-string.set-use-string(false);
}

0 comments on commit d712c5d

Please sign in to comment.