@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
31 lines (22 loc) • 644 B
text/typescript
import { is, toLower } from "ramda";
export const toBoolean = (value: any): boolean | undefined => {
if (is(Boolean, value)) {
return value;
}
return undefined;
};
export const toBooleanWithDefault =
(defaultValue: boolean) =>
(value: any): boolean =>
toBoolean(value) ?? defaultValue;
export const toBooleanWithDefaultTrue = toBooleanWithDefault(true);
export const toBooleanWithDefaultFalse = toBooleanWithDefault(false);
export const isTrue = (value: unknown): boolean => {
if (value === true) {
return true;
}
if (is(String, value) && toLower(value) === "true") {
return true;
}
return false;
};