@smartsoft001/utils 2.45.0 → 2.47.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/.eslintrc.json
CHANGED
package/package.json
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
export class NipService {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return false;
|
|
2
|
+
/***
|
|
3
|
+
* Check valid nip format
|
|
4
|
+
* @param nip {string} - nip string
|
|
5
|
+
* @return return true when correct
|
|
6
|
+
*/
|
|
7
|
+
static isValid(nip: string): boolean {
|
|
8
|
+
if (typeof nip !== 'string') return false;
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
//eslint-disable-next-line
|
|
12
11
|
nip = nip.replace(/[\ \-]/gi, '');
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return sum % 11 === controlNumber;
|
|
13
|
+
const weight = [6, 5, 7, 2, 3, 4, 5, 6, 7];
|
|
14
|
+
let sum = 0;
|
|
15
|
+
// tslint:disable-next-line:radix
|
|
16
|
+
const controlNumber = parseInt(nip.substring(9, 10));
|
|
17
|
+
const weightCount = weight.length;
|
|
18
|
+
for (let i = 0; i < weightCount; i++) {
|
|
19
|
+
// tslint:disable-next-line:radix
|
|
20
|
+
sum += parseInt(nip.substr(i, 1)) * weight[i];
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
return sum % 11 === controlNumber;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/***
|
|
27
|
+
* Check invalid nip format
|
|
28
|
+
* @param nip {string} - nip string
|
|
29
|
+
* @return return true when incorrect
|
|
30
|
+
*/
|
|
31
|
+
static isInvalid(nip: string): boolean {
|
|
32
|
+
return !NipService.isValid(nip);
|
|
33
|
+
}
|
|
35
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ObjectService } from './object.service';
|
|
2
1
|
import { isNull } from 'util';
|
|
3
2
|
|
|
3
|
+
import { ObjectService } from './object.service';
|
|
4
|
+
|
|
4
5
|
describe('shared-utils: ObjectService', () => {
|
|
5
6
|
describe('createByType()', () => {
|
|
6
7
|
it('should return same object when exist same type', () => {
|
|
@@ -14,7 +14,7 @@ export class SpecificationService {
|
|
|
14
14
|
static valid<T>(
|
|
15
15
|
value: T,
|
|
16
16
|
spec: { criteria: any },
|
|
17
|
-
custom?: ISpecificationCustom
|
|
17
|
+
custom?: ISpecificationCustom,
|
|
18
18
|
): boolean {
|
|
19
19
|
const keys = Object.keys(spec.criteria);
|
|
20
20
|
|
|
@@ -27,7 +27,7 @@ export class SpecificationService {
|
|
|
27
27
|
if (
|
|
28
28
|
!SpecificationService.check(
|
|
29
29
|
custom?.$root[key.replace(SPECIFICATION_ROOT_KEY, '')],
|
|
30
|
-
spec.criteria[key]
|
|
30
|
+
spec.criteria[key],
|
|
31
31
|
)
|
|
32
32
|
)
|
|
33
33
|
return false;
|
|
@@ -49,7 +49,7 @@ export class SpecificationService {
|
|
|
49
49
|
static invalid<T>(
|
|
50
50
|
value: T,
|
|
51
51
|
spec: { criteria: any },
|
|
52
|
-
custom?: ISpecificationCustom
|
|
52
|
+
custom?: ISpecificationCustom,
|
|
53
53
|
): boolean {
|
|
54
54
|
return !SpecificationService.valid(value, spec, custom);
|
|
55
55
|
}
|