Code Monkey home page Code Monkey logo

ng13-rut's Introduction

Angular 13 RUT

=============

npm License: MIT

Forked from https://github.com/HeyPay/ng10-rut to work with Angular 13.

Angular 13 library with several components to handle Chilean RUT validation, cleaning and formatting.

Installation

yarn add ng13-rut
# or
npm install ng13-rut --save

Usage

Set-up:

The easiest way to use this library is to import Ng13RutModule in your app's main module.

import { NgModule } from '@angular/core';
import { Ng13RutModule } from 'ng13-rut';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
  ...
  imports: [
    BrowserModule,
    Ng13RutModule
  ],
})
class DemoAppModule { }

Using it:

ng13-rut exposes multiple features that can be used to perform input validation and formatting. Probably you want to use one of the following:

  • RutValidator: Exposes the validateRut 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 formatRut directive to format RUT inputs.

RutValidator

Reactive forms
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { RutValidator } from 'ng13-rut';
export class DemoAppComponent {
  constructor (fb: FormBuilder, rutValidator: RutValidator) {
    this.reactiveForm = fb.group({
      rut: ['30972198', [Validators.required, rutValidator]]
    });
  }
}
Template Form
<input [(ngModel)]="user.rut" name="rut" validateRut required>

RutPipe

{{ user.rut }}
<!-- 30972198 -->
{{ user.rut | rut }}
<!-- 3.097.219-8 -->

formatRut (Directive)

<input [(ngModel)]="user.rut" name="rut" formatRut 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

The original lib was created based on Platanus lib: https://github.com/platanus/ng2-rut

License

Based on Angular 2 RUT by Platanus. Angular 2 RUT is © 2017 Platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.

ng13-rut's People

Contributors

bglamadrid avatar dependabot[bot] avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.