-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.ts
35 lines (31 loc) · 1.03 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import isArray from "lodash/isArray";
import isPlainObject from "lodash/isPlainObject";
import isNull from "lodash/isNull";
import isString from "lodash/isString";
import isNumber from "lodash/isNumber";
import isBoolean from "lodash/isBoolean";
import isInteger from "lodash/isInteger";
import { getRequired } from "./selectors";
import { DataTypes } from ".";
import type { JSONSchema } from ".";
/**
* Returns a boolean if ID is a required field
*/
export const isRequiredField = (schema: JSONSchema, id: string): boolean => {
const requiredList = getRequired(schema);
return isArray(requiredList) && requiredList.includes(id);
};
/**
* Hash table to determine field values are
* the expected data type. Primarily used in Yup Lazy
* to ensure the field value type are supported
*/
export const isTypeOfValue = {
[DataTypes.STRING]: isString,
[DataTypes.NUMBER]: isNumber,
[DataTypes.BOOLEAN]: isBoolean,
[DataTypes.OBJECT]: isPlainObject,
[DataTypes.NULL]: isNull,
[DataTypes.ARRAY]: isArray,
[DataTypes.INTEGER]: isInteger
};