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 🙏

© 2024 – Pkg Stats / Ryan Hefner

decline-word

v1.4.0

Published

Declines words in Russian, Ukrainian and English languages.

Downloads

1,303

Readme

All dependencies Reported vulnerabilities Commits NPM-version Total downloads Developed by
Publish size Install size Minified size Minified + gzipped size

[email protected]

Helps you to inflect words of Russian, Ukrainian and English languages.
It may work for some other languages, who knows.

Installation

decline-word is available via NPM:

$ npm i [email protected]

Usage

For Russian and Ukrainian languages:

| Parameter | Required | Default value | Value | |-----------|----------|---------------|-----------------------------------------------------------------| | 1st | true | | amount of items | | 2nd | true | | main part of the word (unchangeable beginning of each form) | | 3rd | false | '' | word ending for 1 item | | 4th | false | '' | word ending for 2 items | | 5th | false | '' | word ending for 5 items |

import declineWord from 'decline-word';

console.log(`12 ${declineWord(12, 'яблок', 'о', 'а')}`);  // 12 яблок
console.log(`22 ${declineWord(22, 'яблок', 'о', 'а')}`);  // 22 яблока
console.log(`159 ${declineWord(159, 'яблок', 'о', 'а')}`);  // 159 яблок
console.log(`1151 ${declineWord(1151, 'яблок', 'о', 'а')}`);  // 1151 яблоко

console.log(`1 ${declineWord(1, 'апельсин', '', 'и', 'ів')}`);  // 1 апельсин
console.log(`11 ${declineWord(11, 'апельсин', '', 'и', 'ів')}`);  // 11 апельсинів
console.log(`84 ${declineWord(84, 'апельсин', '', 'и', 'ів')}`);  // 84 апельсини
console.log(`147 ${declineWord(147, 'апельсин', '', 'и', 'ів')}`);  // 147 апельсинів

console.log(`0 ${declineWord(0, '', 'гра', 'гри', 'ігор')}`);  // 0 ігор
console.log(`1 ${declineWord(1, '', 'гра', 'гри', 'ігор')}`);  // 1 гра
console.log(`4 ${declineWord(4, '', 'гра', 'гри', 'ігор')}`);  // 4 гри
console.log(`25 ${declineWord(25, '', 'гра', 'гри', 'ігор')}`);  // 25 ігор

For English language:

There are some differences of parameter default values comparing to Russian and Ukrainian languages.

| Parameter | Required | Default value | Value | |-----------|----------|-------------------|-----------------------------------------------------------------| | 1st | true | | amount of items | | 2nd | true | | main part of the word (unchangeable beginning of each form) | | 3rd | false | '' | word ending for 1 item | | 4th | false | 's' | word ending for 2 items | | 5th | false | <4th parameter> | word ending for 5 items |

This difference makes more convenience for using English words.

Note: decline-word declines English words incorrect according to language rules. Just because of if not equal to one is very simple check algorithm (and I'm too lazy to change already made one) this package declines them according to Russian/Ukrainian language rules. Do not use decline-word for English language if you want to decline words correctly.

import declineWord from 'decline-word';

console.log(`1 ${declineWord(1, 'door')}`);  // 1 door
console.log(`10 ${declineWord(10, 'door')}`);  // 10 doors

console.log(`11 ${declineWord(11, 'hero', '', 'es')}`);  // 11 heroes
console.log(`21 ${declineWord(21, 'hero', '', 'es')}`);  // 21 hero (but correct is "heros")

console.log(`5 ${declineWord(5, 'cand', 'y', 'ies')}`);  // 5 candies
console.log(`101 ${declineWord(101, 'cand', 'y', 'ies')}`);  // 101 candy (but correct is "candies")

// declineWord(31, 't', 'ooth', 'eeth') or...
console.log(`31 ${declineWord(31, '', 'tooth', 'teeth')}`);  // 31 tooth (but correct is "teeth")
console.log(`32 ${declineWord(32, '', 'tooth', 'teeth')}`);  // 32 teeth

Advanced usage

import { declineWrapper } from 'decline-word';

const declApples = declineWrapper('яблок', 'о', 'а');
const declOranges = declineWrapper('апельсин', '', 'а', 'ов');
const declPears = declineWrapper('груш', 'а', 'и');

for(let i = 0; i <= 6; i++) {
  console.log(`${i} ${declApples(i)} | ${i} ${declOranges(i)} | ${i} ${declPears(i)}`);
}

/*
  1st iteration: '0 яблок | 0 апельсинов | 0 груш'
  2nd iteration: '1 яблоко | 1 апельсин | 1 груша'
  3rd iteration: '2 яблока | 2 апельсина | 2 груши'
  4th iteration: '3 яблока | 3 апельсина | 3 груши'
  5th iteration: '4 яблока | 4 апельсина | 4 груши'
  6th iteration: '5 яблок | 5 апельсинов | 5 груш'
  7th iteration: '6 яблок | 6 апельсинов | 6 груш'
*/

Declination of cases:

import { declineWrapper } from 'decline-word';

// Nominative case, именительный падеж, називний відмінок
const nomCase = declineWrapper('падеж', '', 'а', 'ей');
console.log('один', nomCase(1));  // один падеж
console.log('два', nomCase(2));  // два падежа
console.log('пять', nomCase(5));  // пять падежей

// Genitive case, родительный падеж, родовий відмінок
const genCase = declineWrapper('падеж', 'а', 'ей', 'ей');
console.log('одного', genCase(1));  // одного падежа
console.log('двух', genCase(2));  // двух падежей
console.log('пяти', genCase(5));  // пяти падежей

// Dative case, дательный падеж, давальний відмінок
const datCase = declineWrapper('падеж', 'у', 'ам', 'ам');
console.log('одному', datCase(1));  // одному падежу
console.log('двум', datCase(2));  // двум падежам
console.log('пяти', datCase(5));  // пяти падежам

// Accusative case, винительный падеж, знахідний відмінок
const accCase = declineWrapper('падеж', '', 'а', 'ей');
console.log('один', accCase(1));  // один падеж
console.log('два', accCase(2));  // два падежа
console.log('пять', accCase(5));  // пять падежей

// Instrumental case, творительный падеж, орудний відмінок
const insCase = declineWrapper('падеж', 'ом', 'ами', 'ами');
console.log('одним', insCase(1));  // одним падежом
console.log('двумя', insCase(2));  // двумя падежами
console.log('пятью', insCase(5));  // пятью падежами

// Prepositional case, предложный падеж, місцевий відмінок
const prepCase = declineWrapper('падеж', 'е', 'ах', 'ах');
console.log('на одном', prepCase(1));  // на одном падеже
console.log('на двух', prepCase(2));  // на двух падежах
console.log('на пяти', prepCase(5));  // на пяти падежах

Testing

$ npm test

See also


Your improve suggestions and bug reports are welcome any time.