npm

converter-library
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Number to Text Conversion Library

This library provides functionality to convert numerical values into their corresponding textual representation in multiple languages, specifically English and Spanish. It is designed to be easily integrated into various projects requiring number-to-text conversion.

Features

  • Convert numbers to words in English and Spanish.
  • Support for large numbers (thousands, millions, billions).
  • Memoization for efficient repeated conversions.
  • Extensible architecture to add more languages in the future and more features.

Development

This project uses the following tools to ensure code quality and consistency:

*ESLint*: For code linting and enforcing coding style.
*Prettier*: For code formatting.
*Husky*: For running Git hooks to automate linting and formatting before commits.

These tools help to maintain a clean and consistent codebase and prevent common coding errors. They are configured to run automatically before each commit, ensuring that all code meets the project's standards.

To run these tools locally, you can use the following commands:

    yarn lint
    yarn prettier
    yarn prettier:check

Installation

You can install the library via npm:

yarn add converter-library

Usage

You can import the library into your project as follows:

import { ConverterModule } from 'your-library-name';

You can create an instance of ConverterModule by specifying the desired language:

const converter = new ConverterModule();
const spanishConverter = new ConverterModule('es'); // For Spanish

You can convert a number to text, use the convertNumberToText method:

const numberText = converter.convertNumberToText("1234");
console.log(numberText); // Output: "one-thousand-two-hundred-thirty-four"
const spanishNumberText = spanishConverter.convertNumberToText("1234");
console.log(spanishNumberText); // Output: "mil-doscientos-treinta y cuatro"

Handling Invalid Inputs

The library handles invalid inputs gracefully. If an invalid number is provided, the output will be:

const invalidText = converter.convertNumberToText("");
console.log(invalidText); // Output: "invalid_input"

Architecture

The library follows an extensible architecture:

BaseNumberToTextService: Abstract class for common functionalities.
EnglishNumberToTextService: Converts numbers to English text.
SpanishNumberToTextService: Converts numbers to Spanish text.
ConverterModule: Main entry point for conversion logic.

Testing

To ensure the quality of the library, it comes with a suite of tests. To run the tests, use the following command:

    yarn test

Coverage

The library also provides coverage reports. You can generate a coverage report by running:

    yarn coverage

This will create a coverage report in the coverage directory, which you can review to assess the testing coverage of your code.

CI/CD Pipeline

The project is set up with a CI/CD pipeline using Bitbucket. The pipeline runs automatically on every merge to the repository, performing the following tasks:

  • Running tests and linters to ensure code quality.
  • Generating coverage reports.
  • Running benchmarks.
  • Publishing the package to npm upon successful builds from the specified branches.

Benchmarks

You can run benchmarks to evaluate the performance of the library. To execute the benchmarks, use the following command:

    yarn benchmark

This command will run predefined benchmarks and output the results to the console, allowing you to compare performance across different methods of number conversion.

Examples

Here are some examples of how to use the library: Basic Usage

import { ConverterModule } from 'your-library-path';
const converter = new ConverterModule('en');
console.log(converter.convertNumberToText('123')); // Outputs: "one-hundred-and-twenty-three"
const spanishConverter = new ConverterModule('es');
console.log(spanishConverter.convertNumberToText('456')); // Outputs: "cuatrocientos-cincuenta-y-seis"

You can replace 'en' or 'es' with the desired language type to convert numbers accordingly.

Documentation

The library is well-documented using JSDoc comments, providing detailed descriptions of functions, classes, and interfaces. You can find JSDoc comments throughout the codebase that explain the purpose and usage of each component.

For example, the ConverterModule class and its methods are documented to guide users on how to instantiate and utilize the conversion features effectively.

Contributions

Contributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details. Contact

Readme

Keywords

none

Package Sidebar

Install

npm i converter-library

Weekly Downloads

3

Version

1.2.0

License

MIT

Unpacked Size

80.1 kB

Total Files

78

Last publish

Collaborators

  • tiarakhayat