Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #45
This commit is contained in:
2025-10-04 11:40:52 -03:00
parent 6ddc48ec60
commit 742de657c5
815 changed files with 62089 additions and 3287 deletions

View File

@ -0,0 +1,41 @@
@push('page_scripts')
<script>
class Rut {
static digitoVerificador(rut) {
if (!(typeof rut === 'string' || rut instanceof String)) {
rut = rut.toString()
}
if (rut.length === 0) {
return ''
}
let M = 0, S = 1
for (; rut; rut = Math.floor(rut / 10)) {
S = (S + rut % 10 * (9 - M++ % 6)) % 11
}
return S ? S - 1 : 'K'
}
static format(rut) {
if (!(typeof rut === 'string' || rut instanceof String)) {
rut = rut.toString()
}
if (rut.length === 0) {
return ''
}
rut.replace(/\D/g, '')
return rut.replace(/^(\d{1,2})(\d{3})(\d{3})$/, '$1.$2.$3')
}
static clean(rut) {
if (!(typeof rut === 'string' || rut instanceof String)) {
rut = rut.toString()
}
return rut.replace(/\D/g, '')
}
static validar(rut, digito) {
if (!(typeof digito === 'string' || digito instanceof String)) {
digito = digito.toString()
}
return Rut.digitoVerificador(rut).toString().toUpperCase() === digito.toUpperCase()
}
}
</script>
@endpush