tanisa 1.1.3 → 1.1.4

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.
@@ -0,0 +1,8 @@
1
+ import { TanisaOptions } from './interface';
2
+ export declare class Tanisa {
3
+ toWords(number: number | string, options?: TanisaOptions): string;
4
+ private convertInteger;
5
+ private formatLargeNumber;
6
+ private convertBelowThousand;
7
+ private convertBelowHundred;
8
+ }
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tanisa = void 0;
4
+ const dictionary_1 = require("./dictionary");
5
+ class Tanisa {
6
+ toWords(number, options) {
7
+ var _a, _b;
8
+ const ignoreDecimal = (_a = options === null || options === void 0 ? void 0 : options.ignoreDecimal) !== null && _a !== void 0 ? _a : false;
9
+ const decimalPlaces = (_b = options === null || options === void 0 ? void 0 : options.decimalPlaces) !== null && _b !== void 0 ? _b : -1;
10
+ const numStr = String(number).trim();
11
+ const [integerPartStr, decimalPartStr] = numStr.split('.');
12
+ const integerPartNum = parseInt(integerPartStr || '0', 10);
13
+ if (isNaN(integerPartNum) ||
14
+ (decimalPartStr &&
15
+ decimalPartStr.length > 0 &&
16
+ isNaN(parseInt(decimalPartStr, 10)))) {
17
+ throw new TypeError(`Invalid number input: "${number}"`);
18
+ }
19
+ if (numStr.trim().startsWith('-') && integerPartNum !== 0) {
20
+ throw new RangeError('Negative numbers are not supported.');
21
+ }
22
+ if (integerPartNum >= dictionary_1.MalagasyNumerals.MAX_SUPPORTED_INTEGER ||
23
+ integerPartStr == dictionary_1.MalagasyNumerals.MAX_SUPPORTED_INTEGER.toString()) {
24
+ throw new RangeError(`Number ${integerPartNum} exceeds the maximum supported value (${dictionary_1.MalagasyNumerals.MAX_SUPPORTED_INTEGER}).`);
25
+ }
26
+ const integerWords = this.convertInteger(integerPartNum);
27
+ let decimalWords = '';
28
+ const processDecimals = decimalPartStr &&
29
+ decimalPartStr.length > 0 &&
30
+ !ignoreDecimal &&
31
+ decimalPlaces !== 0;
32
+ if (processDecimals) {
33
+ let effectiveDecimalPartStr = decimalPartStr;
34
+ if (decimalPlaces > 0 && decimalPartStr.length > decimalPlaces) {
35
+ effectiveDecimalPartStr = decimalPartStr.substring(0, decimalPlaces);
36
+ }
37
+ if (parseInt(effectiveDecimalPartStr || '0', 10) > 0) {
38
+ let tempDecimalWords = '';
39
+ for (let i = 0; i < effectiveDecimalPartStr.length; i++) {
40
+ const digit = effectiveDecimalPartStr[i];
41
+ if (digit === '0') {
42
+ tempDecimalWords += dictionary_1.MalagasyNumerals.GLUE_DECIMAL_ZERO;
43
+ }
44
+ else {
45
+ const remainingDecimal = effectiveDecimalPartStr.substring(i);
46
+ tempDecimalWords += this.convertInteger(parseInt(remainingDecimal, 10));
47
+ break;
48
+ }
49
+ }
50
+ if (tempDecimalWords) {
51
+ decimalWords = dictionary_1.MalagasyNumerals.GLUE_FAINGO + tempDecimalWords;
52
+ }
53
+ }
54
+ }
55
+ return integerWords + decimalWords;
56
+ }
57
+ convertInteger(num) {
58
+ if (num === 0) {
59
+ return dictionary_1.MalagasyNumerals.ZERO;
60
+ }
61
+ for (const unit of dictionary_1.MalagasyNumerals.LARGE_NUMBER_UNITS) {
62
+ if (num >= unit.threshold) {
63
+ return this.formatLargeNumber(num, unit);
64
+ }
65
+ }
66
+ return this.convertBelowThousand(num);
67
+ }
68
+ formatLargeNumber(num, unit) {
69
+ const multiple = Math.floor(num / unit.threshold);
70
+ const remainder = num % unit.threshold;
71
+ let prefix = '';
72
+ if (multiple > 1) {
73
+ prefix = this.convertInteger(multiple) + ' ';
74
+ }
75
+ else if (multiple === 1 && unit.threshold > 1000) {
76
+ prefix = dictionary_1.MalagasyNumerals.DIGITS[1] + ' ';
77
+ }
78
+ const basePart = prefix + unit.name;
79
+ if (remainder > 0) {
80
+ const remainderText = this.convertInteger(remainder);
81
+ return remainderText + dictionary_1.MalagasyNumerals.GLUE_SY + basePart;
82
+ }
83
+ else {
84
+ return basePart;
85
+ }
86
+ }
87
+ convertBelowThousand(num) {
88
+ if (num >= 100) {
89
+ const hundredMultiple = Math.floor(num / 100);
90
+ const remainder = num % 100;
91
+ const hundredWord = dictionary_1.MalagasyNumerals.HUNDREDS[hundredMultiple];
92
+ if (remainder === 0) {
93
+ return hundredWord;
94
+ }
95
+ else {
96
+ const remainderWords = this.convertBelowHundred(remainder);
97
+ let glue = dictionary_1.MalagasyNumerals.GLUE_AMBY;
98
+ if (hundredMultiple >= 2 && remainder >= 10) {
99
+ glue = dictionary_1.MalagasyNumerals.GLUE_SY;
100
+ }
101
+ const finalRemainderWords = remainder === 1 ? dictionary_1.MalagasyNumerals.CUSTOM_ONE : remainderWords;
102
+ return finalRemainderWords + glue + hundredWord;
103
+ }
104
+ }
105
+ return this.convertBelowHundred(num);
106
+ }
107
+ convertBelowHundred(num) {
108
+ if (num >= 10) {
109
+ const tenMultiple = Math.floor(num / 10);
110
+ const remainder = num % 10;
111
+ const tenWord = dictionary_1.MalagasyNumerals.TENS[tenMultiple];
112
+ if (remainder === 0) {
113
+ return tenWord;
114
+ }
115
+ else {
116
+ const digitWord = remainder === 1
117
+ ? dictionary_1.MalagasyNumerals.CUSTOM_ONE
118
+ : dictionary_1.MalagasyNumerals.DIGITS[remainder];
119
+ return digitWord + dictionary_1.MalagasyNumerals.GLUE_AMBY + tenWord;
120
+ }
121
+ }
122
+ return dictionary_1.MalagasyNumerals.DIGITS[num];
123
+ }
124
+ }
125
+ exports.Tanisa = Tanisa;
@@ -0,0 +1,61 @@
1
+ export declare const MalagasyNumerals: {
2
+ readonly GLUE_SY: " sy ";
3
+ readonly GLUE_AMBY: " amby ";
4
+ readonly GLUE_FAINGO: " faingo ";
5
+ readonly GLUE_DECIMAL_ZERO: "aotra ";
6
+ readonly CUSTOM_ONE: "iraika";
7
+ readonly ZERO: "aotra";
8
+ readonly DIGITS: readonly ["", "iray", "roa", "telo", "efatra", "dimy", "enina", "fito", "valo", "sivy"];
9
+ readonly TENS: readonly ["", "folo", "roapolo", "telopolo", "efapolo", "dimampolo", "enimpolo", "fitopolo", "valopolo", "sivifolo"];
10
+ readonly HUNDREDS: readonly ["", "zato", "roanjato", "telonjato", "efajato", "dimanjato", "eninjato", "fitonjato", "valonjato", "sivinjato"];
11
+ readonly LARGE_NUMBER_UNITS: readonly [{
12
+ readonly threshold: 1000000000000000000;
13
+ readonly name: "tsipesimpesinafaharoa";
14
+ }, {
15
+ readonly threshold: 100000000000000000;
16
+ readonly name: "alinkisafaharoa";
17
+ }, {
18
+ readonly threshold: 10000000000000000;
19
+ readonly name: "lavitrisafaharoa";
20
+ }, {
21
+ readonly threshold: 1000000000000000;
22
+ readonly name: "tsitamboisafaharoa";
23
+ }, {
24
+ readonly threshold: 100000000000000;
25
+ readonly name: "safatsiroafaharoa";
26
+ }, {
27
+ readonly threshold: 10000000000000;
28
+ readonly name: "tsitanoanoa";
29
+ }, {
30
+ readonly threshold: 1000000000000;
31
+ readonly name: "tsitokotsiforohana";
32
+ }, {
33
+ readonly threshold: 100000000000;
34
+ readonly name: "tsipesimpesina";
35
+ }, {
36
+ readonly threshold: 10000000000;
37
+ readonly name: "alinkisa";
38
+ }, {
39
+ readonly threshold: 1000000000;
40
+ readonly name: "lavitrisa";
41
+ }, {
42
+ readonly threshold: 100000000;
43
+ readonly name: "tsitamboisa";
44
+ }, {
45
+ readonly threshold: 10000000;
46
+ readonly name: "safatsiroa";
47
+ }, {
48
+ readonly threshold: 1000000;
49
+ readonly name: "tapitrisa";
50
+ }, {
51
+ readonly threshold: 100000;
52
+ readonly name: "hetsy";
53
+ }, {
54
+ readonly threshold: 10000;
55
+ readonly name: "alina";
56
+ }, {
57
+ readonly threshold: 1000;
58
+ readonly name: "arivo";
59
+ }];
60
+ readonly MAX_SUPPORTED_INTEGER: number;
61
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MalagasyNumerals = void 0;
4
+ exports.MalagasyNumerals = {
5
+ GLUE_SY: ' sy ',
6
+ GLUE_AMBY: ' amby ',
7
+ GLUE_FAINGO: ' faingo ',
8
+ GLUE_DECIMAL_ZERO: 'aotra ',
9
+ CUSTOM_ONE: 'iraika',
10
+ ZERO: 'aotra',
11
+ DIGITS: [
12
+ '',
13
+ 'iray',
14
+ 'roa',
15
+ 'telo',
16
+ 'efatra',
17
+ 'dimy',
18
+ 'enina',
19
+ 'fito',
20
+ 'valo',
21
+ 'sivy',
22
+ ],
23
+ TENS: [
24
+ '',
25
+ 'folo',
26
+ 'roapolo',
27
+ 'telopolo',
28
+ 'efapolo',
29
+ 'dimampolo',
30
+ 'enimpolo',
31
+ 'fitopolo',
32
+ 'valopolo',
33
+ 'sivifolo',
34
+ ],
35
+ HUNDREDS: [
36
+ '',
37
+ 'zato',
38
+ 'roanjato',
39
+ 'telonjato',
40
+ 'efajato',
41
+ 'dimanjato',
42
+ 'eninjato',
43
+ 'fitonjato',
44
+ 'valonjato',
45
+ 'sivinjato',
46
+ ],
47
+ LARGE_NUMBER_UNITS: [
48
+ { threshold: 1000000000000000000, name: 'tsipesimpesinafaharoa' },
49
+ { threshold: 100000000000000000, name: 'alinkisafaharoa' },
50
+ { threshold: 10000000000000000, name: 'lavitrisafaharoa' },
51
+ { threshold: 1000000000000000, name: 'tsitamboisafaharoa' },
52
+ { threshold: 100000000000000, name: 'safatsiroafaharoa' },
53
+ { threshold: 10000000000000, name: 'tsitanoanoa' },
54
+ { threshold: 1000000000000, name: 'tsitokotsiforohana' },
55
+ { threshold: 100000000000, name: 'tsipesimpesina' },
56
+ { threshold: 10000000000, name: 'alinkisa' },
57
+ { threshold: 1000000000, name: 'lavitrisa' },
58
+ { threshold: 100000000, name: 'tsitamboisa' },
59
+ { threshold: 10000000, name: 'safatsiroa' },
60
+ { threshold: 1000000, name: 'tapitrisa' },
61
+ { threshold: 100000, name: 'hetsy' },
62
+ { threshold: 10000, name: 'alina' },
63
+ { threshold: 1000, name: 'arivo' },
64
+ ],
65
+ MAX_SUPPORTED_INTEGER: 1000000000000000000 * 1000,
66
+ };
@@ -0,0 +1,3 @@
1
+ export { Tanisa } from './converter';
2
+ export { MalagasyNumerals } from './dictionary';
3
+ export { LargeNumberUnit, TanisaOptions } from './interface';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MalagasyNumerals = exports.Tanisa = void 0;
4
+ var converter_1 = require("./converter");
5
+ Object.defineProperty(exports, "Tanisa", { enumerable: true, get: function () { return converter_1.Tanisa; } });
6
+ var dictionary_1 = require("./dictionary");
7
+ Object.defineProperty(exports, "MalagasyNumerals", { enumerable: true, get: function () { return dictionary_1.MalagasyNumerals; } });
@@ -0,0 +1,6 @@
1
+ import { MalagasyNumerals } from './dictionary';
2
+ export interface TanisaOptions {
3
+ ignoreDecimal?: boolean;
4
+ decimalPlaces?: number;
5
+ }
6
+ export type LargeNumberUnit = (typeof MalagasyNumerals.LARGE_NUMBER_UNITS)[number];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "tanisa",
3
- "version": "1.1.3",
4
- "main": "src/index.ts",
3
+ "version": "1.1.4",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "require": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
5
15
  "description": "An utility to convert Malagasy 🇲🇬 numbers, including decimals, into their word representations.",
6
16
  "license": "MIT",
7
17
  "author": {
@@ -16,8 +26,7 @@
16
26
  "lint": "eslint",
17
27
  "lint:fix": "eslint . --fix",
18
28
  "build": "tsc",
19
- "_postinstall": "husky",
20
- "prepack": "pinst --disable",
29
+ "prepack": "pinst --disable && tsc",
21
30
  "postpack": "pinst --enable",
22
31
  "prepare": "husky"
23
32
  },
package/.husky/pre-commit DELETED
@@ -1 +0,0 @@
1
- yarn lint-staged
package/.husky/pre-push DELETED
@@ -1 +0,0 @@
1
- yarn test
@@ -1,3 +0,0 @@
1
- {
2
- "*.{js,ts,md,json}": ["eslint --fix", "prettier --write"]
3
- }
package/.prettierrc DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "trailingComma": "es5",
3
- "singleQuote": true,
4
- "semi": false,
5
- "tabWidth": 2
6
- }
package/CONTRIBUTING.md DELETED
@@ -1,66 +0,0 @@
1
- # Welcome to Tanisa 🇲🇬
2
-
3
- Hey there,
4
- Thanks for stopping by!
5
- Whether you're here to squash bugs, sprinkle in new features, or just correct that one typo that's been bugging you — you're awesome and we appreciate you.
6
-
7
- This guide is your magic scroll to contributing like a pro. Please read it before opening issues or sending pull requests. It helps us help _you_ help _us_.
8
-
9
- ---
10
-
11
- ## 🐛 Bug Reports & 🧠 Feature Ideas
12
-
13
- Found a bug? Got a genius idea at 2AM? We want to hear it!
14
- Pop it into the [GitHub Issues](https://github.com/nifaliana/tanisa/issues) — but first:
15
-
16
- Check if someone else already reported it.
17
- Include:
18
-
19
- - How to make the bug appear (step-by-step wizardry)
20
- - Your Tanisa version
21
- - Any tweaks you made (we don’t judge)
22
-
23
- ---
24
-
25
- ## 🤝 Pull Requests
26
-
27
- Pull requests are like party invites — we’re thrilled to receive them. Before you crash the repo with your awesome code:
28
-
29
- 1. Work from the latest **main** branch.
30
- 2. Check if someone already fixed that issue.
31
- 3. For big stuff, open an issue first so we can cheer you on.
32
-
33
- **To contribute**:
34
-
35
- 1. Fork the repo.
36
- 2. Make your changes — focus, grasshopper.
37
- 3. Pass all local tests, pre-commits and pre-push (Tanisa is picky).
38
- 4. Write meaningful and [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) messages (not just “fix stuff” 😅).
39
- 5. Open that pull request.
40
- 6. Watch the CI like a hawk — fix if it fails.
41
- 7. Stick around for feedback, high fives, or emoji reactions.
42
-
43
- ---
44
-
45
- ## 🔍 Not Sure Where to Start?
46
-
47
- We label issues with things like `help wanted`, `bug`, `enhancement`, and `question`.
48
- Check out `help wanted` for a warm welcome into the codebase!
49
-
50
- ---
51
-
52
- ## Be Kind. Code Nice.
53
-
54
- We follow the [Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct.html).
55
- Basically: Be cool, be respectful, and remember — behind every GitHub handle is a real human with feelings.
56
-
57
- ---
58
-
59
- ## ⚖️ License Stuff
60
-
61
- Check the [LICENSE](LICENSE) file for the legal spells.
62
- We may ask you to confirm you're cool with our open-source terms when you contribute.
63
-
64
- ---
65
-
66
- 🎉 That’s it! Now go forth, brave contributor, and may your PRs be swift and your bugs be tiny.
package/eslint.config.mjs DELETED
@@ -1,13 +0,0 @@
1
- // @ts-check
2
-
3
- import eslint from '@eslint/js'
4
- import tseslint from 'typescript-eslint'
5
-
6
- export default tseslint.config(
7
- eslint.configs.recommended,
8
- tseslint.configs.recommended,
9
- tseslint.configs.stylistic,
10
- {
11
- ignores: ['./dist', './node_modules'],
12
- }
13
- )
package/src/converter.ts DELETED
@@ -1,155 +0,0 @@
1
- import { MalagasyNumerals } from './dictionary'
2
- import { TanisaOptions, LargeNumberUnit } from './interface'
3
-
4
- export class Tanisa {
5
- public toWords(number: number | string, options?: TanisaOptions): string {
6
- const ignoreDecimal = options?.ignoreDecimal ?? false
7
- const decimalPlaces = options?.decimalPlaces ?? -1
8
-
9
- const numStr = String(number).trim()
10
- const [integerPartStr, decimalPartStr] = numStr.split('.')
11
- const integerPartNum = parseInt(integerPartStr || '0', 10)
12
-
13
- if (
14
- isNaN(integerPartNum) ||
15
- (decimalPartStr &&
16
- decimalPartStr.length > 0 &&
17
- isNaN(parseInt(decimalPartStr, 10)))
18
- ) {
19
- throw new TypeError(`Invalid number input: "${number}"`)
20
- }
21
-
22
- if (numStr.trim().startsWith('-') && integerPartNum !== 0) {
23
- throw new RangeError('Negative numbers are not supported.')
24
- }
25
-
26
- if (
27
- integerPartNum >= MalagasyNumerals.MAX_SUPPORTED_INTEGER ||
28
- integerPartStr == MalagasyNumerals.MAX_SUPPORTED_INTEGER.toString()
29
- ) {
30
- throw new RangeError(
31
- `Number ${integerPartNum} exceeds the maximum supported value (${MalagasyNumerals.MAX_SUPPORTED_INTEGER}).`
32
- )
33
- }
34
-
35
- const integerWords = this.convertInteger(integerPartNum)
36
-
37
- let decimalWords = ''
38
- const processDecimals =
39
- decimalPartStr &&
40
- decimalPartStr.length > 0 &&
41
- !ignoreDecimal &&
42
- decimalPlaces !== 0
43
-
44
- if (processDecimals) {
45
- let effectiveDecimalPartStr = decimalPartStr
46
-
47
- if (decimalPlaces > 0 && decimalPartStr.length > decimalPlaces) {
48
- effectiveDecimalPartStr = decimalPartStr.substring(0, decimalPlaces)
49
- }
50
-
51
- if (parseInt(effectiveDecimalPartStr || '0', 10) > 0) {
52
- let tempDecimalWords = ''
53
- for (let i = 0; i < effectiveDecimalPartStr.length; i++) {
54
- const digit = effectiveDecimalPartStr[i]
55
- if (digit === '0') {
56
- tempDecimalWords += MalagasyNumerals.GLUE_DECIMAL_ZERO
57
- } else {
58
- const remainingDecimal = effectiveDecimalPartStr.substring(i)
59
- tempDecimalWords += this.convertInteger(
60
- parseInt(remainingDecimal, 10)
61
- )
62
- break
63
- }
64
- }
65
- if (tempDecimalWords) {
66
- decimalWords = MalagasyNumerals.GLUE_FAINGO + tempDecimalWords
67
- }
68
- }
69
- }
70
-
71
- return integerWords + decimalWords
72
- }
73
-
74
- private convertInteger(num: number): string {
75
- if (num === 0) {
76
- return MalagasyNumerals.ZERO
77
- }
78
-
79
- for (const unit of MalagasyNumerals.LARGE_NUMBER_UNITS) {
80
- if (num >= unit.threshold) {
81
- return this.formatLargeNumber(num, unit)
82
- }
83
- }
84
-
85
- return this.convertBelowThousand(num)
86
- }
87
-
88
- private formatLargeNumber(num: number, unit: LargeNumberUnit): string {
89
- const multiple = Math.floor(num / unit.threshold)
90
- const remainder = num % unit.threshold
91
-
92
- let prefix = ''
93
- // Use prefix only if multiple is greater than 1 OR
94
- // if multiple is 1 AND the unit is larger than 'arivo' (1000)
95
- if (multiple > 1) {
96
- prefix = this.convertInteger(multiple) + ' '
97
- } else if (multiple === 1 && unit.threshold > 1000) {
98
- prefix = MalagasyNumerals.DIGITS[1] + ' '
99
- }
100
- // If multiple is 1 and unit is 'arivo', no prefix is needed ("arivo", not "iray arivo")
101
- const basePart = prefix + unit.name
102
-
103
- if (remainder > 0) {
104
- const remainderText = this.convertInteger(remainder)
105
- return remainderText + MalagasyNumerals.GLUE_SY + basePart
106
- } else {
107
- return basePart
108
- }
109
- }
110
-
111
- private convertBelowThousand(num: number): string {
112
- // Assumes 0 < num < 1000
113
- if (num >= 100) {
114
- const hundredMultiple = Math.floor(num / 100)
115
- const remainder = num % 100
116
- const hundredWord = MalagasyNumerals.HUNDREDS[hundredMultiple]
117
-
118
- if (remainder === 0) {
119
- return hundredWord
120
- } else {
121
- const remainderWords = this.convertBelowHundred(remainder)
122
- let glue = MalagasyNumerals.GLUE_AMBY as string
123
- // Special rule: Use "sy" if hundred base >= 200 AND remainder >= 10
124
- if (hundredMultiple >= 2 && remainder >= 10) {
125
- glue = MalagasyNumerals.GLUE_SY
126
- }
127
- // Use "iraika" for remainder 1 when connecting
128
- const finalRemainderWords =
129
- remainder === 1 ? MalagasyNumerals.CUSTOM_ONE : remainderWords
130
- return finalRemainderWords + glue + hundredWord
131
- }
132
- }
133
- return this.convertBelowHundred(num)
134
- }
135
-
136
- private convertBelowHundred(num: number): string {
137
- if (num >= 10) {
138
- const tenMultiple = Math.floor(num / 10)
139
- const remainder = num % 10
140
- const tenWord = MalagasyNumerals.TENS[tenMultiple]
141
-
142
- if (remainder === 0) {
143
- return tenWord
144
- } else {
145
- // Always use "amby" for tens+digits
146
- const digitWord =
147
- remainder === 1
148
- ? MalagasyNumerals.CUSTOM_ONE
149
- : MalagasyNumerals.DIGITS[remainder]
150
- return digitWord + MalagasyNumerals.GLUE_AMBY + tenWord
151
- }
152
- }
153
- return MalagasyNumerals.DIGITS[num]
154
- }
155
- }
package/src/dictionary.ts DELETED
@@ -1,70 +0,0 @@
1
- export const MalagasyNumerals = {
2
- GLUE_SY: ' sy ',
3
- GLUE_AMBY: ' amby ',
4
- GLUE_FAINGO: ' faingo ',
5
- GLUE_DECIMAL_ZERO: 'aotra ',
6
-
7
- CUSTOM_ONE: 'iraika', // '1' used before 'amby'
8
-
9
- ZERO: 'aotra',
10
-
11
- // Digits 1-9
12
- DIGITS: [
13
- '',
14
- 'iray',
15
- 'roa',
16
- 'telo',
17
- 'efatra',
18
- 'dimy',
19
- 'enina',
20
- 'fito',
21
- 'valo',
22
- 'sivy',
23
- ],
24
- // Tens 10-90
25
- TENS: [
26
- '',
27
- 'folo',
28
- 'roapolo',
29
- 'telopolo',
30
- 'efapolo',
31
- 'dimampolo',
32
- 'enimpolo',
33
- 'fitopolo',
34
- 'valopolo',
35
- 'sivifolo',
36
- ],
37
- // Hundreds 100-900
38
- HUNDREDS: [
39
- '',
40
- 'zato',
41
- 'roanjato',
42
- 'telonjato',
43
- 'efajato',
44
- 'dimanjato',
45
- 'eninjato',
46
- 'fitonjato',
47
- 'valonjato',
48
- 'sivinjato',
49
- ],
50
- LARGE_NUMBER_UNITS: [
51
- { threshold: 1_000_000_000_000_000_000, name: 'tsipesimpesinafaharoa' },
52
- { threshold: 100_000_000_000_000_000, name: 'alinkisafaharoa' },
53
- { threshold: 10_000_000_000_000_000, name: 'lavitrisafaharoa' },
54
- { threshold: 1_000_000_000_000_000, name: 'tsitamboisafaharoa' },
55
- { threshold: 100_000_000_000_000, name: 'safatsiroafaharoa' },
56
- { threshold: 10_000_000_000_000, name: 'tsitanoanoa' },
57
- { threshold: 1_000_000_000_000, name: 'tsitokotsiforohana' },
58
- { threshold: 100_000_000_000, name: 'tsipesimpesina' },
59
- { threshold: 10_000_000_000, name: 'alinkisa' },
60
- { threshold: 1_000_000_000, name: 'lavitrisa' },
61
- { threshold: 100_000_000, name: 'tsitamboisa' },
62
- { threshold: 10_000_000, name: 'safatsiroa' },
63
- { threshold: 1_000_000, name: 'tapitrisa' },
64
- { threshold: 100_000, name: 'hetsy' },
65
- { threshold: 10_000, name: 'alina' },
66
- { threshold: 1_000, name: 'arivo' },
67
- ] as const,
68
-
69
- MAX_SUPPORTED_INTEGER: 1_000_000_000_000_000_000 * 1000,
70
- } as const
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- // src/index.ts
2
- export { Tanisa } from './converter'
3
- export { MalagasyNumerals } from './dictionary'
4
- export { LargeNumberUnit, TanisaOptions } from './interface'
package/src/interface.ts DELETED
@@ -1,20 +0,0 @@
1
- import { MalagasyNumerals } from './dictionary'
2
-
3
- export interface TanisaOptions {
4
- /**
5
- * If true, ignores the decimal part of the number.
6
- * @default false
7
- */
8
- ignoreDecimal?: boolean
9
-
10
- /**
11
- * Specifies the maximum number of decimal places to convert.
12
- * Extra decimal places will be truncated (not rounded).
13
- * Set to 0 to ignore decimals.
14
- * @default undefined (converts all decimal places)
15
- */
16
- decimalPlaces?: number
17
- }
18
-
19
- export type LargeNumberUnit =
20
- (typeof MalagasyNumerals.LARGE_NUMBER_UNITS)[number]
@@ -1,201 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest'
2
- import { Tanisa, MalagasyNumerals } from '../src'
3
- import { TanisaOptions } from '../src/interface'
4
-
5
- describe('MalagasyNumberToWords', () => {
6
- let converter: Tanisa
7
-
8
- beforeEach(() => {
9
- converter = new Tanisa()
10
- })
11
-
12
- const testCases: [number | string, string][] = [
13
- [0, 'aotra'],
14
- [1, 'iray'],
15
- [5, 'dimy'],
16
- [9, 'sivy'],
17
- // // Tens
18
- [10, 'folo'],
19
- [11, 'iraika amby folo'],
20
- [15, 'dimy amby folo'],
21
- [20, 'roapolo'],
22
- [21, 'iraika amby roapolo'],
23
- [35, 'dimy amby telopolo'],
24
- [99, 'sivy amby sivifolo'],
25
- // // Hundreds
26
- [100, 'zato'],
27
- [101, 'iraika amby zato'],
28
- [110, 'folo amby zato'],
29
- [111, 'iraika amby folo amby zato'],
30
- [121, 'iraika amby roapolo amby zato'],
31
- [200, 'roanjato'],
32
- [201, 'iraika amby roanjato'],
33
- [210, 'folo sy roanjato'],
34
- [225, 'dimy amby roapolo sy roanjato'],
35
- [600, 'eninjato'],
36
- [999, 'sivy amby sivifolo sy sivinjato'],
37
- // // Thousands
38
- [1000, 'arivo'],
39
- [1001, 'iray sy arivo'],
40
- [1010, 'folo sy arivo'],
41
- [1011, 'iraika amby folo sy arivo'],
42
- [1378, 'valo amby fitopolo sy telonjato sy arivo'],
43
- [2000, 'roa arivo'],
44
- [2023, 'telo amby roapolo sy roa arivo'],
45
- // Ten Thousands (Alina)
46
- [10000, 'iray alina'],
47
- [15000, 'dimy arivo sy iray alina'],
48
- [20000, 'roa alina'],
49
- [98_765, 'dimy amby enimpolo sy fitonjato sy valo arivo sy sivy alina'],
50
- // Hundred Thousands (Hetsy)
51
- [100000, 'iray hetsy'],
52
- [
53
- 123456,
54
- 'enina amby dimampolo sy efajato sy telo arivo sy roa alina sy iray hetsy',
55
- ],
56
- [500000, 'dimy hetsy'],
57
- [
58
- 654321,
59
- 'iraika amby roapolo sy telonjato sy efatra arivo sy dimy alina sy enina hetsy',
60
- ],
61
- // Millions (Tapitrisa)
62
- [1000000, 'iray tapitrisa'],
63
- [1000001, 'iray sy iray tapitrisa'],
64
- [2500000, 'dimy hetsy sy roa tapitrisa'],
65
- [
66
- 9876543,
67
- 'telo amby efapolo sy dimanjato sy enina arivo sy fito alina sy valo hetsy sy sivy tapitrisa',
68
- ],
69
- // Larger Units
70
- [10000000, 'iray safatsiroa'],
71
- [100000000, 'iray tsitamboisa'],
72
- [1000000000, 'iray lavitrisa'],
73
- [
74
- 12345678901,
75
- 'iraika amby sivinjato sy valo arivo sy fito alina sy enina hetsy sy dimy tapitrisa sy efatra safatsiroa sy telo tsitamboisa sy roa lavitrisa sy iray alinkisa',
76
- ],
77
- [1_100_000_000_000, 'iray tsipesimpesina sy iray tsitokotsiforohana'],
78
- // Decimals
79
- [0.5, 'aotra faingo dimy'],
80
- [0.1, 'aotra faingo iray'],
81
- ['2.00100', 'roa faingo aotra aotra zato'],
82
- [
83
- 1378.23,
84
- 'valo amby fitopolo sy telonjato sy arivo faingo telo amby roapolo',
85
- ],
86
- [100.01, 'zato faingo aotra iray'],
87
- [0.005, 'aotra faingo aotra aotra dimy'],
88
- ]
89
-
90
- it.each(testCases)('should convert %s to "%s"', (input, expected) => {
91
- expect(converter.toWords(input)).toBe(expected)
92
- })
93
-
94
- describe('Error Handling', () => {
95
- it('should throw TypeError for invalid input', () => {
96
- expect(() => converter.toWords('not a number')).toThrow(TypeError)
97
- expect(() => converter.toWords('123.abc')).toThrow(TypeError)
98
- expect(() => converter.toWords(NaN)).toThrow(TypeError)
99
- })
100
-
101
- it('should throw RangeError for negative numbers', () => {
102
- expect(() => converter.toWords(-1)).toThrow(RangeError)
103
- expect(() => converter.toWords(-100.5)).toThrow(RangeError)
104
- expect(() => converter.toWords('-0')).not.toThrow(RangeError)
105
- expect(converter.toWords('-0')).toBe('aotra')
106
- })
107
-
108
- it('should throw RangeError for numbers exceeding the limit', () => {
109
- const limit = MalagasyNumerals.MAX_SUPPORTED_INTEGER
110
- const largeNumber = BigInt(limit) + BigInt(1)
111
-
112
- expect(() => converter.toWords(limit)).toThrow(RangeError)
113
- expect(() => converter.toWords(largeNumber.toString())).toThrow(
114
- RangeError
115
- )
116
- })
117
-
118
- it('should handle string input correctly', () => {
119
- expect(converter.toWords('123')).toBe('telo amby roapolo amby zato')
120
- expect(converter.toWords('1000.5')).toBe('arivo faingo dimy')
121
- })
122
-
123
- it('should handle number input with maximum safe integer', () => {
124
- const safeInt = Number.MAX_SAFE_INTEGER // 9_007_199_254_740_991
125
- expect(() => converter.toWords(safeInt)).not.toThrow()
126
- })
127
- })
128
-
129
- describe('ignoreDecimal option', () => {
130
- it('should ignore decimal part when ignoreDecimal is true', () => {
131
- const options: TanisaOptions = { ignoreDecimal: true }
132
- expect(converter.toWords(123.456, options)).toBe(
133
- 'telo amby roapolo amby zato'
134
- )
135
- expect(converter.toWords(0.99, options)).toBe('aotra')
136
- expect(converter.toWords(1000.001, options)).toBe('arivo')
137
- })
138
-
139
- it('should NOT ignore decimal part when ignoreDecimal is false or absent', () => {
140
- expect(converter.toWords(10.5, { ignoreDecimal: false })).toBe(
141
- 'folo faingo dimy'
142
- )
143
- expect(converter.toWords(10.5)).toBe('folo faingo dimy')
144
- })
145
- })
146
-
147
- describe('decimalPlaces option', () => {
148
- it('should ignore decimal part when decimalPlaces is 0', () => {
149
- const options: TanisaOptions = { decimalPlaces: 0 }
150
- expect(converter.toWords(123.456, options)).toBe(
151
- 'telo amby roapolo amby zato'
152
- )
153
- expect(converter.toWords(0.99, options)).toBe('aotra')
154
- })
155
-
156
- it('should truncate decimal part to specified places', () => {
157
- expect(converter.toWords(1.2345, { decimalPlaces: 1 })).toBe(
158
- 'iray faingo roa'
159
- )
160
- expect(converter.toWords(1.2345, { decimalPlaces: 2 })).toBe(
161
- 'iray faingo telo amby roapolo'
162
- )
163
- expect(converter.toWords(1.2345, { decimalPlaces: 3 })).toBe(
164
- 'iray faingo efatra amby telopolo sy roanjato'
165
- )
166
- })
167
-
168
- it('should handle leading zeros correctly with truncation', () => {
169
- expect(converter.toWords(10.056, { decimalPlaces: 1 })).toBe('folo')
170
- expect(converter.toWords(10.056, { decimalPlaces: 2 })).toBe(
171
- 'folo faingo aotra dimy'
172
- )
173
- expect(converter.toWords(10.056, { decimalPlaces: 3 })).toBe(
174
- 'folo faingo aotra enina amby dimampolo'
175
- )
176
- expect(converter.toWords(10.009, { decimalPlaces: 2 })).toBe('folo')
177
- expect(converter.toWords(10.009, { decimalPlaces: 3 })).toBe(
178
- 'folo faingo aotra aotra sivy'
179
- )
180
- })
181
-
182
- it('should convert all decimals if decimalPlaces is equal to or greater than actual places', () => {
183
- expect(converter.toWords(5.67, { decimalPlaces: 2 })).toBe(
184
- 'dimy faingo fito amby enimpolo'
185
- )
186
- expect(converter.toWords(5.67, { decimalPlaces: 3 })).toBe(
187
- 'dimy faingo fito amby enimpolo'
188
- )
189
- expect(converter.toWords(5.67, { decimalPlaces: 10 })).toBe(
190
- 'dimy faingo fito amby enimpolo'
191
- )
192
- })
193
- })
194
-
195
- describe('decimalPlaces and ignoreDecimal options', () => {
196
- it('should ignore decimal part if both params is set', () => {
197
- const options: TanisaOptions = { decimalPlaces: 2, ignoreDecimal: true }
198
- expect(converter.toWords(3.134343, options)).toBe('telo')
199
- })
200
- })
201
- })
package/tsconfig.json DELETED
@@ -1,113 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "libReplacement": true, /* Enable lib replacement. */
18
- // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
19
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
20
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
21
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
22
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
23
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
24
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
25
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
26
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
27
-
28
- /* Modules */
29
- "module": "commonjs" /* Specify what module code is generated. */,
30
- // "rootDir": "./", /* Specify the root folder within your source files. */
31
- // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
32
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
35
- // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
36
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
37
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
38
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
39
- // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
40
- // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
41
- // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
42
- // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
43
- // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
44
- // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
45
- // "resolveJsonModule": true, /* Enable importing .json files. */
46
- // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
47
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
48
-
49
- /* JavaScript Support */
50
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
51
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
52
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
53
-
54
- /* Emit */
55
- "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
56
- // "declarationMap": true /* Create sourcemaps for d.ts files. */,
57
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
58
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
59
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
60
- // "noEmit": true, /* Disable emitting files from a compilation. */
61
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
62
- "outDir": "./dist" /* Specify an output folder for all emitted files. */,
63
- "removeComments": true /* Disable emitting comments. */,
64
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
65
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
66
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
67
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
68
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
69
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
70
- // "newLine": "crlf", /* Set the newline character for emitting files. */
71
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
72
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
73
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
74
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
75
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
76
-
77
- /* Interop Constraints */
78
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
79
- // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
80
- // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
81
- // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
82
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
83
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
84
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
85
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
86
-
87
- /* Type Checking */
88
- "strict": true /* Enable all strict type-checking options. */,
89
- "noImplicitAny": true /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
90
- "strictNullChecks": true /* When type checking, take into account 'null' and 'undefined'. */,
91
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
92
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
93
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
94
- // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
95
- "noImplicitThis": true /* Enable error reporting when 'this' is given the type 'any'. */,
96
- "useUnknownInCatchVariables": true /* Default catch clause variables as 'unknown' instead of 'any'. */,
97
- "alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
98
- "noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
99
- "noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
100
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
101
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
102
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
103
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
104
- "noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
105
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
106
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
107
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
108
-
109
- /* Completeness */
110
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
111
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
112
- }
113
- }
package/vitest.config.ts DELETED
@@ -1,7 +0,0 @@
1
- import { defineConfig } from 'vite'
2
-
3
- export default defineConfig({
4
- test: {
5
- exclude: ['./dist', './node_modules'],
6
- },
7
- })