@advdominion/pluralize
This commit is contained in:
parent
205ea19086
commit
0bb60a0e0a
|
@ -0,0 +1,11 @@
|
|||
# is
|
||||
|
||||
Склонение существительных в зависимости от чила
|
||||
|
||||
## Использование
|
||||
|
||||
```js
|
||||
import { pluralize } from '@advdominion/pluralize';
|
||||
|
||||
console.log(pluralize(1, ['яблоко', 'яблока', 'яблок']));
|
||||
```
|
|
@ -0,0 +1,14 @@
|
|||
export const pluralize = (count, words) => {
|
||||
count = Math.abs(count) % 100;
|
||||
const count10 = count % 10;
|
||||
if (count > 10 && count < 20) {
|
||||
return words[2];
|
||||
}
|
||||
if (count10 > 1 && count10 < 5) {
|
||||
return words[1];
|
||||
}
|
||||
if (count10 === 1) {
|
||||
return words[0];
|
||||
}
|
||||
return words[2];
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "@advdominion/pluralize",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.optiweb.ru/public/helpers.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue