Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Replace lodash has() function
Browse files Browse the repository at this point in the history
Replace lodash has
  • Loading branch information
mikejolley committed Apr 20, 2023
1 parent e4f77e5 commit 96faef9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
16 changes: 0 additions & 16 deletions assets/js/data/utils/has-in-state.js

This file was deleted.

27 changes: 27 additions & 0 deletions assets/js/data/utils/has-in-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const has = ( obj: Record< string, unknown >, path: string[] ): boolean => {
return (
!! path &&
!! path.reduce< unknown >(
( prevObj, key ) =>
typeof prevObj === 'object' && prevObj !== null
? ( prevObj as Record< string, unknown > )[ key ]
: undefined,
obj
)
);
};

/**
* Utility for returning whether the given path exists in the state.
*
* @param {Object} state The state being checked
* @param {Array} path The path to check
*
* @return {boolean} True means this exists in the state.
*/
export default function hasInState(
state: Record< string, unknown >,
path: string[]
): boolean {
return has( state, path );
}

0 comments on commit 96faef9

Please sign in to comment.