@kigi/components 1.8.4 → 1.8.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kigi/components",
3
- "version": "1.8.4",
3
+ "version": "1.8.6",
4
4
  "description": "@kigi/components",
5
5
  "main": "src/components/index.ts",
6
6
  "scripts": {
@@ -1,7 +1,7 @@
1
1
  <div class="mbg-input-wrapper mbg-input-name-wrapper"
2
2
  ng-if="$ctrl.props">
3
3
  <input type="text"
4
- ng-if="$ctrl.state == 'TO' || $ctrl.state == 'MT'"
4
+ ng-if="$ctrl.state == 'TO' || $ctrl.state == 'MT' || $ctrl.state == 'AL'"
5
5
  mbg-mask-ie
6
6
  ng-model="$ctrl.ngModel"
7
7
  name="{{$ctrl.name}}"
@@ -17,7 +17,7 @@
17
17
  placeholder="{{ $ctrl.props.placeholder }}" />
18
18
 
19
19
  <input type="text"
20
- ng-if="!$ctrl.state || ($ctrl.state != 'TO' && $ctrl.state != 'MT')"
20
+ ng-if="!$ctrl.state || ($ctrl.state != 'TO' && $ctrl.state != 'MT' && $ctrl.state != 'AL')"
21
21
  ng-model="$ctrl.ngModel"
22
22
  name="{{$ctrl.name}}"
23
23
  ng-init="$ctrl.onInit()"
@@ -8,6 +8,7 @@ export class NgMaskIe {
8
8
  private $timeout
9
9
  private $parse
10
10
  private uid: string = UtilUID.generete()
11
+ private ordZero = '0'.charCodeAt(0)
11
12
 
12
13
  constructor() {
13
14
  this.restrict = 'A'
@@ -25,12 +26,12 @@ export class NgMaskIe {
25
26
  scope.$parent && scope.$parent.$parent && scope.$parent.$parent.$ctrl
26
27
  ? scope.$parent.$parent.$ctrl.state
27
28
  : null
28
- const valid = this.validade(data, state)
29
+ const valid = this.validate(data, state)
29
30
  const form = elm.closest('form')
30
31
  const formName = form.attr('name')
31
32
  const formScope = form.scope()
32
33
  if (formName && formScope) {
33
- this.setIeValidade(elm, valid)
34
+ this.setIeValidate(elm, valid)
34
35
  if (!valid) {
35
36
  elm.addClass('mbg-error')
36
37
  } else {
@@ -65,43 +66,74 @@ export class NgMaskIe {
65
66
  ngModelController.$formatters.push(formatterView)
66
67
 
67
68
  scope.$on('$destroy', () => {
68
- this.setIeValidade(elm, true)
69
+ this.setIeValidate(elm, true)
69
70
  })
70
71
  }
71
72
 
72
- validade(ngModel, state) {
73
+ validate(ngModel, state) {
73
74
  switch (state) {
74
75
  case 'TO':
75
- if (ngModel && (ngModel.length === 11 || ngModel.length === 9)) {
76
- const digit = ngModel[ngModel.length - 1]
77
- let total = 0
78
- let indexCalc = 0
79
- for (let index = 9; index >= 2; index--) {
80
- total += ngModel[indexCalc] * index
81
- if (ngModel.length === 11 && indexCalc === 1) {
82
- indexCalc = indexCalc + 3
83
- } else {
84
- indexCalc++
85
- }
86
- }
87
- const result = total - Math.floor(total / 11) * 11
88
- if (result < 2) {
89
- return Number(digit) === 0
90
- } else {
91
- return Number(digit) === 11 - result
92
- }
76
+ return this.validateTO(ngModel)
77
+ case 'MT':
78
+ return this.validateMT(ngModel)
79
+ case 'AL':
80
+ return this.validateAL(ngModel)
81
+ }
82
+ }
83
+
84
+ charToInt(ch) {
85
+ return ch.charCodeAt(0) - this.ordZero
86
+ }
87
+
88
+ intToChar(int) {
89
+ return String.fromCharCode(int + this.ordZero)
90
+ }
91
+
92
+ validateAL(ie) {
93
+ let dig = -1
94
+ if (ie.length != 9) return false
95
+ var b = 9,
96
+ soma = 0
97
+ for (var i = 0; i <= 7; i++) {
98
+ soma += this.charToInt(ie.charAt(i)) * b
99
+ --b
100
+ }
101
+ soma *= 10
102
+ dig = soma - Math.floor(soma / 11) * 11
103
+ if (dig == 10) {
104
+ dig = 0
105
+ }
106
+ return this.intToChar(dig) == ie.charAt(8)
107
+ }
108
+
109
+ validateTO(ngModel) {
110
+ if (ngModel && (ngModel.length === 11 || ngModel.length === 9)) {
111
+ const digit = ngModel[ngModel.length - 1]
112
+ let total = 0
113
+ let indexCalc = 0
114
+ for (let index = 9; index >= 2; index--) {
115
+ total += ngModel[indexCalc] * index
116
+ if (ngModel.length === 11 && indexCalc === 1) {
117
+ indexCalc = indexCalc + 3
93
118
  } else {
94
- return false
119
+ indexCalc++
95
120
  }
96
- case 'MT':
97
- return this.validadeMT(ngModel)
121
+ }
122
+ const result = total - Math.floor(total / 11) * 11
123
+ if (result < 2) {
124
+ return Number(digit) === 0
125
+ } else {
126
+ return Number(digit) === 11 - result
127
+ }
128
+ } else {
129
+ return false
98
130
  }
99
131
  }
100
132
 
101
- validadeMT(model, plusZero = '') {
133
+ validateMT(model, plusZero = '') {
102
134
  const lengthZero = plusZero.length
103
135
  model = `${plusZero}${model}`
104
- if (model.length != 11 && lengthZero < 2) return this.validadeMT(model, `0`)
136
+ if (model.length != 11 && lengthZero < 2) return this.validateMT(model, `0`)
105
137
  var nro = new Array(11)
106
138
  for (var i = 0; i <= 10; i++) nro[i] = parseInt(model[i])
107
139
  let b = 3
@@ -121,7 +153,7 @@ export class NgMaskIe {
121
153
  return dig == nro[10]
122
154
  }
123
155
 
124
- setIeValidade(elm, valid) {
156
+ setIeValidate(elm, valid) {
125
157
  const form = elm.closest('form')
126
158
  const formName = form.attr('name')
127
159
  const formScope = form.scope()