Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Latest commit

 

History

History
140 lines (74 loc) · 1.93 KB

lib.md

File metadata and controls

140 lines (74 loc) · 1.93 KB

fiRut

Chilean RUT utils for Node.js, the browser and AngularJS.


rut

This module is exposed as window.rut in browser and AngularJS versions. In Node.js require it as fi-rut.


rut.clean(value, parts)

Cleans a string out of invalid RUT characters.

Parameters

value: String, The value to clean.

parts: Boolean, If the function should return an array of parts instead of the concatenated string.

Returns: String | Array, The clean string or a String Array of parts if requested.

Example:

// Returns '7237750521'
rut.clean('7hf23775lwk052dgfdm1');

// Returns ['723775052', '1']
rut.clean('7hf23775lwk052dgfdm1', true);

rut.format(value)

Formats a string as a RUT number.

Parameters

value: String, The value to format.

Returns: String, The formatted string.

Example:

// Returns '16.992.239-k'
rut.format('16992239k');

rut.calculate(digits)

Calculates the RUT verifier.

Parameters

digits: String, The RUT digits to calculate the verifier from.

Returns: String, The verifier.

Example:

// Both return 'k'
rut.calculate(16992239);
rut.calculate('24965101');

rut.validate(value)

Validates a string for a valid RUT number.

Parameters

value: String, The string to validate.

Returns: Boolean, If the string is a valid RUT number.

Example:

// Returns true
rut.validate('24965101k');

rut.digits(value)

Get the RUT digits only.

Parameters

value: Mixed, The value to obtain the digits from.

Returns: String, The digits if any.

Example:

// Returns '14602789'
rut.digits('14.602.789-k');

rut.verifier(value)

Get the RUT verifier only.

Parameters

value: Mixed, The value to obtain the verifier from.

Returns: String, The verifier if any.

Example:

// Returns 'k'
rut.verifier('14.602.789-k');