1.0.0 • Published 5 years ago
ngx-rut v1.0.0
Angular 7 RUT
Angular 7 library with several components to handle Chilean RUT validation, cleaning and formatting.
Installation
yarn add ngx-rut
# or
npm install ngx-rut --save
Usage
Set-up:
The easiest way to use this library is to import NgxRut in your app's main module.
import { NgModule } from '@angular/core';
import { NgxRut } from 'ngx-rut';
import { BrowserModule } from '@angular/platform-browser';
@NgModule({
...
imports: [
BrowserModule,
NgxRut
],
})
class DemoAppModule { }
Run dev server in base project for a fully working example.
Using it:
ngx-rut exposes multiple features that can be used to perform input validation and formatting. Probably you want to use one of the following:
RutValidatorDirective
: Exposes therutValidate
directive (to attach to models or inputs) and the RutValidator class to be used asValidator
on reactive forms.RutPipe
: Exposes theRutPipe
pipe to format rut numbers on templatesRutDirective
: Exposes therutFormat
directive to format RUT inputs.
RutValidator
Reactive forms
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { RutValidator } from 'ngx-rut';
export class DemoAppComponent {
constructor (fb: FormBuilder) {
this.reactiveForm = fb.group({
rut: ['30972198', [Validators.required, RutValidator]]
});
}
}
Template Form
<input [(ngModel)]="user.rut" name="rut" rutValidate required>
RutPipe
{{ user.rut }}
<!-- 30972198 -->
{{ user.rut | rut }}
<!-- 3.097.219-8 -->
formatRut (Directive)
<input [(ngModel)]="user.rut" name="rut" rutFormat required>
<!--
(on blur)
3.097.219-8
(on focus)
30972198
-->
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Credits
Based on platanus library Ng2Rut Thank you contributors!
License
NgxRut is free software and may be redistributed under the terms specified in the LICENSE file.
1.0.0
5 years ago