27
28 /** Check multiple permissions */
29 if (Array.isArray(meta.hasPerm)) {
30 if (meta.hasPerm.every((perm) => ctx.session?.user?.permissions?.includes(perm))) { 31 return true 32 } 33 return false
34 }
35
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 )
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))
}