n2words 1.15.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +13 -29
- package/lib/classes/{AbstractLanguage.mjs → AbstractLanguage.js} +2 -2
- package/lib/classes/{BaseLanguage.mjs → BaseLanguage.js} +3 -3
- package/lib/i18n/{AR.mjs → AR.js} +1 -1
- package/lib/i18n/{AZ.mjs → AZ.js} +1 -1
- package/lib/i18n/{CZ.mjs → CZ.js} +1 -1
- package/lib/i18n/{DE.mjs → DE.js} +1 -1
- package/lib/i18n/{DK.mjs → DK.js} +1 -1
- package/lib/i18n/{EN.mjs → EN.js} +1 -1
- package/lib/i18n/{ES.mjs → ES.js} +1 -1
- package/lib/i18n/{FA.mjs → FA.js} +1 -1
- package/lib/i18n/{FR.mjs → FR.js} +1 -1
- package/lib/i18n/{HE.mjs → HE.js} +1 -1
- package/lib/i18n/{HR.mjs → HR.js} +1 -1
- package/lib/i18n/{HU.mjs → HU.js} +1 -1
- package/lib/i18n/{ID.mjs → ID.js} +1 -1
- package/lib/i18n/{IT.mjs → IT.js} +1 -1
- package/lib/i18n/{KO.mjs → KO.js} +1 -1
- package/lib/i18n/{LT.mjs → LT.js} +1 -1
- package/lib/i18n/{LV.mjs → LV.js} +1 -1
- package/lib/i18n/{NL.mjs → NL.js} +1 -1
- package/lib/i18n/{NO.mjs → NO.js} +1 -1
- package/lib/i18n/{PL.mjs → PL.js} +1 -1
- package/lib/i18n/{PT.mjs → PT.js} +1 -1
- package/lib/i18n/{RU.mjs → RU.js} +1 -1
- package/lib/i18n/{SR.mjs → SR.js} +1 -1
- package/lib/i18n/{TR.mjs → TR.js} +1 -1
- package/lib/i18n/{UK.mjs → UK.js} +1 -1
- package/lib/i18n/{VI.mjs → VI.js} +1 -1
- package/lib/i18n/{ZH.mjs → ZH.js} +1 -1
- package/lib/{n2words.mjs → n2words.js} +28 -28
- package/package.json +44 -36
- package/.editorconfig +0 -13
- package/.eslintrc.json +0 -105
- package/.gitattributes +0 -5
- package/bench.mjs +0 -94
- package/dist/n2words.js +0 -1
- package/examples/node.mjs +0 -10
- package/webpack.config.js +0 -31
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
[](https://coveralls.io/github/forzagreen/n2words?branch=master)
|
|
5
5
|
[](https://npmjs.com/package/n2words)
|
|
6
6
|
[](https://npmjs.com/package/n2words)
|
|
7
|
+
[](https://www.jsdelivr.com/package/npm/n2words)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
__n2words__ converts a numerical number into a written one, supports [27 languages](https://github.com/forzagreen/n2words#supported-languages), and has zero dependencies.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## How To
|
|
11
|
+
## Example
|
|
13
12
|
|
|
14
13
|
```js
|
|
15
14
|
n2words(123) // 'one hundred and twenty-three'
|
|
@@ -20,6 +19,8 @@ n2words(123, {lang: 'es'}) // 'ciento veintitrés'
|
|
|
20
19
|
n2words(123, {lang: 'ar'}) // 'مائة و ثلاثة و عشرون'
|
|
21
20
|
```
|
|
22
21
|
|
|
22
|
+
See the [Wiki](https://github.com/forzagreen/n2words/wiki) for examples and advanced usage.
|
|
23
|
+
|
|
23
24
|
## Install
|
|
24
25
|
|
|
25
26
|
```sh
|
|
@@ -34,42 +35,28 @@ n2words is also available on [jsDelivr](https://jsdelivr.com/package/npm/n2words
|
|
|
34
35
|
|
|
35
36
|
```js
|
|
36
37
|
import n2words from 'n2words'
|
|
37
|
-
|
|
38
|
-
// Source file
|
|
39
|
-
import n2words from 'n2words/lib/n2words.mjs'
|
|
40
|
-
|
|
41
|
-
// Individual languages (recommended)
|
|
42
|
-
import n2wordsEN from 'n2words/lib/i18n/EN.mjs'
|
|
43
38
|
```
|
|
44
39
|
|
|
45
40
|
### CommonJS
|
|
46
41
|
|
|
47
42
|
```js
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// Dynamic Import (source files)
|
|
51
|
-
import('n2words/lib/n2words.mjs').then(n2words => {
|
|
43
|
+
// Dynamic Import
|
|
44
|
+
import('n2words').then(n2words => {
|
|
52
45
|
// Available via "default" method
|
|
53
46
|
n2words.default(100)
|
|
54
47
|
})
|
|
55
|
-
|
|
56
|
-
// Individual languages
|
|
57
|
-
import('n2words/lib/i18n/EN.mjs').then(n2wordsEN => {
|
|
58
|
-
n2wordsEN.default(100)
|
|
59
|
-
})
|
|
60
48
|
```
|
|
61
49
|
|
|
62
50
|
### Browser
|
|
63
51
|
|
|
64
52
|
```html
|
|
65
53
|
<script src="n2words.js"></script>
|
|
54
|
+
<script>
|
|
55
|
+
n2words(100)
|
|
56
|
+
</script>
|
|
66
57
|
```
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- Cardinal numbers
|
|
71
|
-
- Decimal numbers
|
|
72
|
-
- Negative numbers
|
|
59
|
+
You can also [import only specific languages](https://github.com/forzagreen/n2words/wiki/Importing-only-specific-languages) if you don't need all of them.
|
|
73
60
|
|
|
74
61
|
## Supported Languages
|
|
75
62
|
|
|
@@ -103,10 +90,7 @@ import('n2words/lib/i18n/EN.mjs').then(n2wordsEN => {
|
|
|
103
90
|
|
|
104
91
|
## Contributing
|
|
105
92
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
All help is welcome!
|
|
109
|
-
|
|
93
|
+
__This library is in active development.__ We are looking to improve the design and process for language contributors as well as add more languages.
|
|
110
94
|
## License
|
|
111
95
|
|
|
112
|
-
MIT
|
|
96
|
+
[MIT](https://github.com/forzagreen/n2words/blob/master/LICENSE)
|
|
@@ -11,10 +11,10 @@ export default class {
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @param {object} options Options for class.
|
|
14
|
-
* @param {string} [options.negativeWord
|
|
14
|
+
* @param {string} [options.negativeWord] Word that precedes a negative number (if any).
|
|
15
15
|
* @param {string} options.separatorWord Word that separates cardinal numbers (i.e. "and").
|
|
16
16
|
* @param {string} options.zero Word for 0 (i.e. "zero").
|
|
17
|
-
* @param {string} [options.spaceSeparator
|
|
17
|
+
* @param {string} [options.spaceSeparator] Character that separates words.
|
|
18
18
|
*/
|
|
19
19
|
constructor(options) {
|
|
20
20
|
// Merge supplied options with defaults
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import AbstractLanguage from './AbstractLanguage.
|
|
1
|
+
import AbstractLanguage from './AbstractLanguage.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates new common language class that uses a highest matching word value algorithm.
|
|
@@ -11,10 +11,10 @@ export default class extends AbstractLanguage {
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @param {object} options Options for class.
|
|
14
|
-
* @param {string} [options.negativeWord
|
|
14
|
+
* @param {string} [options.negativeWord] Word that precedes a negative number (if any).
|
|
15
15
|
* @param {string} options.separatorWord Word that separates cardinal numbers (i.e. "and").
|
|
16
16
|
* @param {string} options.zero Word for 0 (i.e. "zero").
|
|
17
|
-
* @param {string} [options.spaceSeparator
|
|
17
|
+
* @param {string} [options.spaceSeparator] Character that separates words.
|
|
18
18
|
* @param {Array} cards Array of number matching "cards" from highest-to-lowest.
|
|
19
19
|
*/
|
|
20
20
|
constructor(options, cards) {
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
/* eslint-disable import/max-dependencies */
|
|
2
|
-
import n2wordsAR from './i18n/AR.
|
|
3
|
-
import n2wordsAZ from './i18n/AZ.
|
|
4
|
-
import n2wordsCZ from './i18n/CZ.
|
|
5
|
-
import n2wordsDE from './i18n/DE.
|
|
6
|
-
import n2wordsDK from './i18n/DK.
|
|
7
|
-
import n2wordsEN from './i18n/EN.
|
|
8
|
-
import n2wordsES from './i18n/ES.
|
|
9
|
-
import n2wordsFA from './i18n/FA.
|
|
10
|
-
import n2wordsFR from './i18n/FR.
|
|
11
|
-
import n2wordsHE from './i18n/HE.
|
|
12
|
-
import n2wordsHR from './i18n/HR.
|
|
13
|
-
import n2wordsHU from './i18n/HU.
|
|
14
|
-
import n2wordsID from './i18n/ID.
|
|
15
|
-
import n2wordsIT from './i18n/IT.
|
|
16
|
-
import n2wordsKO from './i18n/KO.
|
|
17
|
-
import n2wordsLT from './i18n/LT.
|
|
18
|
-
import n2wordsLV from './i18n/LV.
|
|
19
|
-
import n2wordsNL from './i18n/NL.
|
|
20
|
-
import n2wordsNO from './i18n/NO.
|
|
21
|
-
import n2wordsPL from './i18n/PL.
|
|
22
|
-
import n2wordsPT from './i18n/PT.
|
|
23
|
-
import n2wordsRU from './i18n/RU.
|
|
24
|
-
import n2wordsSR from './i18n/SR.
|
|
25
|
-
import n2wordsTR from './i18n/TR.
|
|
26
|
-
import n2wordsUK from './i18n/UK.
|
|
27
|
-
import n2wordsVI from './i18n/VI.
|
|
28
|
-
import n2wordsZH from './i18n/ZH.
|
|
2
|
+
import n2wordsAR from './i18n/AR.js';
|
|
3
|
+
import n2wordsAZ from './i18n/AZ.js';
|
|
4
|
+
import n2wordsCZ from './i18n/CZ.js';
|
|
5
|
+
import n2wordsDE from './i18n/DE.js';
|
|
6
|
+
import n2wordsDK from './i18n/DK.js';
|
|
7
|
+
import n2wordsEN from './i18n/EN.js';
|
|
8
|
+
import n2wordsES from './i18n/ES.js';
|
|
9
|
+
import n2wordsFA from './i18n/FA.js';
|
|
10
|
+
import n2wordsFR from './i18n/FR.js';
|
|
11
|
+
import n2wordsHE from './i18n/HE.js';
|
|
12
|
+
import n2wordsHR from './i18n/HR.js';
|
|
13
|
+
import n2wordsHU from './i18n/HU.js';
|
|
14
|
+
import n2wordsID from './i18n/ID.js';
|
|
15
|
+
import n2wordsIT from './i18n/IT.js';
|
|
16
|
+
import n2wordsKO from './i18n/KO.js';
|
|
17
|
+
import n2wordsLT from './i18n/LT.js';
|
|
18
|
+
import n2wordsLV from './i18n/LV.js';
|
|
19
|
+
import n2wordsNL from './i18n/NL.js';
|
|
20
|
+
import n2wordsNO from './i18n/NO.js';
|
|
21
|
+
import n2wordsPL from './i18n/PL.js';
|
|
22
|
+
import n2wordsPT from './i18n/PT.js';
|
|
23
|
+
import n2wordsRU from './i18n/RU.js';
|
|
24
|
+
import n2wordsSR from './i18n/SR.js';
|
|
25
|
+
import n2wordsTR from './i18n/TR.js';
|
|
26
|
+
import n2wordsUK from './i18n/UK.js';
|
|
27
|
+
import n2wordsVI from './i18n/VI.js';
|
|
28
|
+
import n2wordsZH from './i18n/ZH.js';
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Converts a number to written form.
|
|
32
32
|
* @param {number|string} value The number to convert.
|
|
33
|
-
* @param {object} [options
|
|
33
|
+
* @param {object} [options] User options.
|
|
34
34
|
* @returns {string} Value in written format.
|
|
35
35
|
*/
|
|
36
36
|
export default function(value, options = {lang: 'en'}) {
|
package/package.json
CHANGED
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n2words",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "dist/n2words.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"lint": "eslint --config .eslintrc.json lib/ test/",
|
|
8
|
-
"test": "ava --verbose",
|
|
9
|
-
"coverage": "c8 ava",
|
|
10
|
-
"build": "webpack --config webpack.config.js --progress",
|
|
11
|
-
"bench": "node bench.mjs"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/forzagreen/n2words.git"
|
|
16
|
-
},
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": "16 || >=18"
|
|
19
|
-
},
|
|
3
|
+
"version": "1.16.0",
|
|
4
|
+
"description": "n2words converts a numerical number into a written one, supports 27 languages and has zero dependencies.",
|
|
20
5
|
"keywords": [
|
|
21
6
|
"n2words",
|
|
22
7
|
"convert",
|
|
@@ -54,28 +39,31 @@
|
|
|
54
39
|
"vietnamese",
|
|
55
40
|
"azerbaijani"
|
|
56
41
|
],
|
|
57
|
-
"
|
|
58
|
-
"license": "MIT",
|
|
42
|
+
"homepage": "https://github.com/forzagreen/n2words#readme",
|
|
59
43
|
"bugs": {
|
|
60
44
|
"url": "https://github.com/forzagreen/n2words/issues"
|
|
61
45
|
},
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
46
|
+
"repository": "github:forzagreen/n2words",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"author": "Wael TELLAT",
|
|
49
|
+
"contributors": [
|
|
50
|
+
"Tyler Vigario <TylerVigario90@gmail.com>"
|
|
51
|
+
],
|
|
52
|
+
"type": "module",
|
|
53
|
+
"exports": {
|
|
54
|
+
".": "./lib/n2words.js",
|
|
55
|
+
"./i18n/": "./lib/i18n/"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"lib/*",
|
|
59
|
+
"build/*"
|
|
60
|
+
],
|
|
61
|
+
"scripts": {
|
|
62
|
+
"bench": "node bench.js",
|
|
63
|
+
"build": "webpack --config webpack.config.js --progress",
|
|
64
|
+
"coverage": "c8 ava",
|
|
65
|
+
"lint": "eslint --config .eslintrc.json lib/ test/",
|
|
66
|
+
"test": "ava --verbose"
|
|
79
67
|
},
|
|
80
68
|
"ava": {
|
|
81
69
|
"files": [
|
|
@@ -92,5 +80,25 @@
|
|
|
92
80
|
"lcov",
|
|
93
81
|
"text"
|
|
94
82
|
]
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@babel/core": "^7.22.1",
|
|
86
|
+
"@babel/preset-env": "^7.22.4",
|
|
87
|
+
"ava": "^5.3.0",
|
|
88
|
+
"babel-loader": "^9.1.2",
|
|
89
|
+
"benchmark": "^2.1.4",
|
|
90
|
+
"c8": "^7.14.0",
|
|
91
|
+
"core-js": "^3.30.2",
|
|
92
|
+
"eslint": "^8.41.0",
|
|
93
|
+
"eslint-plugin-ava": "^14.0.0",
|
|
94
|
+
"eslint-plugin-import": "^2.27.5",
|
|
95
|
+
"eslint-plugin-jsdoc": "^46.0.0",
|
|
96
|
+
"eslint-plugin-node": "^11.1.0",
|
|
97
|
+
"microtime": "^3.1.1",
|
|
98
|
+
"webpack": "^5.84.1",
|
|
99
|
+
"webpack-cli": "^5.1.1"
|
|
100
|
+
},
|
|
101
|
+
"engines": {
|
|
102
|
+
"node": "16 || >=18"
|
|
95
103
|
}
|
|
96
104
|
}
|
package/.editorconfig
DELETED
package/.eslintrc.json
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"browser": true,
|
|
4
|
-
"commonjs": true,
|
|
5
|
-
"es6": true,
|
|
6
|
-
"es2017": true,
|
|
7
|
-
"es2020": true,
|
|
8
|
-
"es2021": true,
|
|
9
|
-
"es2022": true,
|
|
10
|
-
"node": true
|
|
11
|
-
},
|
|
12
|
-
"plugins": [
|
|
13
|
-
"ava",
|
|
14
|
-
"node",
|
|
15
|
-
"import",
|
|
16
|
-
"jsdoc"
|
|
17
|
-
],
|
|
18
|
-
"extends": [
|
|
19
|
-
"eslint:recommended",
|
|
20
|
-
"plugin:ava/recommended",
|
|
21
|
-
"plugin:node/recommended",
|
|
22
|
-
"plugin:import/errors",
|
|
23
|
-
"plugin:import/warnings",
|
|
24
|
-
"plugin:jsdoc/recommended"
|
|
25
|
-
],
|
|
26
|
-
"overrides": [{
|
|
27
|
-
"files": ["*.js", "*.mjs"]
|
|
28
|
-
}],
|
|
29
|
-
"parserOptions": {
|
|
30
|
-
"ecmaVersion": "latest",
|
|
31
|
-
"sourceType": "module"
|
|
32
|
-
},
|
|
33
|
-
"rules": {
|
|
34
|
-
// Ignore platform dependent linebreak
|
|
35
|
-
"linebreak-style": "off",
|
|
36
|
-
// Remove maximum length limit
|
|
37
|
-
"max-len": "off",
|
|
38
|
-
// Enforce camelCase for variable names
|
|
39
|
-
"camelcase": ["error", {
|
|
40
|
-
"properties": "never"
|
|
41
|
-
}],
|
|
42
|
-
// Enforce indent of two spaces
|
|
43
|
-
"indent": [
|
|
44
|
-
"error", 2, {
|
|
45
|
-
"SwitchCase": 1
|
|
46
|
-
}
|
|
47
|
-
],
|
|
48
|
-
// Remove trailing whitespace
|
|
49
|
-
"no-trailing-spaces": "error",
|
|
50
|
-
// Enforce use of single quotes
|
|
51
|
-
"quotes": ["error", "single"],
|
|
52
|
-
// Enforce use of semicolon to end lines
|
|
53
|
-
"semi": "error",
|
|
54
|
-
// Enforce consistent spacing before & after arrow function
|
|
55
|
-
"arrow-spacing": "error",
|
|
56
|
-
// Enforce omitting parentheses when unnecessary for arrow functions
|
|
57
|
-
"arrow-parens": ["error", "as-needed"],
|
|
58
|
-
// Disallow multiple imports of same module
|
|
59
|
-
"no-duplicate-imports": "error",
|
|
60
|
-
// Enforce let or const instead of var
|
|
61
|
-
"no-var": "error",
|
|
62
|
-
// Enforce consistent brace style usage (1TBS default)
|
|
63
|
-
"brace-style": "error",
|
|
64
|
-
//
|
|
65
|
-
// -- IMPORT RULES --
|
|
66
|
-
//
|
|
67
|
-
// Report any invalid exports, i.e. re-export of the same name
|
|
68
|
-
"import/export": "error",
|
|
69
|
-
// Report modules without exports, or exports without matching import in another module
|
|
70
|
-
"import/no-unused-modules": "error",
|
|
71
|
-
// Report potentially ambiguous parse goal (script vs. module)
|
|
72
|
-
"import/unambiguous": "error",
|
|
73
|
-
// Report CommonJS require calls and module.exports or exports.*
|
|
74
|
-
"import/no-commonjs": "error",
|
|
75
|
-
// Report AMD require and define calls
|
|
76
|
-
"import/no-amd": "error",
|
|
77
|
-
// No Node.js builtin modules
|
|
78
|
-
"import/no-nodejs-modules": "error",
|
|
79
|
-
// Report imported names marked with @deprecated documentation tag
|
|
80
|
-
"import/no-deprecated": "error",
|
|
81
|
-
// Ensure all imports appear before other statements
|
|
82
|
-
"import/first": "error",
|
|
83
|
-
// Ensure consistent use of file extension within the import path
|
|
84
|
-
"import/extensions": ["error", "always"],
|
|
85
|
-
// Enforce a newline after import statements
|
|
86
|
-
"import/newline-after-import": "error",
|
|
87
|
-
// Ensure imports point to a file/module that can be resolved
|
|
88
|
-
"import/no-unresolved": ["error", {
|
|
89
|
-
"commonjs": true
|
|
90
|
-
}],
|
|
91
|
-
// Limit the maximum number of dependencies a module can have
|
|
92
|
-
"import/max-dependencies": "error",
|
|
93
|
-
// Prefer a default export if module exports a single name
|
|
94
|
-
"import/prefer-default-export": "error",
|
|
95
|
-
// Forbid unassigned imports
|
|
96
|
-
"import/no-unassigned-import": ["error", {
|
|
97
|
-
"allow": ["**/app.mjs"]
|
|
98
|
-
}]
|
|
99
|
-
//
|
|
100
|
-
// -- JSDOC RULES --
|
|
101
|
-
//
|
|
102
|
-
// Checks for presence of jsdoc comments, on class declarations as well as functions
|
|
103
|
-
//"jsdoc/require-jsdoc": "off"
|
|
104
|
-
}
|
|
105
|
-
}
|