react-rut
Version:
Chilean RUT for React
19 lines • 685 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const unformat_1 = __importDefault(require("./unformat"));
function format(value) {
const unformatted = unformat_1.default(value);
if (unformatted.length < 2) {
return unformatted;
}
const length = unformatted.length - 1;
const rut = unformatted
.substring(0, length)
.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
return `${rut}-${unformatted.charAt(length)}`;
}
exports.default = format;
//# sourceMappingURL=format.js.map