No longer maintained. Please see @fiquu/cl-rut.
Chilean RUT utils for Node.js, the browser and AngularJS.
bower install --save fi-rut
Include the distributable versions into your scripts bundle or load them as scripts in your HTML.
The library will be assigned as rut
into the window
so you can access its methods directly via window.rut
.
IMPORTANT: Values will allways be converted to lower case to enforce consistency.
For production use the non-minified version:
<script src="/bower_components/fi-rut/dist/fi-rut.js"></script>
For production use the minified version:
<script src="/bower_components/fi-rut/dist/fi-rut.min.js"></script>
var input = document.querySelector('input#rut');
var calculated = rut.calculate(input.value);
var verififer = rut.verifier(input.value);
var isValid = rut.validate(input.value);
var formatted = rut.format(input.value);
var digits = rut.digits(input.value);
var clean = rut.clean(input.value);
Read the library docs for the library's methods specification.
bower install --save fi-rut
Include the distributable versions into your scripts bundle or load them as scripts in your HTML.
This version includes both the browser and AngularJS modules.
The library will be assigned as rut
into the window
so you can access its methods directly via window.rut
.
For development or easy debugging use the non-minified version:
<script src="/bower_components/fi-rut/dist/fi-rut-ng.js"></script>
For production use the minified version:
<script src="/bower_components/fi-rut/dist/fi-rut-ng.min.js"></script>
Include the ngRut
dependency into your app:
angular.module('MyApp', [
// ...
'ngRut'
// ...
]);
The ng-rut
directive must be used only in an <input>
element and will add real-time format and validation to the associated ngModel
:
<input ng-model="data.rut" ng-rut>
Use the ngRut
service to access the module's methods programatically:
function MyController($scope, ngRut) {
var calculated = ngRut.calculate($scope.data.rut);
var verififer = ngRut.verifier($scope.data.rut);
var isValid = ngRut.validate($scope.data.rut);
var formatted = ngRut.format($scope.data.rut);
var digits = ngRut.digits($scope.data.rut);
var clean = ngRut.clean($scope.data.rut);
}
angular.module('MyApp').controller('MyController', ['$scope', 'ngRut', MyController]);
Use the ngRut
filter to interpolate template strings:
<p>{{ data.rut | ngRut }}</p>
<p>{{ data.rut | ngRut : 'calculate' }}</p>
<p>{{ data.rut | ngRut : 'validate' }}</p>
<p>{{ data.rut | ngRut : 'verifier' }}</p>
<p>{{ data.rut | ngRut : 'digits' }}</p>
<p>{{ data.rut | ngRut : 'clean' }}</p>
The module, filter, directive and service are called ngRut
(not fi-rut
) to maintain compatibility with the deprecated ngRut module.
Read the library docs for the library's methods specification.
Read the AngularJS docs for usage and specification on the module, service, directive and filter.
npm install --save fi-rut
Just require fi-rut
.
const rut = require('fi-rut');
const rut = require('fi-rut');
var value = '22222222';
var calculated = rut.calculate(value);
var verififer = rut.verifier(value);
var isValid = rut.validate(value);
var formatted = rut.format(value);
var digits = rut.digits(value);
var clean = rut.clean(value);
Read the library docs for the methods specification.