Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: betsol/numerous
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.3
Choose a base ref
...
head repository: betsol/numerous
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.0
Choose a head ref
  • 6 commits
  • 863 files changed
  • 1 contributor

Commits on Aug 11, 2021

  1. Multiple changes:

    - done some major refactoring
    - changed locale file format
    - updated locales generation script
    - updated CLDR to the latest version and re-generated all the locales
    - updated library API to better support modern front-end development practices
    - added TypeScript declarations
    - updated README
    - updated dependencies
    - updated package manifest file
    - added npm lock file
    
    Signed-off-by: Slava Fomin II <slava@fomin.io>
    slavafomin committed Aug 11, 2021

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    kamilmysliwiec Kamil Mysliwiec
    Copy the full SHA
    0acb09d View commit details
  2. Multiple changes:

    - refactored demo application
    - introduced webpack build for demo application
    - removed bower
    - added hack to prevent webpack from importing all the locales
    - improved types
    - updated dependencies
    
    Signed-off-by: Slava Fomin II <slava@fomin.io>
    slavafomin committed Aug 11, 2021

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    kamilmysliwiec Kamil Mysliwiec
    Copy the full SHA
    e014a39 View commit details
  3. Updated project manifest

    Signed-off-by: Slava Fomin II <slava@fomin.io>
    slavafomin committed Aug 11, 2021
    Copy the full SHA
    4424edf View commit details
  4. Fixed Gulpfile

    Signed-off-by: Slava Fomin II <slava@fomin.io>
    slavafomin committed Aug 11, 2021
    Copy the full SHA
    d74c774 View commit details
  5. Updated changelog

    Signed-off-by: Slava Fomin II <slava@fomin.io>
    slavafomin committed Aug 11, 2021
    Copy the full SHA
    0eaea0b View commit details
  6. 2.0.0

    slavafomin committed Aug 11, 2021
    Copy the full SHA
    e095ade View commit details
Showing 863 changed files with 24,981 additions and 10,566 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.log
Thumbs.db
.DS_Store?
/.idea/
/.publish
/node_modules/
/bower_components/
/.publish

/**/dist/

*.log
.DS_Store?
Thumbs.db
15 changes: 15 additions & 0 deletions changelog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@

# Numerous Changelog

This file documents all the **significant** changes over the history of this library.


## Version 2.0.0
(August 11, 2021)

- done some major refactoring
- changed locale file format
- updated CLDR to the latest version and re-generated all the locales
- updated library API to better support modern front-end development practices
- added TypeScript support
- updated README
- updated dependencies
- updated package manifest file
- removed bower support


## Version 1.0.0
(September 17, 2016)

151 changes: 90 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,108 +1,137 @@

# Numerous

[![npm version](https://badge.fury.io/js/numerous.svg)][repo-npm]
![Bower](https://img.shields.io/bower/v/numerous.svg)
[![Build Status](https://travis-ci.org/betsol/numerous.svg)](https://travis-ci.org/betsol/numerous)


Tiny pluralization library in JavaScript that supports almost any language.

For more details, please, read the article:<br>
[How to pluralize any word in different languages using JavaScript?][article]


## Features

- supports ~639 locales by means of [CLDR][lib-cldr] (built-in). See the [complete list][locales].
- could be run in node or browser environment
- a completely stand-alone solution (no APIs or polyfills required)
- supports **789** locales by means of [CLDR][lib-cldr] (built-in).
See the [complete list][locales]
- could be run in Node.js or browser
- very lightweight *(just ~300 Bytes compressed)*
- almost no dependencies
- TypeScript support out of the box


## Demo

Please see [the demo][site].
Please see [the demo][demo].


## Usage

1. Require library
2. ???
3. Pluralize!
## Install

For more details, please, read the article:
[«How to pluralize any word in different languages using JavaScript?»][article].
```shell
npm install --save numerous
```


### With Node
## Usage

1). Install module via npm: `npm i -S numerous`.
### Node.js

2). Require it:
In Node.js environment the library automatically loads
the required locales on first use.

```js
const numerous = require('numerous');
```

// Create an instance of Numerous using preferred locale
const { pluralize } = numerous.create('en');

### In browser
// Specify the list of variants
const variants = {
one: 'apple',
other: 'apples',
};

1). Install package via Bower: `bower install --save betsol/numerous`.
// Pluralize!

2). Add library to your page:
// I have 1 apple
const applesCount = 1;
console.log(`I have ${applesCount} ${pluralize(applesCount, variants)}`);

```html
<script src="/bower_components/numerous/lib/numerous.js"></script>
// She had 5 apples
const applesCount = 5;
console.log(`She had ${applesCount} ${pluralize(applesCount, variants)}`);
```

3). Add required locales to your page:

```html
<script src="/bower_components/numerous/locales/en.js"></script>
<script src="/bower_components/numerous/locales/ru.js"></script>
```
### Browser

You could use npm instead of bower above.
In browser environment you need to load all the locales that you are
planning to use before initializing the instance of Numerous.
This is done in order to provide optimal bundle size.

```js
import * as numerous from 'numerous';

## Examples
import enLocale from 'numerous/locales/en';
import ruLocale from 'numerous/locales/ru';

### Static Example
// Register single locale
numerous.registerLocale(enLocale);

```js
// Or register multiple locales at the same time
numerous.registerLocale([
enLocale,
ruLocale,
]);

// Returns "apple".
numerous.pluralize('en', 1, {
// Create an instance of Numerous
// using previously registered locale
const { pluralize } = numerous.create('en');

// Specify the list of variants
const variants = {
one: 'apple',
other: 'apples'
});
other: 'apples',
};

// Returns "cats".
numerous.pluralize('en', 2, {
one: 'cat',
other: 'cats'
});
// Pluralize!

// I have 1 apple
const applesCount = 1;
console.log(`I have ${applesCount} ${pluralize(applesCount, variants)}`);

// She had 5 apples
const applesCount = 5;
console.log(`She had ${applesCount} ${pluralize(applesCount, variants)}`);
```

### Instance Example

```js
### Without instantiating

// Creating instances for specific locales.
var englishPluralizer = numerous.create('en');
var russianPluralizer = numerous.create('ru');
You can use the library without instantiating it first.
You just need to specify the locale on each call.

```js

// Returns "apple".
englishPluralizer.pluralize(1, {
// "apple"
numerous.pluralize('en', 1, {
one: 'apple',
other: 'apples'
});

// Returns "яблока".
russianPluralizer.pluralize(2, {
one: 'яблоко',
few: 'яблока',
many: 'яблок'
// "cats"
numerous.pluralize('en', 2, {
one: 'cat',
other: 'cats'
});

```

## Examples

Please see [test files](./test) for more use cases.


## Changelog

@@ -111,20 +140,20 @@ Please see the [complete changelog][changelog] for list of changes.

## Contributors

This library was made possible by [it's contributors][contributors].
- [Slava Fomin II](https://github.com/slavafomin) (author)


## Developer guide
## Developer Guide

Fork, clone, create a feature branch, add tests, commit, create a PR.

Run:

- `npm install && bower install` to initialize the project
- `npm run-script build-locales` to build fresh list of locales
- `npm install` to initialize the project
- `npm run build-locales` to build fresh locales
- `npm test` to test the library
- `npm start` to run local webserver for demos page
- `npm run-script demo-deploy` to deploy GitHub Pages
- `npm run demo:run` to run local webserver with demo page
- `npm run demo:deploy` to deploy GitHub Pages


## Feedback
@@ -153,7 +182,7 @@ Thank you!

The MIT License (MIT)

Copyright (c) 2015-2016 Slava Fomin II, BETTER SOLUTIONS
2015—2021 Slava Fomin II

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -174,14 +203,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


[changelog]: changelog.md
[changelog]: CHANGELOG.md
[contributors]: https://github.com/betsol/numerous/graphs/contributors
[so-ask]: http://stackoverflow.com/questions/ask?tags=node.js
[email]: mailto:s.fomin@betsol.ru
[email]: mailto:slava@fomin.io
[new-issue]: https://github.com/betsol/numerous/issues/new
[locales]: docs/locales.md
[lib-cldr]: https://github.com/papandreou/node-cldr
[repo-gh]: https://github.com/betsol/numerous
[repo-npm]: https://www.npmjs.com/package/numerous
[site]: http://betsol.github.io/numerous/
[demo]: http://betsol.github.io/numerous/
[article]: https://gist.github.com/slavafomin/f2e5259cab17d55af5d9fa4c2c2baa08
Loading