mirror of
https://github.com/smolgrrr/TAO.git
synced 2024-09-20 17:31:26 +00:00
21 lines
492 B
TypeScript
21 lines
492 B
TypeScript
|
export const uniqBy = <T>(arr: T[], key: keyof T): T[] => {
|
||
|
return Object.values(
|
||
|
arr.reduce(
|
||
|
(map, item) => ({
|
||
|
...map,
|
||
|
[`${item[key]}`]: item,
|
||
|
}),
|
||
|
{},
|
||
|
),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
export const uniqValues = (value: string, index: number, self: string[]) => {
|
||
|
return self.indexOf(value) === index
|
||
|
}
|
||
|
|
||
|
export const dateToUnix = (_date?: Date) => {
|
||
|
const date = _date || new Date()
|
||
|
|
||
|
return Math.floor(date.getTime() / 1000)
|
||
|
}
|