npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pl-declension

v0.1.1

Published

Zero-dependency utility for Polish noun declension. Provides simple pluralization rules for i18n and dynamic UI strings.

Readme

pl-declension

npm version npm downloads

Większość bibliotek do pluralizacji działa na schemacie 1 item, 2 items. W Polsce mamy:

  • 1 komentarz
  • 2 komentarze
  • 5 komentarzy

Ta paczka dostarcza jedną małą funkcję: declination(count, [one, few, many]).

Instalacja

npm i pl-declension

Użycie

import { declination } from 'pl-declension';

const n = 5;
const label = declination(n, ['komentarz', 'komentarze', 'komentarzy']);

console.log(`${n} ${label}`);

Możesz też przekazać formy jako obiekt:

import { declination } from 'pl-declension';

const n = 2;
const label = declination(n, { one: 'komentarz', few: 'komentarze', many: 'komentarzy' });

API

declination(count, forms)

  • count: number | bigint
  • forms:
    • tablica: [one, few, many]
    • albo obiekt: { one, few, many }

Zwraca jedną z form w zależności od liczby.

format(count, forms, options?)

Zwraca gotowy string, domyślnie z liczbą:

import { format } from 'pl-declension';

format(5, ['komentarz', 'komentarze', 'komentarzy']);
// => "5 komentarzy"

format(5, ['komentarz', 'komentarze', 'komentarzy'], { includeNumber: false });
// => "komentarzy"

Opcje:

  • includeNumber?: boolean (domyślnie true)
  • separator?: string (domyślnie spacja)
  • number?: (count) => string | number (opcjonalny formatter liczby)

Przykład formattera:

import { format } from 'pl-declension';

format(10000, ['komentarz', 'komentarze', 'komentarzy'], {
  number: (n) => Number(n).toLocaleString('pl-PL')
});
// => "10 000 komentarzy" (zależnie od ustawień środowiska)

formIndex(count)

Zwraca indeks formy: 0 | 1 | 2.

Przydatne, jeśli wolisz sam wybierać z tablicy:

import { formIndex } from 'pl-declension';

const forms = ['komentarz', 'komentarze', 'komentarzy'];
const label = forms[formIndex(22)];

createDeclension(forms)

Tworzy wyspecjalizowaną funkcję dla konkretnych form (wygodne w UI):

import { createDeclension } from 'pl-declension';

const comments = createDeclension(['komentarz', 'komentarze', 'komentarzy']);

comments(1); // "komentarz"
comments(2); // "komentarze"
comments(5); // "komentarzy"

assertForms(forms)

Waliduje i normalizuje formy do obiektu { one, few, many }. Przydatne, jeśli chcesz walidować na starcie aplikacji.

Aliasy

Jeśli wolisz inną nazwę:

  • pluralizePl (alias declination)
  • decline (alias declination)

Reguły

  • one: tylko dla 1
  • few: dla 2-4, z wyjątkiem 12-14
  • many: dla reszty (w tym 0)

Dla liczb niecałkowitych (np. 1.5) zwracana jest forma many.

Intl.PluralRules

W JavaScripcie istnieje Intl.PluralRules, ale w praktyce i tak potrzebujesz mapowania na własne formy i trzech wariantów dla języka polskiego. Ta paczka celuje w prosty, powtarzalny przypadek front-endowy: podajesz liczbę i trzy formy, dostajesz string.

Release

Konwencja tagów:

  • v0.1.0, v0.1.1, ...

Benchmark

Możesz odpalić prosty benchmark lokalnie:

npm run bench

Przykłady

import { format } from 'pl-declension';

const n = 22;
console.log(format(n, ['komentarz', 'komentarze', 'komentarzy']));
// => "22 komentarze"
import { format } from 'pl-declension';

const n = 12;
console.log(format(n, ['komentarz', 'komentarze', 'komentarzy']));
// => "12 komentarzy"