Skip to content

Commit

Permalink
object & string functions bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Black Mirror committed Apr 27, 2018
1 parent 11b5b79 commit 054b728
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions scss/types/_object.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
///
/// $p: get($o, 'prop1.subprop2'); // #444
/// @return {any}
@function get($map, $path) {
$keys: $path;
@function get($o, $p) {
$keys: $p;

@if is-string($path) {
$keys: string-split($path);
@if is-string($p) {
$keys: string-split($p);
}

$length: length($keys);
Expand All @@ -47,7 +47,7 @@
$keys: nth($keys, 1);
}

$get: map-get($map, nth($keys, 1));
$get: map-get($o, nth($keys, 1));

@if $length > 1 {
@for $i from 2 through $length {
Expand Down Expand Up @@ -103,11 +103,11 @@
/// )
///
/// @return {any}
@function set($obj, $path, $value) {
$keys: $path;
@function set($o, $p, $v) {
$keys: $p;

@if is-string($path) {
$keys: string-split($path);
@if is-string($p) {
$keys: string-split($p);
}

$length: length($keys);
Expand All @@ -116,10 +116,10 @@


@if $length > 1 {
$map-level: get($obj, $keys);
$map-level: get($o, $keys);
}

$merge: (nth($keys, $length): $value);
$merge: (nth($keys, $length): $v);

@if $map-level {
$get-keys: get-keys($keys, $length);
Expand All @@ -132,7 +132,7 @@

@if $j > 1 {
$get-keys: get-keys($keys, $j);
$map-level: get($obj, $get-keys);
$map-level: get($o, $get-keys);

@if $map-level {
$merge: map-merge($map-level, ($key: $merge));
Expand All @@ -146,9 +146,9 @@
}
}

$obj: map-merge($obj, $merge);
$o: map-merge($o, $merge);

@return $obj;
@return $o;
}

/// Deep extend/merge function for objects
Expand Down Expand Up @@ -201,7 +201,7 @@
/// )
///
/// @return {any}
@function extend($object, $objects...) {
@function extend($o, $objects...) {
$max: length($objects); // Loop through all maps in $objects...

@for $i from 1 through $max {
Expand All @@ -210,14 +210,14 @@

@each $key, $value in $current {
// If value is a nested map and same key from object is a nested map as well
@if is-object($value) and is-object(map-get($object, $key)) {
@if is-object($value) and is-object(map-get($o, $key)) {
// Recursive extend
$value: extend(get($object, $key), $value);
$value: extend(get($o, $key), $value);
} // Merge current tuple with object

$object: map-merge($object, ($key: $value));
$o: map-merge($o, ($key: $value));
}
}

@return $object;
@return $o;
}
2 changes: 1 addition & 1 deletion scss/types/_string.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/// @param {string} $n - the needle
/// @return {number}
@function string-index($h, $n) {
@return str-index($n, $n);
@return str-index($h, $n);
}

/// Inserts string $i in string $s at $p position
Expand Down

0 comments on commit 054b728

Please sign in to comment.