This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/utils.ts
Dominik Pschenitschni 4655e1ce34
All checks were successful
continuous-integration/drone/pr Build is passing
feat: update eslint config
support async component, see: https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
2022-10-04 13:45:16 +02:00

26 lines
804 B
TypeScript

export function findIndexById<T extends {id: string | number}>(array : T[], id : string | number) {
return array.findIndex(({id: currentId}) => currentId === id)
}
export function findById<T extends {id: string | number}>(array : T[], id : string | number) {
return array.find(({id: currentId}) => currentId === id)
}
export function includesById(array: [], id: string | number) {
return array.some(({id: currentId}) => currentId === id)
}
// https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_isnil
export function isNil(value: unknown) {
return value == null
}
export function omitBy(obj: Record<string, unknown>, check: (value: unknown) => boolean) {
if (isNil(obj)) {
return {}
}
return Object.fromEntries(
Object.entries(obj).filter(([, value]) => !check(value)),
)
}