Skip to content

Commit

Permalink
feat: expose locales in an iterable capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
s1gtrap committed Jul 16, 2024
1 parent d7ef165 commit cb7b8cf
Show file tree
Hide file tree
Showing 32 changed files with 211 additions and 234 deletions.
28 changes: 15 additions & 13 deletions dist/ToWords.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { ConstructorOf, ConverterOptions, LocaleInterface, ToWordsOptions } from './types';
import LOCALES from './locales';
export { LOCALES };
export declare const DefaultConverterOptions: ConverterOptions;
export declare const DefaultToWordsOptions: ToWordsOptions;
export declare class ToWords {
private options;
private locale;
constructor(options?: ToWordsOptions);
getLocaleClass(): ConstructorOf<LocaleInterface>;
getLocale(): InstanceType<ConstructorOf<LocaleInterface>>;
convert(number: number, options?: ConverterOptions): string;
protected convertNumber(number: number): string[];
protected convertCurrency(number: number, options?: ConverterOptions): string[];
protected convertInternal(number: number, trailing?: boolean): string[];
toFixed(number: number, precision?: number): number;
isFloat(number: number | string): boolean;
isValidNumber(number: number | string): boolean;
isNumberZero(number: number): boolean;
private options;
private locale;
constructor(options?: ToWordsOptions);
getLocaleClass(): ConstructorOf<LocaleInterface>;
getLocale(): InstanceType<ConstructorOf<LocaleInterface>>;
convert(number: number, options?: ConverterOptions): string;
protected convertNumber(number: number): string[];
protected convertCurrency(number: number, options?: ConverterOptions): string[];
protected convertInternal(number: number, trailing?: boolean): string[];
toFixed(number: number, precision?: number): number;
isFloat(number: number | string): boolean;
isValidNumber(number: number | string): boolean;
isNumberZero(number: number): boolean;
}
87 changes: 7 additions & 80 deletions dist/ToWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToWords = exports.DefaultToWordsOptions = exports.DefaultConverterOptions = void 0;
const ee_EE_1 = __importDefault(require("./locales/ee-EE"));
const en_AE_1 = __importDefault(require("./locales/en-AE"));
const en_BD_1 = __importDefault(require("./locales/en-BD"));
const en_GB_1 = __importDefault(require("./locales/en-GB"));
const en_GH_1 = __importDefault(require("./locales/en-GH"));
const en_IE_1 = __importDefault(require("./locales/en-IE"));
const en_IN_1 = __importDefault(require("./locales/en-IN"));
const en_MM_1 = __importDefault(require("./locales/en-MM"));
const en_MU_1 = __importDefault(require("./locales/en-MU"));
const en_NG_1 = __importDefault(require("./locales/en-NG"));
const en_NP_1 = __importDefault(require("./locales/en-NP"));
const en_PH_1 = __importDefault(require("./locales/en-PH"));
const en_US_1 = __importDefault(require("./locales/en-US"));
const es_ES_1 = __importDefault(require("./locales/es-ES"));
const es_MX_1 = __importDefault(require("./locales/es-MX"));
const fa_IR_1 = __importDefault(require("./locales/fa-IR"));
const fr_BE_1 = __importDefault(require("./locales/fr-BE"));
const fr_FR_1 = __importDefault(require("./locales/fr-FR"));
const gu_IN_1 = __importDefault(require("./locales/gu-IN"));
const hi_IN_1 = __importDefault(require("./locales/hi-IN"));
const ko_KR_1 = __importDefault(require("./locales/ko-KR"));
const mr_IN_1 = __importDefault(require("./locales/mr-IN"));
const nl_SR_1 = __importDefault(require("./locales/nl-SR"));
const pt_BR_1 = __importDefault(require("./locales/pt-BR"));
const tr_TR_1 = __importDefault(require("./locales/tr-TR"));
exports.ToWords = exports.DefaultToWordsOptions = exports.DefaultConverterOptions = exports.LOCALES = void 0;
const locales_1 = __importDefault(require("./locales"));
exports.LOCALES = locales_1.default;
exports.DefaultConverterOptions = {
currency: false,
ignoreDecimal: false,
Expand All @@ -46,61 +23,11 @@ class ToWords {
this.options = Object.assign({}, exports.DefaultToWordsOptions, options);
}
getLocaleClass() {
/* eslint-disable @typescript-eslint/no-var-requires */
switch (this.options.localeCode) {
case 'ee-EE':
return ee_EE_1.default;
case 'en-AE':
return en_AE_1.default;
case 'en-BD':
return en_BD_1.default;
case 'en-GB':
return en_GB_1.default;
case 'en-GH':
return en_GH_1.default;
case 'en-IE':
return en_IE_1.default;
case 'en-IN':
return en_IN_1.default;
case 'en-MM':
return en_MM_1.default;
case 'en-MU':
return en_MU_1.default;
case 'en-NG':
return en_NG_1.default;
case 'en-NP':
return en_NP_1.default;
case 'en-PH':
return en_PH_1.default;
case 'en-US':
return en_US_1.default;
case 'es-ES':
return es_ES_1.default;
case 'es-MX':
return es_MX_1.default;
case 'fa-IR':
return fa_IR_1.default;
case 'fr-BE':
return fr_BE_1.default;
case 'fr-FR':
return fr_FR_1.default;
case 'gu-IN':
return gu_IN_1.default;
case 'hi-IN':
return hi_IN_1.default;
case 'ko-KR':
return ko_KR_1.default;
case 'mr-IN':
return mr_IN_1.default;
case 'nl-SR':
return nl_SR_1.default;
case 'pt-BR':
return pt_BR_1.default;
case 'tr-TR':
return tr_TR_1.default;
if (!(this.options.localeCode in locales_1.default)) {
/* eslint-enable @typescript-eslint/no-var-requires */
throw new Error(`Unknown Locale "${this.options.localeCode}"`);
}
/* eslint-enable @typescript-eslint/no-var-requires */
throw new Error(`Unknown Locale "${this.options.localeCode}"`);
return locales_1.default[this.options.localeCode];
}
getLocale() {
if (this.locale === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion dist/locales/ee-EE.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-AE.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-BD.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-GB.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-GH.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-IE.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-IN.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-MM.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-MU.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-NG.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-NP.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-PH.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/en-US.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/es-ES.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/es-MX.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/fa-IR.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/fr-BE.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/fr-FR.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/gu-IN.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/hi-IN.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
5 changes: 5 additions & 0 deletions dist/locales/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ConstructorOf, LocaleInterface } from '../types';
declare const LOCALES: {
[key: string]: ConstructorOf<LocaleInterface>;
};
export default LOCALES;
58 changes: 58 additions & 0 deletions dist/locales/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ee_EE_1 = __importDefault(require("./ee-EE"));
const en_AE_1 = __importDefault(require("./en-AE"));
const en_BD_1 = __importDefault(require("./en-BD"));
const en_GB_1 = __importDefault(require("./en-GB"));
const en_GH_1 = __importDefault(require("./en-GH"));
const en_IE_1 = __importDefault(require("./en-IE"));
const en_IN_1 = __importDefault(require("./en-IN"));
const en_MM_1 = __importDefault(require("./en-MM"));
const en_MU_1 = __importDefault(require("./en-MU"));
const en_NG_1 = __importDefault(require("./en-NG"));
const en_NP_1 = __importDefault(require("./en-NP"));
const en_PH_1 = __importDefault(require("./en-PH"));
const en_US_1 = __importDefault(require("./en-US"));
const es_ES_1 = __importDefault(require("./es-ES"));
const es_MX_1 = __importDefault(require("./es-MX"));
const fa_IR_1 = __importDefault(require("./fa-IR"));
const fr_BE_1 = __importDefault(require("./fr-BE"));
const fr_FR_1 = __importDefault(require("./fr-FR"));
const gu_IN_1 = __importDefault(require("./gu-IN"));
const hi_IN_1 = __importDefault(require("./hi-IN"));
const ko_KR_1 = __importDefault(require("./ko-KR"));
const mr_IN_1 = __importDefault(require("./mr-IN"));
const nl_SR_1 = __importDefault(require("./nl-SR"));
const pt_BR_1 = __importDefault(require("./pt-BR"));
const tr_TR_1 = __importDefault(require("./tr-TR"));
const LOCALES = {
'ee-EE': ee_EE_1.default,
'en-AE': en_AE_1.default,
'en-BD': en_BD_1.default,
'en-GB': en_GB_1.default,
'en-GH': en_GH_1.default,
'en-IE': en_IE_1.default,
'en-IN': en_IN_1.default,
'en-MM': en_MM_1.default,
'en-MU': en_MU_1.default,
'en-NG': en_NG_1.default,
'en-NP': en_NP_1.default,
'en-PH': en_PH_1.default,
'en-US': en_US_1.default,
'es-ES': es_ES_1.default,
'es-MX': es_MX_1.default,
'fa-IR': fa_IR_1.default,
'fr-BE': fr_BE_1.default,
'fr-FR': fr_FR_1.default,
'gu-IN': gu_IN_1.default,
'hi-IN': hi_IN_1.default,
'ko-KR': ko_KR_1.default,
'mr-IN': mr_IN_1.default,
'nl-SR': nl_SR_1.default,
'pt-BR': pt_BR_1.default,
'tr-TR': tr_TR_1.default,
};
exports.default = LOCALES;
2 changes: 1 addition & 1 deletion dist/locales/ko-KR.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/mr-IN.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/nl-SR.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/pt-BR.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
2 changes: 1 addition & 1 deletion dist/locales/tr-TR.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LocaleConfig, LocaleInterface } from '../types';
export default class Locale implements LocaleInterface {
config: LocaleConfig;
config: LocaleConfig;
}
Loading

0 comments on commit cb7b8cf

Please sign in to comment.