-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import isEqual from 'lodash/isEqual'; | ||
import { deepEqual } from "fast-equals"; | ||
Check failure on line 1 in packages/utils/src/enumOptionsIsSelected.ts
|
||
|
||
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from './types'; | ||
import { EnumOptionsType, RJSFSchema, StrictRJSFSchema } from "./types"; | ||
Check failure on line 3 in packages/utils/src/enumOptionsIsSelected.ts
|
||
|
||
/** Determines whether the given `value` is (one of) the `selected` value(s). | ||
* | ||
* @param value - The value being checked to see if it is selected | ||
* @param selected - The current selected value or list of values | ||
* @returns - true if the `value` is one of the `selected` ones, false otherwise | ||
*/ | ||
export default function enumOptionsIsSelected<S extends StrictRJSFSchema = RJSFSchema>( | ||
value: EnumOptionsType<S>['value'], | ||
selected: EnumOptionsType<S>['value'] | EnumOptionsType<S>['value'][] | ||
export default function enumOptionsIsSelected< | ||
Check failure on line 11 in packages/utils/src/enumOptionsIsSelected.ts
|
||
S extends StrictRJSFSchema = RJSFSchema, | ||
>( | ||
value: EnumOptionsType<S>["value"], | ||
selected: EnumOptionsType<S>["value"] | EnumOptionsType<S>["value"][], | ||
) { | ||
if (Array.isArray(selected)) { | ||
return selected.some((sel) => isEqual(sel, value)); | ||
return selected.some((sel) => deepEqual(sel, value)); | ||
} | ||
return isEqual(selected, value); | ||
return deepEqual(selected, value); | ||
} |