/ngx-nepali-number

Angular package that converts numbers into Nepali numbers.

Primary LanguageTypeScriptMIT LicenseMIT

ngx-nepali-number

Angular package that converts English numbers to Nepali numbers.

Installation

Use Node Package Manager npm to install ngx-nepali-number.

npm install ngx-nepali-number

Usage

Import NgxNepaliNumberModule in the root module(AppModule):

// Import module
import {NgxNepaliNumberModule} from 'ngx-nepali-number';

@NgModule({
  imports: [
    // ...
    NgxNepaliNumberModule.forRoot()
  ]
})
export class AppModule {}

Add NgxNepaliNumberService service wherever you want to use the ngx-nepali-number.

import { NgxNepaliNumberService } from "ngx-nepali-number";

class AppComponent implements OnInit {
  constructor(private nepaliNumberService: NgxNepaliNumberService) {}

  ngOnInit() {
    //English number to convert into Nepali 
    const englishNumber: number = 12345;
    const nepaliNumber: string = this.nepaliNumberService.convertToNepaliNumber(englishNumber);
    console.log(nepaliNumber);
    //check output on console
    //१२३४५
  }
}

You can use ngx-nepali-number as both angular pipe & directive.

  1. Using as angular pipe in your template
    <p>The height of Mount Everest is {{ '8848' | nepaliNumber }} Meter.</p>
  1. Using as angular directive in your template
    Total Price:<input type="number" nepaliNumber/>

if you want to bind converted nepali number into your formControl name just pass [formControl] as Angular Input.

Component:

//...
import { FormControl } from '@angular/forms';

class AppComponent implements OnInit {
 //FormControl for binding converted Nepali number 
 public totalPrice: FormControl = new FormControl();
  constructor() {}
  ngOnInit() {
    
  }
}

Template:

    Total Price:<input type="number" nepaliNumber [formControl]="totalPrice"/>
    <p>You have entered {{ totalPrice.value }} as total price.</p>

Creator

License

ngx-nepali-number is MIT licensed.