1.0.0 • Published 5 years ago

ngx-rut v1.0.0

Weekly downloads
11
License
-
Repository
-
Last release
5 years ago

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 the rutValidate directive (to attach to models or inputs) and the RutValidator class to be used as Validator on reactive forms.
  • RutPipe: Exposes the RutPipe pipe to format rut numbers on templates
  • RutDirective: Exposes the rutFormat 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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. 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.