ng-number-to-text
v1.0.9
Published
Set of pipes for angular2+ projects to convert numbers to words as ordinal numbers
Downloads
35
Maintainers
Readme
Number To Text
Number To Text is an angular module that contains a set of pipes to convert numbers into words.
Features
- Convert numbers into words for both languages (Arabic and English) -more languages will be added later-.
- For Arabic language, Masculine and Feminine expressions are added.
- Can convert from 0 to 100 as ordinal numbers.
- It can be used for ordering, building floors, etc.
Installation
Use npm to install:
npm i ng-number-to-text
Usage
- First, import the module:
import {NumberToTextModule} from 'ng-number-to-text';
@NgModule({
declarations: [
...
],
imports: [
...
NumberToTextModule,
...
],
providers: [...],
bootstrap: [...]
})
export class AppModule { }
- Second, use it in your component in one of two ways:
- in your *.ts file:
import {Component, OnInit} from '@angular/core';
import {NumberToTextPipe} from 'ng-number-to-text/lib/pipes/number-to-text.pipe';
import {NumberToTextArPipe} from 'ng-number-to-text/lib/pipes/number-to-text-ar.pipe';
import {NumberToTextArFemPipe} from 'ng-number-to-text/lib/pipes/number-to-text-ar-fem.pipe';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [NumberToTextPipe, NumberToTextArPipe, NumberToTextArFemPipe]
})
export class AppComponent implements OnInit {
textEn: string;
textAr: string;
textArFem: string;
constructor(
private numberToTextPipe: NumberToTextPipe,
private numberToTextArPipe: NumberToTextArPipe,
private numberToTextArFemPipe: NumberToTextArFemPipe
) {}
ngOnInit(): void {
this.textEn = this.numberToTextPipe.transform(12); // The twelfth
this.textAr = this.numberToTextArPipe.transform(12); // الثانى عشر
this.textArFem = this.numberToTextArFemPipe.transform(12); // الثانية عشر
}
}
- in your *.html file:
<h1>{{'45' | numberToText}}</h1> // The forty-fifth
<h1>{{'45' | numberToTextAr}}</h1> // الخامس والاربعون
<h1>{{'45' | numberToTextArFem}}</h1> // الخامسة والاربعون
Contributing
Feel free to contribute GitHub.