Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Use a simple ternary for trivial singular/plural, not Intl.PluralRules
For a basic English singular/plural toggle, a count-based ternary is clearer than pulling in Intl.PluralRules.
Bad example
| 1 | const plurals = new Intl.PluralRules('en-US'); |
| 2 | const word = plurals.select(count) === 'one' ? 'item' : 'items'; |
| 3 | console.log(`Found ${count} ${word}`); |
Explanation (EN)
Intl.PluralRules adds machinery for a case that doesn't need it; it shines for locale-dependent plural forms, not a fixed English 's' suffix.
Objašnjenje (HR)
Intl.PluralRules dodaje masineriju za slucaj kojem ne treba; korisna je za plurale ovisne o lokalizaciji, a ne za fiksni engleski nastavak 's'.
Good example
| 1 | console.log(`Found ${count} item${count === 1 ? '' : 's'}`); |
Explanation (EN)
A count-based ternary expresses the same toggle in one readable line with no extra objects or API surface.
Objašnjenje (HR)
Ternar na temelju broja izrazava isti prekidac u jednom citljivom retku bez dodatnih objekata ili API povrsine.
Exceptions / Tradeoffs (EN)
Use Intl.PluralRules (or a real i18n library) when output must support multiple locales with genuinely different plural categories.
Iznimke / Tradeoffi (HR)
Koristi Intl.PluralRules (ili pravu i18n biblioteku) kada izlaz mora podrzavati vise lokalizacija sa stvarno razlicitim kategorijama plurala.