ngx-rut-v2 1.6.4 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -110
- package/fesm2022/ngx-rut-v2.mjs +55 -26
- package/fesm2022/ngx-rut-v2.mjs.map +1 -1
- package/package.json +6 -6
- package/types/ngx-rut-v2.d.ts +63 -0
- package/index.d.ts +0 -5
- package/lib/directives/rut-validator.directive.d.ts +0 -8
- package/lib/directives/rut-value-accessor.directive.d.ts +0 -18
- package/lib/directives/rut.directive.d.ts +0 -7
- package/lib/helpers/rut-helpers.d.ts +0 -20
- package/lib/pipes/rut.pipe.d.ts +0 -7
- package/public-api.d.ts +0 -5
package/README.md
CHANGED
|
@@ -1,110 +1,174 @@
|
|
|
1
|
-
# ngx-rut-v2
|
|
2
|
-
|
|
3
|
-
Basado en [ngx-rut](https://github.com/danieldiazastudillo/ngx-rut) pero usando Angular con
|
|
4
|
-
|
|
5
|
-
Valida y formatea [RUT Chilenos](https://en.wikipedia.org/wiki/National_identification_number#Chile)
|
|
6
|
-
|
|
7
|
-
## Compatibilidad
|
|
8
|
-
|
|
9
|
-
| Versión ngx-rut-v2 | Versión Angular |
|
|
10
|
-
|
|
11
|
-
| 1.5.0 | 18 |
|
|
12
|
-
| 1.6.0 | 19 |
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
```html
|
|
80
|
-
|
|
81
|
-
<!--
|
|
82
|
-
|
|
83
|
-
3.097.219-8
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
1
|
+
# ngx-rut-v2
|
|
2
|
+
|
|
3
|
+
Basado en [ngx-rut](https://github.com/danieldiazastudillo/ngx-rut) pero usando Angular con componentes, directivas y validaciones _standalone_. Para uso en Angular con módulos se recomienda esa versión.
|
|
4
|
+
|
|
5
|
+
Valida y formatea [RUT Chilenos](https://en.wikipedia.org/wiki/National_identification_number#Chile)
|
|
6
|
+
|
|
7
|
+
## Compatibilidad Angular
|
|
8
|
+
|
|
9
|
+
| Versión ngx-rut-v2 | Versión Angular | Estado |
|
|
10
|
+
|--------------------|-----------------|--------|
|
|
11
|
+
| 1.5.0 | 18 | ✅ Soportado |
|
|
12
|
+
| 1.6.0 | 19 | ✅ Soportado |
|
|
13
|
+
| 1.7.0 | 19 | ✅ Soportado |
|
|
14
|
+
| 1.8.0 | 20 | ✅ Soportado |
|
|
15
|
+
| 1.9.0 | 21 | ✅ Soportado |
|
|
16
|
+
| 1.10.0 | 21 | ✅ Actual (Recomendado) |
|
|
17
|
+
|
|
18
|
+
> **Nota:** Las versiones soportan Angular desde 20.0.0 hasta 21.x. Para versiones anteriores de Angular, consulte versiones anteriores de la librería.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install --save ngx-rut-v2
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Set-up:
|
|
28
|
+
|
|
29
|
+
Se deben importar las funciones, directivas & pipes directamente (standalones)
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
...
|
|
33
|
+
import { rutValidator, RutValidator, RutDirective, RutPipe, RutValueAccessor } from 'ngx-rut-v2';
|
|
34
|
+
...
|
|
35
|
+
|
|
36
|
+
@Component({
|
|
37
|
+
selector: 'app-some-component',
|
|
38
|
+
standalone: true, //IMPORTANTE!
|
|
39
|
+
imports: [
|
|
40
|
+
RutValidator,
|
|
41
|
+
RutDirective,
|
|
42
|
+
RutPipe,
|
|
43
|
+
RutValueAccessor
|
|
44
|
+
]
|
|
45
|
+
})
|
|
46
|
+
class SomeComponent { }
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Uso
|
|
51
|
+
|
|
52
|
+
El paquete expone diversas funciones de validación de RUTs. Sin embargo se recomienda usar:
|
|
53
|
+
- `rutValidator`: Función validadora para formularios reactivos.
|
|
54
|
+
- `RutValidator`: Expone la directiva `validateRut` (para `NgModel` o `inputs` en _Template-Driven Forms_)
|
|
55
|
+
- `RutPipe`: Expone el _pipe_ para formatear texto como RUT
|
|
56
|
+
- `RutDirective`: Expone la directiva `formatRut` para formateo de `inputs`
|
|
57
|
+
- `RutValueAccessor`: ControlValueAccessor para formularios reactivos con formateo automático
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Reactive Forms
|
|
61
|
+
|
|
62
|
+
#### Componente
|
|
63
|
+
```typescript
|
|
64
|
+
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
|
|
65
|
+
import { rutValidator } from 'ngx-rut-v2';
|
|
66
|
+
export class DemoAppComponent {
|
|
67
|
+
constructor (private fb: FormBuilder) {
|
|
68
|
+
this.reactiveForm = fb.group({
|
|
69
|
+
rut: ['30972198', [Validators.required, rutValidator]]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Template
|
|
76
|
+
|
|
77
|
+
##### Rut Pipe (standalone)
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
{{ user.rut }}
|
|
81
|
+
<!-- 30972198 -->
|
|
82
|
+
{{ user.rut | rut }}
|
|
83
|
+
<!-- 3.097.219-8 -->
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
##### RutValueAccessor (Directiva con Formateo en Tiempo Real)
|
|
87
|
+
|
|
88
|
+
> **NUEVO en v1.10.0:** Formateo automático mientras el usuario escribe, con restricción de caracteres y conversión automática a mayúsculas.
|
|
89
|
+
|
|
90
|
+
**Características:**
|
|
91
|
+
- ✅ Formateo en tiempo real mientras escribe (no espera blur)
|
|
92
|
+
- ✅ Restricción de entrada: solo números y letra 'K'
|
|
93
|
+
- ✅ Conversión automática de 'k' a 'K' (mayúscula)
|
|
94
|
+
- ✅ Preservación de la posición del cursor durante el formateo
|
|
95
|
+
- ✅ Validación en tiempo real con `rutValidator`
|
|
96
|
+
- ✅ El input muestra el valor formateado (ej: "12.345.678-K")
|
|
97
|
+
- ✅ El formulario recibe el valor limpio (ej: "12345678K")
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<input formControlName="rut" formatRut />
|
|
101
|
+
<!--
|
|
102
|
+
Mientras escribe: 12345678k
|
|
103
|
+
Se muestra: 12.345.678-K (automáticamente formateado y en mayúscula)
|
|
104
|
+
Valor del form: 12345678K (sin formato, listo para validación)
|
|
105
|
+
-->
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Ejemplo Completo con Validación:**
|
|
109
|
+
```typescript
|
|
110
|
+
import { Component, inject } from '@angular/core';
|
|
111
|
+
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
|
112
|
+
import { rutValidator, RutValueAccessor, RutPipe } from 'ngx-rut-v2';
|
|
113
|
+
|
|
114
|
+
@Component({
|
|
115
|
+
selector: 'app-rut-example',
|
|
116
|
+
standalone: true,
|
|
117
|
+
imports: [ReactiveFormsModule, RutValueAccessor, RutPipe],
|
|
118
|
+
template: `
|
|
119
|
+
<form [formGroup]="form">
|
|
120
|
+
<label for="rut">RUT (Rol Único Tributario):</label>
|
|
121
|
+
<input
|
|
122
|
+
id="rut"
|
|
123
|
+
formControlName="rut"
|
|
124
|
+
formatRut
|
|
125
|
+
class="form-control"
|
|
126
|
+
/>
|
|
127
|
+
|
|
128
|
+
@if (form.get('rut')?.hasError('invalidRut')) {
|
|
129
|
+
<div class="text-danger">
|
|
130
|
+
El RUT ingresado es inválido
|
|
131
|
+
</div>
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@if (form.get('rut')?.valid && form.get('rut')?.value) {
|
|
135
|
+
<div class="text-success">
|
|
136
|
+
✓ El RUT es válido
|
|
137
|
+
</div>
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
<p>Valor del formulario: {{ form.value | json }}</p>
|
|
141
|
+
<p>RUT Formateado: {{ form.get('rut')?.value | rut }}</p>
|
|
142
|
+
</form>
|
|
143
|
+
`
|
|
144
|
+
})
|
|
145
|
+
export class RutExampleComponent {
|
|
146
|
+
private fb = inject(FormBuilder);
|
|
147
|
+
|
|
148
|
+
form = this.fb.group({
|
|
149
|
+
rut: ['', [Validators.required, rutValidator]]
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
##### Error Form
|
|
154
|
+
|
|
155
|
+
>IMPORTANTE: Por defecto el error que retorna la validación es `invalidRut`
|
|
156
|
+
|
|
157
|
+
```html
|
|
158
|
+
<mat-form-field>
|
|
159
|
+
<mat-label>RUT</mat-label>
|
|
160
|
+
<input matInput formControlName="rut" formatRut />
|
|
161
|
+
@if (reactiveForm.get('rut')?.hasError('invalidRut')) {
|
|
162
|
+
<mat-error>El RUT ingresado es <strong>inválido</strong></mat-error>
|
|
163
|
+
}
|
|
164
|
+
</mat-form-field>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
##### Template-Driven Forms
|
|
168
|
+
```html
|
|
169
|
+
<input [(ngModel)]="user.rut" name="rut" validateRut formatRut required>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
package/fesm2022/ngx-rut-v2.mjs
CHANGED
|
@@ -81,19 +81,18 @@ class RutValidator {
|
|
|
81
81
|
validate(control) {
|
|
82
82
|
return rutValidator(control);
|
|
83
83
|
}
|
|
84
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
85
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
84
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutValidator, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
85
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: RutValidator, isStandalone: true, selector: "[validateRut][ngModel],[validateRut][formControl]", providers: [
|
|
86
86
|
{ provide: NG_VALIDATORS, useExisting: forwardRef(() => RutValidator), multi: true },
|
|
87
87
|
], ngImport: i0 });
|
|
88
88
|
}
|
|
89
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
89
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutValidator, decorators: [{
|
|
90
90
|
type: Directive,
|
|
91
91
|
args: [{
|
|
92
92
|
selector: '[validateRut][ngModel],[validateRut][formControl]',
|
|
93
93
|
providers: [
|
|
94
94
|
{ provide: NG_VALIDATORS, useExisting: forwardRef(() => RutValidator), multi: true },
|
|
95
|
-
]
|
|
96
|
-
standalone: true
|
|
95
|
+
]
|
|
97
96
|
}]
|
|
98
97
|
}] });
|
|
99
98
|
|
|
@@ -111,18 +110,45 @@ class RutValueAccessor {
|
|
|
111
110
|
this.renderer = renderer;
|
|
112
111
|
this.elementRef = elementRef;
|
|
113
112
|
}
|
|
114
|
-
onInput(
|
|
115
|
-
const
|
|
113
|
+
onInput(event) {
|
|
114
|
+
const input = event.target;
|
|
115
|
+
const cursorPosition = input.selectionStart || 0;
|
|
116
|
+
const previousValue = input.value;
|
|
117
|
+
// Get the raw value and clean it (only numbers and K)
|
|
118
|
+
const rawValue = input.value.toUpperCase();
|
|
116
119
|
const cleaned = rutClean(rawValue);
|
|
120
|
+
// Format the cleaned value for display
|
|
117
121
|
const formatted = rutFormat(cleaned);
|
|
118
|
-
//
|
|
122
|
+
// Update the input display with formatted value
|
|
119
123
|
this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatted);
|
|
120
|
-
//
|
|
124
|
+
// Send the cleaned (unformatted) value to the form control
|
|
121
125
|
this.onChange(cleaned);
|
|
126
|
+
// Adjust cursor position after formatting
|
|
127
|
+
const lengthDiff = formatted.length - previousValue.length;
|
|
128
|
+
const newPosition = cursorPosition + lengthDiff;
|
|
129
|
+
// Restore cursor position
|
|
130
|
+
setTimeout(() => {
|
|
131
|
+
input.setSelectionRange(newPosition, newPosition);
|
|
132
|
+
}, 0);
|
|
122
133
|
}
|
|
123
134
|
onBlur() {
|
|
124
135
|
this.onTouched();
|
|
125
136
|
}
|
|
137
|
+
onKeyDown(event) {
|
|
138
|
+
const key = event.key;
|
|
139
|
+
// Allow: backspace, delete, tab, escape, enter, arrows, home, end
|
|
140
|
+
if (['Backspace', 'Delete', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(key)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
// Allow: Ctrl+A, Ctrl+C, Ctrl+V, Ctrl+X
|
|
144
|
+
if (event.ctrlKey || event.metaKey) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// Allow only numbers and K/k
|
|
148
|
+
if (!/^[0-9kK]$/.test(key)) {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
126
152
|
writeValue(value) {
|
|
127
153
|
const formatted = rutFormat(value) || '';
|
|
128
154
|
this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatted);
|
|
@@ -136,56 +162,59 @@ class RutValueAccessor {
|
|
|
136
162
|
setDisabledState(isDisabled) {
|
|
137
163
|
this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
|
|
138
164
|
}
|
|
139
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
140
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
165
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutValueAccessor, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
166
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: RutValueAccessor, isStandalone: true, selector: "input[formatRut]", host: { listeners: { "input": "onInput($event)", "blur": "onBlur()", "keydown": "onKeyDown($event)" } }, providers: [RUT_VALUE_ACCESSOR], ngImport: i0 });
|
|
141
167
|
}
|
|
142
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
168
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutValueAccessor, decorators: [{
|
|
143
169
|
type: Directive,
|
|
144
170
|
args: [{
|
|
145
171
|
selector: 'input[formatRut]',
|
|
146
|
-
standalone: true,
|
|
147
172
|
providers: [RUT_VALUE_ACCESSOR],
|
|
148
173
|
}]
|
|
149
174
|
}], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }], propDecorators: { onInput: [{
|
|
150
175
|
type: HostListener,
|
|
151
|
-
args: ['input', ['$event
|
|
176
|
+
args: ['input', ['$event']]
|
|
152
177
|
}], onBlur: [{
|
|
153
178
|
type: HostListener,
|
|
154
179
|
args: ['blur']
|
|
180
|
+
}], onKeyDown: [{
|
|
181
|
+
type: HostListener,
|
|
182
|
+
args: ['keydown', ['$event']]
|
|
155
183
|
}] } });
|
|
156
184
|
|
|
157
185
|
class RutDirective {
|
|
158
|
-
onFocus(
|
|
186
|
+
onFocus(event) {
|
|
187
|
+
const input = event.target;
|
|
159
188
|
input.value = rutClean(input.value);
|
|
160
189
|
}
|
|
161
|
-
onBlur(
|
|
190
|
+
onBlur(event) {
|
|
191
|
+
const input = event.target;
|
|
162
192
|
input.value = rutFormat(input.value) || '';
|
|
163
193
|
}
|
|
164
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
165
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
194
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
195
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.6", type: RutDirective, isStandalone: true, selector: "[formatRut]", host: { listeners: { "focus": "onFocus($event)", "blur": "onBlur($event)" } }, ngImport: i0 });
|
|
166
196
|
}
|
|
167
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
197
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutDirective, decorators: [{
|
|
168
198
|
type: Directive,
|
|
169
199
|
args: [{
|
|
170
|
-
selector: '[formatRut]'
|
|
171
|
-
standalone: true
|
|
200
|
+
selector: '[formatRut]'
|
|
172
201
|
}]
|
|
173
202
|
}], propDecorators: { onFocus: [{
|
|
174
203
|
type: HostListener,
|
|
175
|
-
args: ['focus', ['$event
|
|
204
|
+
args: ['focus', ['$event']]
|
|
176
205
|
}], onBlur: [{
|
|
177
206
|
type: HostListener,
|
|
178
|
-
args: ['blur', ['$event
|
|
207
|
+
args: ['blur', ['$event']]
|
|
179
208
|
}] } });
|
|
180
209
|
|
|
181
210
|
class RutPipe {
|
|
182
211
|
transform(value) {
|
|
183
212
|
return rutFormat(value);
|
|
184
213
|
}
|
|
185
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
186
|
-
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "
|
|
214
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
215
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.0.6", ngImport: i0, type: RutPipe, isStandalone: true, name: "rut" });
|
|
187
216
|
}
|
|
188
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
217
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: RutPipe, decorators: [{
|
|
189
218
|
type: Pipe,
|
|
190
219
|
args: [{
|
|
191
220
|
name: 'rut',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-rut-v2.mjs","sources":["../../../projects/ngx-rut-v2/src/lib/helpers/rut-helpers.ts","../../../projects/ngx-rut-v2/src/lib/directives/rut-validator.directive.ts","../../../projects/ngx-rut-v2/src/lib/directives/rut-value-accessor.directive.ts","../../../projects/ngx-rut-v2/src/lib/directives/rut.directive.ts","../../../projects/ngx-rut-v2/src/lib/pipes/rut.pipe.ts","../../../projects/ngx-rut-v2/src/public-api.ts","../../../projects/ngx-rut-v2/src/ngx-rut-v2.ts"],"sourcesContent":["/**\r\n *\r\n * @param value The RUT string to clean.\r\n * @description Cleans a RUT (Rol Único Tributario) string by removing non-numeric characters and leading zeros.\r\n * Converts the RUT to uppercase and returns it.\r\n * @returns The cleaned RUT string.\r\n */\r\nexport function rutClean(value: string): string {\r\n if (typeof value === 'string') {\r\n return value\r\n .replace(/[^0-9kK]+/g, '')\r\n .replace(/^0+/, '')\r\n .toUpperCase();\r\n }\r\n return '';\r\n}\r\n\r\n/**\r\n * @param value The RUT string to validate.\r\n * @description Validates a RUT (Rol Único Tributario) string.\r\n * @returns True if the RUT is valid, false otherwise.\r\n */\r\nexport function rutValidate(value: string): boolean {\r\n if (typeof value !== 'string') {\r\n return false;\r\n }\r\n\r\n const rut: string = rutClean(value);\r\n if (rut.length < 2) {\r\n return false;\r\n }\r\n\r\n const body: string = rut.slice(0, -1);\r\n const dv: string = rut.slice(-1).toUpperCase();\r\n\r\n let sum = 0;\r\n let multiplier = 2;\r\n\r\n for (let i = body.length - 1; i >= 0; i--) {\r\n sum += parseInt(body.charAt(i), 10) * multiplier;\r\n multiplier = multiplier === 7 ? 2 : multiplier + 1;\r\n }\r\n\r\n const expectedDv = 11 - (sum % 11);\r\n let expectedDvStr = '';\r\n\r\n if (expectedDv === 11) {\r\n expectedDvStr = '0';\r\n } else if (expectedDv === 10) {\r\n expectedDvStr = 'K';\r\n } else {\r\n expectedDvStr = expectedDv.toString();\r\n }\r\n\r\n return dv === expectedDvStr;\r\n}\r\n\r\n/**\r\n * Formats a RUT (Rol Único Tributario) string.\r\n * @param value The RUT string to format.\r\n * @returns The formatted RUT string.\r\n */\r\nexport function rutFormat(value: string): string {\r\n const rut: string = rutClean(value);\r\n\r\n if (rut.length <= 1) {\r\n return rut;\r\n }\r\n\r\n let result: string = `${rut.slice(-4, -1)}-${rut.slice(-1)}`;\r\n for (let i: number = 4; i < rut.length; i += 3) {\r\n result = `${rut.slice(-3 - i, -i)}.${result}`;\r\n }\r\n\r\n return result;\r\n}\r\n","import { Directive, forwardRef } from '@angular/core';\r\nimport { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator, ValidatorFn } from '@angular/forms';\r\nimport { rutValidate } from '../helpers/rut-helpers';\r\n\r\n// Single reusable ValidatorFn\r\nexport const rutValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {\r\n const value = control.value;\r\n if (!value) {\r\n return null;\r\n }\r\n return rutValidate(value) ? null : { invalidRut: true };\r\n};\r\n\r\n@Directive({\r\n selector: '[validateRut][ngModel],[validateRut][formControl]',\r\n providers: [\r\n { provide: NG_VALIDATORS, useExisting: forwardRef(() => RutValidator), multi: true },\r\n ],\r\n standalone: true\r\n})\r\nexport class RutValidator implements Validator {\r\n validate(control: AbstractControl): ValidationErrors | null {\r\n return rutValidator(control);\r\n }\r\n}\r\n","\r\nimport { Directive, forwardRef, ElementRef, Renderer2, HostListener } from '@angular/core';\r\nimport { rutFormat, rutClean } from '../helpers/rut-helpers';\r\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\r\n\r\nconst RUT_VALUE_ACCESSOR: any = {\r\n provide: NG_VALUE_ACCESSOR,\r\n useExisting: forwardRef(() => RutValueAccessor),\r\n multi: true,\r\n};\r\n\r\n@Directive({\r\n selector: 'input[formatRut]',\r\n standalone: true,\r\n providers: [RUT_VALUE_ACCESSOR],\r\n})\r\nexport class RutValueAccessor implements ControlValueAccessor {\r\n private onChange: (value: any) => void = () => {};\r\n private onTouched: () => void = () => {};\r\n\r\n constructor(\r\n private readonly renderer: Renderer2,\r\n private readonly elementRef: ElementRef,\r\n ) {}\r\n\r\n\r\n @HostListener('input', ['$event.target'])\r\n onInput(input: HTMLInputElement) {\r\n const rawValue = input.value;\r\n const cleaned = rutClean(rawValue);\r\n const formatted = rutFormat(cleaned);\r\n // Set the formatted value visually\r\n this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatted);\r\n // Emit the cleaned value to the form\r\n this.onChange(cleaned);\r\n }\r\n\r\n\r\n @HostListener('blur')\r\n onBlur() {\r\n this.onTouched();\r\n }\r\n\r\n writeValue(value: any): void {\r\n const formatted = rutFormat(value) || '';\r\n this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatted);\r\n }\r\n\r\n registerOnChange(fn: (_: any) => void): void {\r\n this.onChange = fn;\r\n }\r\n\r\n registerOnTouched(fn: () => void): void {\r\n this.onTouched = fn;\r\n }\r\n\r\n setDisabledState(isDisabled: boolean): void {\r\n this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);\r\n }\r\n}\r\n","import { Directive, HostListener } from '@angular/core';\r\nimport { rutClean, rutFormat } from '../helpers/rut-helpers';\r\n\r\n@Directive({\r\n selector: '[formatRut]',\r\n standalone: true\r\n})\r\nexport class RutDirective {\r\n @HostListener('focus', ['$event.target'])\r\n onFocus(input: HTMLInputElement) {\r\n input.value = rutClean(input.value);\r\n }\r\n\r\n @HostListener('blur', ['$event.target'])\r\n onBlur(input: HTMLInputElement) {\r\n input.value = rutFormat(input.value) || '';\r\n }\r\n}\r\n","import { Pipe, PipeTransform } from '@angular/core';\r\nimport { rutFormat } from '../helpers/rut-helpers';\r\n\r\n@Pipe({\r\n name: 'rut',\r\n standalone: true\r\n})\r\nexport class RutPipe implements PipeTransform {\r\n public transform(value: string): string {\r\n return rutFormat(value);\r\n }\r\n}\r\n","/*\r\n * Public API Surface of ngx-rut-v2\r\n */\r\n\r\nexport * from './lib/helpers/rut-helpers';\r\nexport * from './lib/directives/rut-validator.directive';\r\nexport * from './lib/directives/rut-value-accessor.directive';\r\nexport * from './lib/directives/rut.directive';\r\nexport * from './lib/pipes/rut.pipe';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public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a,EAAA;AAC5B,QAAA,OAAO,SAAS,CAAC,KAAK,CAAC;;wGAFd,OAAO,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA;sGAAP,OAAO,EAAA,YAAA,EAAA,IAAA,EAAA,IAAA,EAAA,KAAA,EAAA,CAAA;;4FAAP,OAAO,EAAA,UAAA,EAAA,CAAA;kBAJnB,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA;AACJ,oBAAA,IAAI,EAAE,KAAK;AACX,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACND;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngx-rut-v2.mjs","sources":["../../../projects/ngx-rut-v2/src/lib/helpers/rut-helpers.ts","../../../projects/ngx-rut-v2/src/lib/directives/rut-validator.directive.ts","../../../projects/ngx-rut-v2/src/lib/directives/rut-value-accessor.directive.ts","../../../projects/ngx-rut-v2/src/lib/directives/rut.directive.ts","../../../projects/ngx-rut-v2/src/lib/pipes/rut.pipe.ts","../../../projects/ngx-rut-v2/src/public-api.ts","../../../projects/ngx-rut-v2/src/ngx-rut-v2.ts"],"sourcesContent":["/**\n *\n * @param value The RUT string to clean.\n * @description Cleans a RUT (Rol Único Tributario) string by removing non-numeric characters and leading zeros.\n * Converts the RUT to uppercase and returns it.\n * @returns The cleaned RUT string.\n */\nexport function rutClean(value: string): string {\n if (typeof value === 'string') {\n return value\n .replace(/[^0-9kK]+/g, '')\n .replace(/^0+/, '')\n .toUpperCase();\n }\n return '';\n}\n\n/**\n * @param value The RUT string to validate.\n * @description Validates a RUT (Rol Único Tributario) string.\n * @returns True if the RUT is valid, false otherwise.\n */\nexport function rutValidate(value: string): boolean {\n if (typeof value !== 'string') {\n return false;\n }\n\n const rut: string = rutClean(value);\n if (rut.length < 2) {\n return false;\n }\n\n const body: string = rut.slice(0, -1);\n const dv: string = rut.slice(-1).toUpperCase();\n\n let sum = 0;\n let multiplier = 2;\n\n for (let i = body.length - 1; i >= 0; i--) {\n sum += parseInt(body.charAt(i), 10) * multiplier;\n multiplier = multiplier === 7 ? 2 : multiplier + 1;\n }\n\n const expectedDv = 11 - (sum % 11);\n let expectedDvStr = '';\n\n if (expectedDv === 11) {\n expectedDvStr = '0';\n } else if (expectedDv === 10) {\n expectedDvStr = 'K';\n } else {\n expectedDvStr = expectedDv.toString();\n }\n\n return dv === expectedDvStr;\n}\n\n/**\n * Formats a RUT (Rol Único Tributario) string.\n * @param value The RUT string to format.\n * @returns The formatted RUT string.\n */\nexport function rutFormat(value: string): string {\n const rut: string = rutClean(value);\n\n if (rut.length <= 1) {\n return rut;\n }\n\n let result: string = `${rut.slice(-4, -1)}-${rut.slice(-1)}`;\n for (let i: number = 4; i < rut.length; i += 3) {\n result = `${rut.slice(-3 - i, -i)}.${result}`;\n }\n\n return result;\n}\n","import { Directive, forwardRef } from '@angular/core';\nimport { AbstractControl, NG_VALIDATORS, ValidationErrors, Validator, ValidatorFn } from '@angular/forms';\nimport { rutValidate } from '../helpers/rut-helpers';\n\n// Single reusable ValidatorFn\nexport const rutValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {\n const value = control.value;\n if (!value) {\n return null;\n }\n return rutValidate(value) ? null : { invalidRut: true };\n};\n\n@Directive({\n selector: '[validateRut][ngModel],[validateRut][formControl]',\n providers: [\n { provide: NG_VALIDATORS, useExisting: forwardRef(() => RutValidator), multi: true },\n ]\n})\nexport class RutValidator implements Validator {\n validate(control: AbstractControl): ValidationErrors | null {\n return rutValidator(control);\n }\n}\n","\nimport { Directive, forwardRef, ElementRef, Renderer2, HostListener } from '@angular/core';\nimport { rutFormat, rutClean } from '../helpers/rut-helpers';\nimport { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';\n\nconst RUT_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => RutValueAccessor),\n multi: true,\n};\n\n@Directive({\n selector: 'input[formatRut]',\n providers: [RUT_VALUE_ACCESSOR],\n})\nexport class RutValueAccessor implements ControlValueAccessor {\n private onChange: (value: any) => void = () => {};\n private onTouched: () => void = () => {};\n\n constructor(\n private readonly renderer: Renderer2,\n private readonly elementRef: ElementRef,\n ) {}\n\n @HostListener('input', ['$event'])\n onInput(event: Event) {\n const input = event.target as HTMLInputElement;\n const cursorPosition = input.selectionStart || 0;\n const previousValue = input.value;\n\n // Get the raw value and clean it (only numbers and K)\n const rawValue = input.value.toUpperCase();\n const cleaned = rutClean(rawValue);\n\n // Format the cleaned value for display\n const formatted = rutFormat(cleaned);\n\n // Update the input display with formatted value\n this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatted);\n\n // Send the cleaned (unformatted) value to the form control\n this.onChange(cleaned);\n\n // Adjust cursor position after formatting\n const lengthDiff = formatted.length - previousValue.length;\n const newPosition = cursorPosition + lengthDiff;\n\n // Restore cursor position\n setTimeout(() => {\n input.setSelectionRange(newPosition, newPosition);\n }, 0);\n }\n\n @HostListener('blur')\n onBlur() {\n this.onTouched();\n }\n\n @HostListener('keydown', ['$event'])\n onKeyDown(event: KeyboardEvent) {\n const key = event.key;\n\n // Allow: backspace, delete, tab, escape, enter, arrows, home, end\n if (['Backspace', 'Delete', 'Tab', 'Escape', 'Enter', 'ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(key)) {\n return;\n }\n\n // Allow: Ctrl+A, Ctrl+C, Ctrl+V, Ctrl+X\n if (event.ctrlKey || event.metaKey) {\n return;\n }\n\n // Allow only numbers and K/k\n if (!/^[0-9kK]$/.test(key)) {\n event.preventDefault();\n }\n }\n\n writeValue(value: any): void {\n const formatted = rutFormat(value) || '';\n this.renderer.setProperty(this.elementRef.nativeElement, 'value', formatted);\n }\n\n registerOnChange(fn: (_: any) => void): void {\n this.onChange = fn;\n }\n\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n setDisabledState(isDisabled: boolean): void {\n this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);\n }\n}\n","import { Directive, HostListener } from '@angular/core';\nimport { rutClean, rutFormat } from '../helpers/rut-helpers';\n\n@Directive({\n selector: '[formatRut]'\n})\nexport class RutDirective {\n @HostListener('focus', ['$event'])\n onFocus(event: Event) {\n const input = event.target as HTMLInputElement;\n input.value = rutClean(input.value);\n }\n\n @HostListener('blur', ['$event'])\n onBlur(event: Event) {\n const input = event.target as HTMLInputElement;\n input.value = rutFormat(input.value) || '';\n }\n}\n","import { Pipe, PipeTransform } from '@angular/core';\nimport { rutFormat } from '../helpers/rut-helpers';\n\n@Pipe({\n name: 'rut',\n standalone: true\n})\nexport class RutPipe implements PipeTransform {\n public transform(value: string): string {\n return rutFormat(value);\n }\n}\n","/*\n * Public API Surface of ngx-rut-v2\n */\n\nexport * from './lib/helpers/rut-helpers';\nexport * from './lib/directives/rut-validator.directive';\nexport * from './lib/directives/rut-value-accessor.directive';\nexport * from './lib/directives/rut.directive';\nexport * from './lib/pipes/rut.pipe';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAAA;;;;;;AAMG;AACG,SAAU,QAAQ,CAAC,KAAa,EAAA;AACpC,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO;AACJ,aAAA,OAAO,CAAC,YAAY,EAAE,EAAE;AACxB,aAAA,OAAO,CAAC,KAAK,EAAE,EAAE;AACjB,aAAA,WAAW,EAAE;IAClB;AACA,IAAA,OAAO,EAAE;AACX;AAEA;;;;AAIG;AACG,SAAU,WAAW,CAAC,KAAa,EAAA;AACvC,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,MAAM,GAAG,GAAW,QAAQ,CAAC,KAAK,CAAC;AACnC,IAAA,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;AAClB,QAAA,OAAO,KAAK;IACd;IAEA,MAAM,IAAI,G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AA,EAAA,iBAAA,EAAA,MAAA,EAAA,gBAAA,EAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA;;2FAAZ,YAAY,EAAA,UAAA,EAAA,CAAA;kBAHxB,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE;AACX,iBAAA;;sBAEE,YAAY;uBAAC,OAAO,EAAE,CAAC,QAAQ,CAAC;;sBAMhC,YAAY;uBAAC,MAAM,EAAE,CAAC,QAAQ,CAAC;;;MCNrB,OAAO,CAAA;AACX,IAAA,SAAS,CAAC,KAAa,EAAA;AAC5B,QAAA,OAAO,SAAS,CAAC,KAAK,CAAC;IACzB;uGAHW,OAAO,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA;qGAAP,OAAO,EAAA,YAAA,EAAA,IAAA,EAAA,IAAA,EAAA,KAAA,EAAA,CAAA;;2FAAP,OAAO,EAAA,UAAA,EAAA,CAAA;kBAJnB,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA;AACJ,oBAAA,IAAI,EAAE,KAAK;AACX,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACND;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-rut-v2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Daniel Díaz Astudillo"
|
|
@@ -8,24 +8,24 @@
|
|
|
8
8
|
"description": "Angular library to format and validate RUT (Rol Único Tributario) from Chile",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/danieldiazastudillo/ngx-rut-v2"
|
|
11
|
+
"url": "git+https://github.com/danieldiazastudillo/ngx-rut-v2.git"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@angular/common": "
|
|
15
|
-
"@angular/core": "
|
|
14
|
+
"@angular/common": ">=20.0.0 <22.0.0",
|
|
15
|
+
"@angular/core": ">=20.0.0 <22.0.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"tslib": "^2.8.1"
|
|
19
19
|
},
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"module": "fesm2022/ngx-rut-v2.mjs",
|
|
22
|
-
"typings": "
|
|
22
|
+
"typings": "types/ngx-rut-v2.d.ts",
|
|
23
23
|
"exports": {
|
|
24
24
|
"./package.json": {
|
|
25
25
|
"default": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
".": {
|
|
28
|
-
"types": "./
|
|
28
|
+
"types": "./types/ngx-rut-v2.d.ts",
|
|
29
29
|
"default": "./fesm2022/ngx-rut-v2.mjs"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ValidatorFn, Validator, AbstractControl, ValidationErrors, ControlValueAccessor } from '@angular/forms';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { Renderer2, ElementRef, PipeTransform } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param value The RUT string to clean.
|
|
8
|
+
* @description Cleans a RUT (Rol Único Tributario) string by removing non-numeric characters and leading zeros.
|
|
9
|
+
* Converts the RUT to uppercase and returns it.
|
|
10
|
+
* @returns The cleaned RUT string.
|
|
11
|
+
*/
|
|
12
|
+
declare function rutClean(value: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* @param value The RUT string to validate.
|
|
15
|
+
* @description Validates a RUT (Rol Único Tributario) string.
|
|
16
|
+
* @returns True if the RUT is valid, false otherwise.
|
|
17
|
+
*/
|
|
18
|
+
declare function rutValidate(value: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Formats a RUT (Rol Único Tributario) string.
|
|
21
|
+
* @param value The RUT string to format.
|
|
22
|
+
* @returns The formatted RUT string.
|
|
23
|
+
*/
|
|
24
|
+
declare function rutFormat(value: string): string;
|
|
25
|
+
|
|
26
|
+
declare const rutValidator: ValidatorFn;
|
|
27
|
+
declare class RutValidator implements Validator {
|
|
28
|
+
validate(control: AbstractControl): ValidationErrors | null;
|
|
29
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RutValidator, never>;
|
|
30
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RutValidator, "[validateRut][ngModel],[validateRut][formControl]", never, {}, {}, never, never, true, never>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare class RutValueAccessor implements ControlValueAccessor {
|
|
34
|
+
private readonly renderer;
|
|
35
|
+
private readonly elementRef;
|
|
36
|
+
private onChange;
|
|
37
|
+
private onTouched;
|
|
38
|
+
constructor(renderer: Renderer2, elementRef: ElementRef);
|
|
39
|
+
onInput(event: Event): void;
|
|
40
|
+
onBlur(): void;
|
|
41
|
+
onKeyDown(event: KeyboardEvent): void;
|
|
42
|
+
writeValue(value: any): void;
|
|
43
|
+
registerOnChange(fn: (_: any) => void): void;
|
|
44
|
+
registerOnTouched(fn: () => void): void;
|
|
45
|
+
setDisabledState(isDisabled: boolean): void;
|
|
46
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RutValueAccessor, never>;
|
|
47
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RutValueAccessor, "input[formatRut]", never, {}, {}, never, never, true, never>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class RutDirective {
|
|
51
|
+
onFocus(event: Event): void;
|
|
52
|
+
onBlur(event: Event): void;
|
|
53
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RutDirective, never>;
|
|
54
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<RutDirective, "[formatRut]", never, {}, {}, never, never, true, never>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare class RutPipe implements PipeTransform {
|
|
58
|
+
transform(value: string): string;
|
|
59
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<RutPipe, never>;
|
|
60
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<RutPipe, "rut", true>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { RutDirective, RutPipe, RutValidator, RutValueAccessor, rutClean, rutFormat, rutValidate, rutValidator };
|
package/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AbstractControl, ValidationErrors, Validator, ValidatorFn } from '@angular/forms';
|
|
2
|
-
import * as i0 from "@angular/core";
|
|
3
|
-
export declare const rutValidator: ValidatorFn;
|
|
4
|
-
export declare class RutValidator implements Validator {
|
|
5
|
-
validate(control: AbstractControl): ValidationErrors | null;
|
|
6
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RutValidator, never>;
|
|
7
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<RutValidator, "[validateRut][ngModel],[validateRut][formControl]", never, {}, {}, never, never, true, never>;
|
|
8
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ElementRef, Renderer2 } from '@angular/core';
|
|
2
|
-
import { ControlValueAccessor } from '@angular/forms';
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
export declare class RutValueAccessor implements ControlValueAccessor {
|
|
5
|
-
private readonly renderer;
|
|
6
|
-
private readonly elementRef;
|
|
7
|
-
private onChange;
|
|
8
|
-
private onTouched;
|
|
9
|
-
constructor(renderer: Renderer2, elementRef: ElementRef);
|
|
10
|
-
onInput(input: HTMLInputElement): void;
|
|
11
|
-
onBlur(): void;
|
|
12
|
-
writeValue(value: any): void;
|
|
13
|
-
registerOnChange(fn: (_: any) => void): void;
|
|
14
|
-
registerOnTouched(fn: () => void): void;
|
|
15
|
-
setDisabledState(isDisabled: boolean): void;
|
|
16
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RutValueAccessor, never>;
|
|
17
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<RutValueAccessor, "input[formatRut]", never, {}, {}, never, never, true, never>;
|
|
18
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as i0 from "@angular/core";
|
|
2
|
-
export declare class RutDirective {
|
|
3
|
-
onFocus(input: HTMLInputElement): void;
|
|
4
|
-
onBlur(input: HTMLInputElement): void;
|
|
5
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RutDirective, never>;
|
|
6
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<RutDirective, "[formatRut]", never, {}, {}, never, never, true, never>;
|
|
7
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param value The RUT string to clean.
|
|
4
|
-
* @description Cleans a RUT (Rol Único Tributario) string by removing non-numeric characters and leading zeros.
|
|
5
|
-
* Converts the RUT to uppercase and returns it.
|
|
6
|
-
* @returns The cleaned RUT string.
|
|
7
|
-
*/
|
|
8
|
-
export declare function rutClean(value: string): string;
|
|
9
|
-
/**
|
|
10
|
-
* @param value The RUT string to validate.
|
|
11
|
-
* @description Validates a RUT (Rol Único Tributario) string.
|
|
12
|
-
* @returns True if the RUT is valid, false otherwise.
|
|
13
|
-
*/
|
|
14
|
-
export declare function rutValidate(value: string): boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Formats a RUT (Rol Único Tributario) string.
|
|
17
|
-
* @param value The RUT string to format.
|
|
18
|
-
* @returns The formatted RUT string.
|
|
19
|
-
*/
|
|
20
|
-
export declare function rutFormat(value: string): string;
|
package/lib/pipes/rut.pipe.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { PipeTransform } from '@angular/core';
|
|
2
|
-
import * as i0 from "@angular/core";
|
|
3
|
-
export declare class RutPipe implements PipeTransform {
|
|
4
|
-
transform(value: string): string;
|
|
5
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<RutPipe, never>;
|
|
6
|
-
static ɵpipe: i0.ɵɵPipeDeclaration<RutPipe, "rut", true>;
|
|
7
|
-
}
|
package/public-api.d.ts
DELETED