13 lines
548 B
JavaScript
13 lines
548 B
JavaScript
/**
|
|
* Normalize an array of forwards by converting the pct from a string to a number
|
|
* Also extracts nym from nested user object, if necessary
|
|
* @param {*} forward Array of forward objects ({nym?: string, pct: string, user?: { name: string } })
|
|
* @returns normalized array, or undefined if not provided
|
|
*/
|
|
export const normalizeForwards = (forward) => {
|
|
if (!Array.isArray(forward)) {
|
|
return undefined
|
|
}
|
|
return forward.filter(fwd => fwd.nym || fwd.user?.name).map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) }))
|
|
}
|