135}
136
137export const isValidBreadcrumbProps = (props: PossibleBreadcrumbProps): props is BreadcrumbProps => {
138 if (props.option === 'close') {139 return true140 } else if (props.option === 'back') {141 if (props.backTo === 'dynamicText') {142 if (typeof props.onClick === 'function' && typeof props.backToText === 'string') {143 return true144 }145 } else if (props.backTo === 'none' || props.backTo === 'search') {146 return true147 }148 }149 return false
150}
151type PossibleBreadcrumbProps = {
8
9const ajv = new Ajv()
10const validateJsonSchema = (schema: unknown): schema is JSONSchemaType<unknown> => {
11 if (schema && typeof schema === 'object' && ajv.validateSchema(schema)) {12 return true13 }14 return false
15}
16
7 if (!item || typeof item !== 'object') {
8 return false
9 }
10 if ('tsKey' in item) {11 return true12 }13 return false
14}
15
10 })
11 .refine(
12 (keys) => {
13 if (keys.organizationId || keys.serviceId) return true14 else return false15 },
16 { message: 'Requires one of the following: organizationId, serviceId' }
17 )
12 includeUnsupported: z.boolean().optional().default(false),
13 })
14 .refine(({ id, slug }) => {
15 if (!id && !slug) {16 return false17 }18 return true
19 }, 'Missing required params: `id` or `slug`')
20export type TGetAttributesSchema = z.infer<typeof ZGetAttributesSchema>
The following pattern:
if (condition) {
return true
}
return false
can be refactored to:
return condition
When condition
is not a boolean value,
it can be cast into one using the Boolean
constructor.
function isEven(num: number) {
if (num % 2 === 0) return true
return false
}
async function userExists(name: string) {
if (await db.getUser(name)) return true
return false
}
function isEven(num: number) {
return num % 2 === 0
}
async function userExists(name: string) {
return Boolean(await db.getUser(name))
}