Skip to content

Commit

Permalink
Remove lodash use from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jul 5, 2021
1 parent d08a3ae commit c3355b1
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions packages/block-editor/src/components/border-radius-control/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty, isNumber } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -73,16 +68,7 @@ export function getAllValue( values = {} ) {
: '';
const unit = mode( allUnits );

/**
* The isNumber check is important. On reset actions, the incoming value
* may be null or an empty string.
*
* Also, the value may also be zero (0), which is considered a valid unit value.
*
* isNumber() is more specific for these cases, rather than relying on a
* simple truthy check.
*/
const allValue = isNumber( value ) ? `${ value }${ unit }` : null;
const allValue = value === 0 || value ? `${ value }${ unit }` : null;

return allValue;
}
Expand All @@ -107,9 +93,20 @@ export function isValuesMixed( values = {} ) {
* @return {boolean} Whether values are mixed.
*/
export function isValuesDefined( values ) {
return (
values !== undefined &&
( typeof values === 'string' ||
! isEmpty( Object.values( values ).filter( Boolean ) ) )
);
if ( ! values ) {
return false;
}

// A string value represents a shorthand value.
if ( typeof values === 'string' ) {
return true;
}

// An object represents longhand border radius values, if any are set
// flag values as being defined.
const filteredValues = Object.values( values ).filter( ( value ) => {
return !! value || value === 0;
} );

return !! filteredValues.length;
}

0 comments on commit c3355b1

Please sign in to comment.