diia-open-source / be-pkg-utils

European Union Public License 1.2
14 stars 10 forks source link

Rewrite with better semantics and readability #13

Open tshemsedinov opened 4 months ago

tshemsedinov commented 4 months ago

Code readability is terrible, forEach has different semantics, long expressions are totally unreadable https://github.com/diia-open-source/be-pkg-utils/blob/e969374fb769e59ab6bbdb709caeba0199e14a8c/src/session.ts#L3-L15 Please consider at least:

export function profileFeaturesToList(features: UserFeatures): ProfileFeature[] {
    const featuresList: ProfileFeature[] = []

    const entries = Object.entries(features)
    for (const [key, value]: [string, unknown] of entries) {
      if (!value) continue
      featuresList.push(<ProfileFeature>key))
    }

    return featuresList.filter((feature) => {
        if (feature !== ProfileFeature.office) return true
        return features?.[feature]?.status === DiiaOfficeStatus.ACTIVE
    })
}
bohdansec commented 4 months ago

image

У коді, який ви надали, є синтаксична помилка: ви додали зайву закриваючу дужку після <ProfileFeature>key

Також, у вашому коді є багато частин, які можна покращити. Наприклад, я рекомендую використовувати оператор as для приведення типів замість застарілого синтаксису з кутовими дужками, який ви використовували у вашому прикладі <ProfileFeature>key. Цей підхід є більш сучасним, безпечним і бажаним у TypeScript.

vird commented 4 months ago

https://github.com/diia-open-source/be-pkg-utils/pull/25