pb10001/integer-reader

View on GitHub
src/index.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { IReadableInteger } from './IReadableInteger';
import { ReadableEnglishInteger } from './ReadableEnglishInteger';
import { ReadableJapaneseInteger } from './ReadableJapaneseInteger';

export const read = (num: number, locale?: string): string => {
  let reader: IReadableInteger;
  if (num !== Math.floor(num)) {
    return null;
  } else if (locale === 'en') {
    reader = new ReadableEnglishInteger(num);
  } else if (locale === 'ja') {
    reader = new ReadableJapaneseInteger(num);
  } else {
    reader = new ReadableEnglishInteger(num);
  }
  return reader.read();
};