@luftborn/custom-elements 1.4.0 → 2.0.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.
Files changed (196) hide show
  1. package/README.md +2 -2
  2. package/assets/style.css +277 -277
  3. package/azure-pipeline.yml +54 -0
  4. package/demo/index.html +585 -585
  5. package/demo/index.js +6109 -0
  6. package/demo/index.min.js +6110 -0
  7. package/demo/index.min.js.map +1 -0
  8. package/demo/index.ts +11 -11
  9. package/demo/old/index.html +586 -586
  10. package/demo/old/index.js +10849 -10849
  11. package/demo/old/index.min.js +10850 -10850
  12. package/demo/old/index.ts +10 -10
  13. package/dist/custom-form.d.ts +20 -20
  14. package/dist/custom-form.js +147 -147
  15. package/dist/elements/Address/AddressElement.d.ts +28 -28
  16. package/dist/elements/Address/AddressElement.js +206 -206
  17. package/dist/elements/BankField/BankFieldElement.d.ts +22 -22
  18. package/dist/elements/BankField/BankFieldElement.js +127 -127
  19. package/dist/elements/CPRElement/CPRElement.d.ts +14 -14
  20. package/dist/elements/CPRElement/CPRElement.js +82 -82
  21. package/dist/elements/CVRElement/CVRElement.d.ts +14 -14
  22. package/dist/elements/CVRElement/CVRElement.js +82 -82
  23. package/dist/elements/CheckBoxElement/CheckBoxElement.d.ts +14 -14
  24. package/dist/elements/CheckBoxElement/CheckBoxElement.js +96 -96
  25. package/dist/elements/CustomRegularExpression/CustomRegularExpressionElement.d.ts +12 -12
  26. package/dist/elements/CustomRegularExpression/CustomRegularExpressionElement.js +82 -82
  27. package/dist/elements/DateField/DateFieldElement.d.ts +12 -12
  28. package/dist/elements/DateField/DateFieldElement.js +85 -85
  29. package/dist/elements/DropDownList/DropDownListElement.d.ts +14 -14
  30. package/dist/elements/DropDownList/DropDownListElement.js +93 -93
  31. package/dist/elements/Elements.d.ts +18 -18
  32. package/dist/elements/Elements.js +37 -37
  33. package/dist/elements/EmailField/EmailFieldElement.d.ts +13 -13
  34. package/dist/elements/EmailField/EmailFieldElement.js +83 -83
  35. package/dist/elements/FileField/FileFieldElement.d.ts +15 -15
  36. package/dist/elements/FileField/FileFieldElement.js +103 -103
  37. package/dist/elements/IdentificationElement/IdentificationElement.d.ts +18 -18
  38. package/dist/elements/IdentificationElement/IdentificationElement.js +94 -94
  39. package/dist/elements/InternationaPhoneNumber/InternationaPhoneNumberElement.d.ts +16 -16
  40. package/dist/elements/InternationaPhoneNumber/InternationaPhoneNumberElement.js +114 -114
  41. package/dist/elements/NumericField/NumericFieldElement.d.ts +12 -12
  42. package/dist/elements/NumericField/NumericFieldElement.js +91 -91
  43. package/dist/elements/RadioButtonGroup/RadioButtonGroupElement.d.ts +14 -14
  44. package/dist/elements/RadioButtonGroup/RadioButtonGroupElement.js +99 -99
  45. package/dist/elements/TextAreaElement/TextAreaElement.d.ts +12 -12
  46. package/dist/elements/TextAreaElement/TextAreaElement.js +79 -79
  47. package/dist/elements/TextField/TextFieldElement.d.ts +12 -12
  48. package/dist/elements/TextField/TextFieldElement.js +79 -79
  49. package/dist/elements/TypeAhead/TypeAheadElement.d.ts +24 -24
  50. package/dist/elements/TypeAhead/TypeAheadElement.js +209 -209
  51. package/dist/framework/CustomEvents.d.ts +21 -21
  52. package/dist/framework/CustomEvents.js +47 -47
  53. package/dist/framework/CustomInputElement.d.ts +50 -50
  54. package/dist/framework/CustomInputElement.js +258 -258
  55. package/dist/framework/Language/Languages/Base/BaseDictionary.d.ts +4 -4
  56. package/dist/framework/Language/Languages/Base/BaseDictionary.js +20 -20
  57. package/dist/framework/Language/Languages/CzechDictionary.d.ts +4 -4
  58. package/dist/framework/Language/Languages/CzechDictionary.js +39 -39
  59. package/dist/framework/Language/Languages/DanishDictionary.d.ts +4 -4
  60. package/dist/framework/Language/Languages/DanishDictionary.js +39 -39
  61. package/dist/framework/Language/Languages/DutchDictionary.d.ts +4 -4
  62. package/dist/framework/Language/Languages/DutchDictionary.js +39 -39
  63. package/dist/framework/Language/Languages/EnglishDictionary.d.ts +4 -4
  64. package/dist/framework/Language/Languages/EnglishDictionary.js +39 -39
  65. package/dist/framework/Language/Languages/EstonianDictionary.d.ts +4 -4
  66. package/dist/framework/Language/Languages/EstonianDictionary.js +39 -39
  67. package/dist/framework/Language/Languages/FinnishDictionary.d.ts +4 -4
  68. package/dist/framework/Language/Languages/FinnishDictionary.js +39 -39
  69. package/dist/framework/Language/Languages/FrenchDictionary.d.ts +4 -4
  70. package/dist/framework/Language/Languages/FrenchDictionary.js +39 -39
  71. package/dist/framework/Language/Languages/GermanDictionary.d.ts +4 -4
  72. package/dist/framework/Language/Languages/GermanDictionary.js +39 -39
  73. package/dist/framework/Language/Languages/GreekDictionary.d.ts +4 -4
  74. package/dist/framework/Language/Languages/GreekDictionary.js +39 -39
  75. package/dist/framework/Language/Languages/HungarianDictionary.d.ts +4 -4
  76. package/dist/framework/Language/Languages/HungarianDictionary.js +39 -39
  77. package/dist/framework/Language/Languages/IcelandicDictionary.d.ts +4 -4
  78. package/dist/framework/Language/Languages/IcelandicDictionary.js +39 -39
  79. package/dist/framework/Language/Languages/ItalianDictionary.d.ts +4 -4
  80. package/dist/framework/Language/Languages/ItalianDictionary.js +39 -39
  81. package/dist/framework/Language/Languages/LatvianDictionary.d.ts +4 -4
  82. package/dist/framework/Language/Languages/LatvianDictionary.js +39 -39
  83. package/dist/framework/Language/Languages/LituanianDictionary.d.ts +4 -4
  84. package/dist/framework/Language/Languages/LituanianDictionary.js +39 -39
  85. package/dist/framework/Language/Languages/NorwegianDictionary.d.ts +4 -4
  86. package/dist/framework/Language/Languages/NorwegianDictionary.js +39 -39
  87. package/dist/framework/Language/Languages/PolishDictionary.d.ts +4 -4
  88. package/dist/framework/Language/Languages/PolishDictionary.js +39 -39
  89. package/dist/framework/Language/Languages/PortugueseDictionary.d.ts +4 -4
  90. package/dist/framework/Language/Languages/PortugueseDictionary.js +39 -39
  91. package/dist/framework/Language/Languages/SpanishDictionary.d.ts +4 -4
  92. package/dist/framework/Language/Languages/SpanishDictionary.js +39 -39
  93. package/dist/framework/Language/Languages/SwedishDictionary.d.ts +4 -4
  94. package/dist/framework/Language/Languages/SwedishDictionary.js +39 -39
  95. package/dist/framework/Language/Translator.d.ts +23 -23
  96. package/dist/framework/Language/Translator.js +115 -115
  97. package/dist/framework/Models/OptionWithDescription.d.ts +6 -6
  98. package/dist/framework/Models/OptionWithDescription.js +9 -9
  99. package/dist/framework/Polyfills/getAttributeNamesPolyfill.d.ts +1 -1
  100. package/dist/framework/Polyfills/getAttributeNamesPolyfill.js +17 -17
  101. package/dist/framework/Translations/CaseConverter.d.ts +5 -5
  102. package/dist/framework/Translations/CaseConverter.js +50 -50
  103. package/dist/framework/Utilities/ArrayUtil.d.ts +6 -6
  104. package/dist/framework/Utilities/ArrayUtil.js +36 -36
  105. package/dist/framework/Utilities/DomUtil.d.ts +21 -21
  106. package/dist/framework/Utilities/DomUtil.js +101 -101
  107. package/dist/framework/Utilities/DomUtility.d.ts +3 -3
  108. package/dist/framework/Utilities/DomUtility.js +12 -12
  109. package/dist/framework/Utilities/MakeRequest.d.ts +8 -8
  110. package/dist/framework/Utilities/MakeRequest.js +48 -48
  111. package/dist/framework/Utilities/StringUtil.d.ts +4 -4
  112. package/dist/framework/Utilities/StringUtil.js +16 -16
  113. package/dist/framework/Utilities/ViewportUtil.d.ts +8 -8
  114. package/dist/framework/Utilities/ViewportUtil.js +42 -42
  115. package/dist/framework/Utilities/debouncer.d.ts +8 -8
  116. package/dist/framework/Utilities/debouncer.js +51 -51
  117. package/dist/framework/Validation/IValidator.interface.d.ts +3 -3
  118. package/dist/framework/Validation/IValidator.interface.js +2 -2
  119. package/dist/framework/Validation/Validators/BankAccount.d.ts +4 -4
  120. package/dist/framework/Validation/Validators/BankAccount.js +12 -12
  121. package/dist/framework/Validation/Validators/BankAccountRegistrationNumber.d.ts +4 -4
  122. package/dist/framework/Validation/Validators/BankAccountRegistrationNumber.js +12 -12
  123. package/dist/framework/Validation/Validators/BankIdNorway.d.ts +5 -5
  124. package/dist/framework/Validation/Validators/BankIdNorway.js +21 -21
  125. package/dist/framework/Validation/Validators/BankIdSweden.d.ts +5 -5
  126. package/dist/framework/Validation/Validators/BankIdSweden.js +21 -21
  127. package/dist/framework/Validation/Validators/CPR.d.ts +9 -9
  128. package/dist/framework/Validation/Validators/CPR.js +75 -75
  129. package/dist/framework/Validation/Validators/CVR.d.ts +5 -5
  130. package/dist/framework/Validation/Validators/CVR.js +30 -30
  131. package/dist/framework/custom-element.decorator.d.ts +9 -9
  132. package/dist/framework/custom-element.decorator.js +51 -51
  133. package/dist/index.d.ts +7 -7
  134. package/dist/index.js +14 -14
  135. package/package.json +38 -38
  136. package/src/custom-form.ts +140 -140
  137. package/src/elements/Address/AddressElement.ts +216 -216
  138. package/src/elements/BankField/BankFieldElement.ts +127 -127
  139. package/src/elements/CPRElement/CPRElement.ts +74 -74
  140. package/src/elements/CVRElement/CVRElement.ts +75 -75
  141. package/src/elements/CheckBoxElement/CheckBoxElement.ts +99 -99
  142. package/src/elements/CustomRegularExpression/CustomRegularExpressionElement.ts +75 -75
  143. package/src/elements/DateField/DateFieldElement.ts +78 -78
  144. package/src/elements/DropDownList/DropDownListElement.ts +100 -100
  145. package/src/elements/Elements.ts +37 -37
  146. package/src/elements/EmailField/EmailFieldElement.ts +78 -78
  147. package/src/elements/FileField/FileFieldElement.ts +96 -96
  148. package/src/elements/IdentificationElement/IdentificationElement.ts +104 -104
  149. package/src/elements/InternationaPhoneNumber/InternationaPhoneNumberElement.ts +116 -116
  150. package/src/elements/NumericField/NumericFieldElement.ts +84 -84
  151. package/src/elements/RadioButtonGroup/RadioButtonGroupElement.ts +103 -103
  152. package/src/elements/TextAreaElement/TextAreaElement.ts +72 -72
  153. package/src/elements/TextField/TextFieldElement.ts +72 -72
  154. package/src/elements/TypeAhead/TypeAheadElement.ts +248 -248
  155. package/src/framework/CustomEvents.ts +47 -47
  156. package/src/framework/CustomInputElement.ts +277 -277
  157. package/src/framework/Language/Languages/Base/BaseDictionary.ts +15 -15
  158. package/src/framework/Language/Languages/CzechDictionary.ts +18 -18
  159. package/src/framework/Language/Languages/DanishDictionary.ts +17 -17
  160. package/src/framework/Language/Languages/DutchDictionary.ts +17 -17
  161. package/src/framework/Language/Languages/EnglishDictionary.ts +18 -18
  162. package/src/framework/Language/Languages/EstonianDictionary.ts +17 -17
  163. package/src/framework/Language/Languages/FinnishDictionary.ts +17 -17
  164. package/src/framework/Language/Languages/FrenchDictionary.ts +17 -17
  165. package/src/framework/Language/Languages/GermanDictionary.ts +17 -17
  166. package/src/framework/Language/Languages/GreekDictionary.ts +17 -17
  167. package/src/framework/Language/Languages/HungarianDictionary.ts +17 -17
  168. package/src/framework/Language/Languages/IcelandicDictionary.ts +17 -17
  169. package/src/framework/Language/Languages/ItalianDictionary.ts +17 -17
  170. package/src/framework/Language/Languages/LatvianDictionary.ts +17 -17
  171. package/src/framework/Language/Languages/LituanianDictionary.ts +17 -17
  172. package/src/framework/Language/Languages/NorwegianDictionary.ts +17 -17
  173. package/src/framework/Language/Languages/PolishDictionary.ts +17 -17
  174. package/src/framework/Language/Languages/PortugueseDictionary.ts +17 -17
  175. package/src/framework/Language/Languages/SpanishDictionary.ts +17 -17
  176. package/src/framework/Language/Languages/SwedishDictionary.ts +17 -17
  177. package/src/framework/Language/Translator.ts +110 -110
  178. package/src/framework/Models/OptionWithDescription.ts +8 -8
  179. package/src/framework/Polyfills/getAttributeNamesPolyfill.ts +13 -13
  180. package/src/framework/Translations/CaseConverter.ts +43 -43
  181. package/src/framework/Utilities/ArrayUtil.ts +31 -31
  182. package/src/framework/Utilities/DomUtil.ts +117 -117
  183. package/src/framework/Utilities/DomUtility.ts +6 -6
  184. package/src/framework/Utilities/MakeRequest.ts +47 -47
  185. package/src/framework/Utilities/StringUtil.ts +8 -8
  186. package/src/framework/Utilities/ViewportUtil.ts +46 -46
  187. package/src/framework/Utilities/debouncer.ts +66 -66
  188. package/src/framework/Validation/IValidator.interface.ts +3 -3
  189. package/src/framework/Validation/Validators/BankAccount.ts +7 -7
  190. package/src/framework/Validation/Validators/BankAccountRegistrationNumber.ts +8 -8
  191. package/src/framework/Validation/Validators/BankIdNorway.ts +21 -21
  192. package/src/framework/Validation/Validators/BankIdSweden.ts +21 -21
  193. package/src/framework/Validation/Validators/CPR.ts +82 -82
  194. package/src/framework/Validation/Validators/CVR.ts +27 -27
  195. package/src/framework/custom-element.decorator.ts +57 -57
  196. package/src/index.ts +12 -12
@@ -1,47 +1,47 @@
1
- export default class MakeRequest {
2
- method: string;
3
- url: string;
4
- headers: any;
5
-
6
- constructor(url: string, method: string = 'get', headers: any = {}) {
7
- this.method = method;
8
- this.url = url;
9
- this.headers = headers;
10
- }
11
-
12
- private setHeaders(httpRequest: XMLHttpRequest) {
13
- for (const header in this.headers) {
14
- httpRequest.setRequestHeader(header, this.headers[header]);
15
- }
16
- }
17
-
18
- send(data: any = null) {
19
- return new Promise((resolve, reject) => {
20
- const xmlHttpRequest = new XMLHttpRequest();
21
- xmlHttpRequest.open(this.method, this.url);
22
- this.setHeaders(xmlHttpRequest);
23
- xmlHttpRequest.onload = () => {
24
- if (
25
- xmlHttpRequest.status >= 200 &&
26
- xmlHttpRequest.status < 300
27
- ) {
28
- resolve(xmlHttpRequest.response);
29
- } else {
30
- reject({
31
- status: xmlHttpRequest.status,
32
- statusText: xmlHttpRequest.statusText,
33
- body: xmlHttpRequest.response,
34
- });
35
- }
36
- };
37
- xmlHttpRequest.onerror = () => {
38
- reject({
39
- status: xmlHttpRequest.status,
40
- statusText: xmlHttpRequest.statusText,
41
- body: xmlHttpRequest.response,
42
- });
43
- };
44
- xmlHttpRequest.send(data);
45
- });
46
- }
47
- }
1
+ export default class MakeRequest {
2
+ method: string;
3
+ url: string;
4
+ headers: any;
5
+
6
+ constructor(url: string, method: string = 'get', headers: any = {}) {
7
+ this.method = method;
8
+ this.url = url;
9
+ this.headers = headers;
10
+ }
11
+
12
+ private setHeaders(httpRequest: XMLHttpRequest) {
13
+ for (const header in this.headers) {
14
+ httpRequest.setRequestHeader(header, this.headers[header]);
15
+ }
16
+ }
17
+
18
+ send(data: any = null) {
19
+ return new Promise((resolve, reject) => {
20
+ const xmlHttpRequest = new XMLHttpRequest();
21
+ xmlHttpRequest.open(this.method, this.url);
22
+ this.setHeaders(xmlHttpRequest);
23
+ xmlHttpRequest.onload = () => {
24
+ if (
25
+ xmlHttpRequest.status >= 200 &&
26
+ xmlHttpRequest.status < 300
27
+ ) {
28
+ resolve(xmlHttpRequest.response);
29
+ } else {
30
+ reject({
31
+ status: xmlHttpRequest.status,
32
+ statusText: xmlHttpRequest.statusText,
33
+ body: xmlHttpRequest.response,
34
+ });
35
+ }
36
+ };
37
+ xmlHttpRequest.onerror = () => {
38
+ reject({
39
+ status: xmlHttpRequest.status,
40
+ statusText: xmlHttpRequest.statusText,
41
+ body: xmlHttpRequest.response,
42
+ });
43
+ };
44
+ xmlHttpRequest.send(data);
45
+ });
46
+ }
47
+ }
@@ -1,9 +1,9 @@
1
- export class StringUtil {
2
-
3
- constructor() {
4
- }
5
-
6
- public static StringFormat(str: string, ...args: string[]) {
7
- return str.replace(/{(\d+)}/g, (match, index) => args[index] || '');
8
- }
1
+ export class StringUtil {
2
+
3
+ constructor() {
4
+ }
5
+
6
+ public static StringFormat(str: string, ...args: string[]) {
7
+ return str.replace(/{(\d+)}/g, (match, index) => args[index] || '');
8
+ }
9
9
  }
@@ -1,46 +1,46 @@
1
- export class ViewportUtil {
2
- private element?: HTMLElement;
3
- constructor(element: HTMLElement = null) {
4
- this.element = element;
5
- }
6
-
7
- public IsVisible(): boolean {
8
- const bounds = this.element.getBoundingClientRect();
9
- return (
10
- ((bounds.top > 0 && bounds.top < innerHeight) ||
11
- (bounds.bottom > 0 && bounds.bottom < innerHeight)) &&
12
- ((bounds.left > 0 && bounds.left < innerWidth) ||
13
- (bounds.right > 0 && bounds.right < innerWidth))
14
- );
15
- }
16
-
17
- public IsPartiallyVisible() {
18
- const bounds = this.element.getBoundingClientRect();
19
- return (
20
- bounds.top >= 0 ||
21
- bounds.left >= 0 ||
22
- bounds.bottom <= innerHeight ||
23
- bounds.right <= innerWidth
24
- );
25
- }
26
-
27
- public IsOffsetVisible(offset: number = 300) {
28
- const bounds = this.element.getBoundingClientRect();
29
- // tslint:disable-next-line: max-line-length
30
- return (
31
- bounds.top + offset >= 0 ||
32
- bounds.left + offset >= 0 ||
33
- bounds.bottom - offset <= innerHeight ||
34
- bounds.right - offset <= innerWidth
35
- );
36
- }
37
-
38
- public WindowTop(offset: number = 0) {
39
- const YOffset =
40
- window.pageYOffset ||
41
- document.documentElement.scrollTop ||
42
- document.body.scrollTop ||
43
- 0;
44
- return offset <= YOffset;
45
- }
46
- }
1
+ export class ViewportUtil {
2
+ private element?: HTMLElement;
3
+ constructor(element: HTMLElement = null) {
4
+ this.element = element;
5
+ }
6
+
7
+ public IsVisible(): boolean {
8
+ const bounds = this.element.getBoundingClientRect();
9
+ return (
10
+ ((bounds.top > 0 && bounds.top < innerHeight) ||
11
+ (bounds.bottom > 0 && bounds.bottom < innerHeight)) &&
12
+ ((bounds.left > 0 && bounds.left < innerWidth) ||
13
+ (bounds.right > 0 && bounds.right < innerWidth))
14
+ );
15
+ }
16
+
17
+ public IsPartiallyVisible() {
18
+ const bounds = this.element.getBoundingClientRect();
19
+ return (
20
+ bounds.top >= 0 ||
21
+ bounds.left >= 0 ||
22
+ bounds.bottom <= innerHeight ||
23
+ bounds.right <= innerWidth
24
+ );
25
+ }
26
+
27
+ public IsOffsetVisible(offset: number = 300) {
28
+ const bounds = this.element.getBoundingClientRect();
29
+ // tslint:disable-next-line: max-line-length
30
+ return (
31
+ bounds.top + offset >= 0 ||
32
+ bounds.left + offset >= 0 ||
33
+ bounds.bottom - offset <= innerHeight ||
34
+ bounds.right - offset <= innerWidth
35
+ );
36
+ }
37
+
38
+ public WindowTop(offset: number = 0) {
39
+ const YOffset =
40
+ window.pageYOffset ||
41
+ document.documentElement.scrollTop ||
42
+ document.body.scrollTop ||
43
+ 0;
44
+ return offset <= YOffset;
45
+ }
46
+ }
@@ -1,67 +1,67 @@
1
- type Procedure = (...args: any[]) => any;
2
-
3
- interface Debounce {
4
- (...args: any[]): any;
5
- clear: () => void;
6
- flush: () => void;
7
- }
8
-
9
- const debouncer = (func: Procedure, wait: number, immediate: boolean = false) => {
10
- let timeout: number | null;
11
- let args: any;
12
- let context: any;
13
- let result: any;
14
-
15
- const later = () => {
16
- timeout = null;
17
- if (!immediate) {
18
- result = func.apply(context, args);
19
- context = args = null;
20
- }
21
- };
22
-
23
- const debouncedFunc: Procedure = function (this: any) {
24
- context = this;
25
- args = arguments;
26
- const callNow = immediate && !timeout;
27
-
28
- if (!timeout) {
29
- timeout = window.setTimeout(later, wait);
30
- }
31
-
32
- if (callNow) {
33
- result = func.apply(context, args);
34
- context = args = null;
35
- }
36
-
37
- return result;
38
- };
39
-
40
- const clear = () => {
41
- if (timeout) {
42
- clearTimeout(timeout);
43
- timeout = null;
44
- }
45
- };
46
-
47
- const flush = () => {
48
- if (timeout) {
49
- result = func.apply(context, args);
50
- context = args = null;
51
-
52
- clearTimeout(timeout);
53
- timeout = null;
54
- }
55
- };
56
-
57
- const debounced: Debounce = (() => {
58
- const f: any = debouncedFunc;
59
- f.clear = clear;
60
- f.flush = flush;
61
- return f;
62
- })();
63
-
64
- return debounced;
65
- };
66
-
1
+ type Procedure = (...args: any[]) => any;
2
+
3
+ interface Debounce {
4
+ (...args: any[]): any;
5
+ clear: () => void;
6
+ flush: () => void;
7
+ }
8
+
9
+ const debouncer = (func: Procedure, wait: number, immediate: boolean = false) => {
10
+ let timeout: number | null;
11
+ let args: any;
12
+ let context: any;
13
+ let result: any;
14
+
15
+ const later = () => {
16
+ timeout = null;
17
+ if (!immediate) {
18
+ result = func.apply(context, args);
19
+ context = args = null;
20
+ }
21
+ };
22
+
23
+ const debouncedFunc: Procedure = function (this: any) {
24
+ context = this;
25
+ args = arguments;
26
+ const callNow = immediate && !timeout;
27
+
28
+ if (!timeout) {
29
+ timeout = window.setTimeout(later, wait);
30
+ }
31
+
32
+ if (callNow) {
33
+ result = func.apply(context, args);
34
+ context = args = null;
35
+ }
36
+
37
+ return result;
38
+ };
39
+
40
+ const clear = () => {
41
+ if (timeout) {
42
+ clearTimeout(timeout);
43
+ timeout = null;
44
+ }
45
+ };
46
+
47
+ const flush = () => {
48
+ if (timeout) {
49
+ result = func.apply(context, args);
50
+ context = args = null;
51
+
52
+ clearTimeout(timeout);
53
+ timeout = null;
54
+ }
55
+ };
56
+
57
+ const debounced: Debounce = (() => {
58
+ const f: any = debouncedFunc;
59
+ f.clear = clear;
60
+ f.flush = flush;
61
+ return f;
62
+ })();
63
+
64
+ return debounced;
65
+ };
66
+
67
67
  export default debouncer;
@@ -1,3 +1,3 @@
1
- export default interface IValidator {
2
- isSatisfiedBy(input: string, allowEmpty: boolean): boolean;
3
- }
1
+ export default interface IValidator {
2
+ isSatisfiedBy(input: string, allowEmpty: boolean): boolean;
3
+ }
@@ -1,7 +1,7 @@
1
- import IValidation from '../IValidator.interface';
2
-
3
- export default class BankAccountValidator implements IValidation {
4
- isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
- return true;
6
- }
7
- }
1
+ import IValidation from '../IValidator.interface';
2
+
3
+ export default class BankAccountValidator implements IValidation {
4
+ isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
+ return true;
6
+ }
7
+ }
@@ -1,8 +1,8 @@
1
- import IValidation from '../IValidator.interface';
2
-
3
- export default class BankAccountRegistrationNumberValidator
4
- implements IValidation {
5
- isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
6
- return true;
7
- }
8
- }
1
+ import IValidation from '../IValidator.interface';
2
+
3
+ export default class BankAccountRegistrationNumberValidator
4
+ implements IValidation {
5
+ isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
6
+ return true;
7
+ }
8
+ }
@@ -1,21 +1,21 @@
1
- import IValidation from '../IValidator.interface';
2
-
3
- export default class BankIdNorwayValidator implements IValidation {
4
- isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
- return this.checkNoPersonnummer(input, allowEmpty);
6
- }
7
-
8
- private checkNoPersonnummer(
9
- input: string,
10
- allowEmpty: boolean = true,
11
- ): boolean {
12
- if (!input) {
13
- return allowEmpty;
14
- }
15
- const personnummer: string = input.replace(' ', '').replace('-', '');
16
- const regex: RegExp = new RegExp(
17
- /^(0[1-9]|1[0-9]|2[0-9]|3[0-1])(0[1-9]|1[0-2])(\d{2})(\d{5})$/,
18
- );
19
- return regex.test(personnummer);
20
- }
21
- }
1
+ import IValidation from '../IValidator.interface';
2
+
3
+ export default class BankIdNorwayValidator implements IValidation {
4
+ isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
+ return this.checkNoPersonnummer(input, allowEmpty);
6
+ }
7
+
8
+ private checkNoPersonnummer(
9
+ input: string,
10
+ allowEmpty: boolean = true,
11
+ ): boolean {
12
+ if (!input) {
13
+ return allowEmpty;
14
+ }
15
+ const personnummer: string = input.replace(' ', '').replace('-', '');
16
+ const regex: RegExp = new RegExp(
17
+ /^(0[1-9]|1[0-9]|2[0-9]|3[0-1])(0[1-9]|1[0-2])(\d{2})(\d{5})$/,
18
+ );
19
+ return regex.test(personnummer);
20
+ }
21
+ }
@@ -1,21 +1,21 @@
1
- import IValidation from '../IValidator.interface';
2
-
3
- export default class BankIdSwedenValidator implements IValidation {
4
- isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
- return this.checkSePersonnummer(input, allowEmpty);
6
- }
7
-
8
- private checkSePersonnummer(
9
- input: string,
10
- allowEmpty: boolean = true,
11
- ): boolean {
12
- if (!input) {
13
- return allowEmpty;
14
- }
15
- const personnummer: string = input.replace(' ', '').replace('-', '');
16
- const regex: RegExp = new RegExp(
17
- /^(19\d{2}|20\d{2})(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])(\d{4})$/,
18
- );
19
- return regex.test(personnummer);
20
- }
21
- }
1
+ import IValidation from '../IValidator.interface';
2
+
3
+ export default class BankIdSwedenValidator implements IValidation {
4
+ isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
+ return this.checkSePersonnummer(input, allowEmpty);
6
+ }
7
+
8
+ private checkSePersonnummer(
9
+ input: string,
10
+ allowEmpty: boolean = true,
11
+ ): boolean {
12
+ if (!input) {
13
+ return allowEmpty;
14
+ }
15
+ const personnummer: string = input.replace(' ', '').replace('-', '');
16
+ const regex: RegExp = new RegExp(
17
+ /^(19\d{2}|20\d{2})(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])(\d{4})$/,
18
+ );
19
+ return regex.test(personnummer);
20
+ }
21
+ }
@@ -1,82 +1,82 @@
1
- import IValidation from '../IValidator.interface';
2
-
3
- export default class CprValidator implements IValidation {
4
- isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
- return this.checkCpr(input, allowEmpty);
6
- }
7
- private modulus11Multiply(value: number, index: number): number {
8
- const control: number[] = [4, 3, 2, 7, 6, 5, 4, 3, 2, 1];
9
- return control[index] * value;
10
- }
11
-
12
- private modulus11Exceptions(input: string): boolean {
13
- const exceptionDates: Date[] = [
14
- 1960,
15
- 1964,
16
- 1965,
17
- 1966,
18
- 1969,
19
- 1970,
20
- 1980,
21
- 1982,
22
- 1984,
23
- 1985,
24
- 1986,
25
- 1987,
26
- 1988,
27
- 1989,
28
- 1990,
29
- ].map(x => new Date(x, 0, 1)); // months are 0-indexed
30
-
31
- const cprDate: Date = this.getCprDate(input);
32
-
33
- return exceptionDates.some(x => x.getDate() === cprDate.getDate());
34
- }
35
-
36
- private checkCprDate(input: string): boolean {
37
- let year: number = +input.substr(4, 2) + 2000;
38
- year -= year > new Date().getFullYear() ? 100 : 0; // is 20xx or 19xx
39
- const month: number = +input.substr(2, 2) - 1;
40
- const day: number = +input.substr(0, 2);
41
- const date: Date = new Date(year, month, day);
42
- return (
43
- date.getFullYear() === year &&
44
- date.getMonth() === month &&
45
- date.getDate() === day
46
- );
47
- }
48
-
49
- private getCprDate(input: string): Date {
50
- let year: number = +input.substr(4, 2) + 2000;
51
- year -= year > new Date().getFullYear() ? 100 : 0; // is 20xx or 19xx
52
- const month: number = +input.substr(2, 2) - 1;
53
- const day: number = +input.substr(0, 2);
54
- return new Date(year, month, day);
55
- }
56
-
57
- private checkCpr(input: string, allowEmpty: boolean = true): boolean {
58
- if (!input) {
59
- return allowEmpty;
60
- }
61
- const cprnr: string = input.replace(' ', '').replace('-', '');
62
- if (!cprnr.match(/^\d{10}$/)) {
63
- return false;
64
- }
65
- if (!this.checkCprDate(cprnr)) {
66
- return false;
67
- }
68
- if (this.modulus11Exceptions(cprnr)) {
69
- return true;
70
- }
71
-
72
- let output: number = 0;
73
- for (let i: number = 0; i < 10; i++) {
74
- output += this.modulus11Multiply(
75
- parseInt(cprnr.substr(i, 1), 10),
76
- i,
77
- );
78
- }
79
-
80
- return output % 11 === 0; // hvis output går op i 11, er det et gyldigt cpr.
81
- }
82
- }
1
+ import IValidation from '../IValidator.interface';
2
+
3
+ export default class CprValidator implements IValidation {
4
+ isSatisfiedBy(input: string, allowEmpty: boolean = true): boolean {
5
+ return this.checkCpr(input, allowEmpty);
6
+ }
7
+ private modulus11Multiply(value: number, index: number): number {
8
+ const control: number[] = [4, 3, 2, 7, 6, 5, 4, 3, 2, 1];
9
+ return control[index] * value;
10
+ }
11
+
12
+ private modulus11Exceptions(input: string): boolean {
13
+ const exceptionDates: Date[] = [
14
+ 1960,
15
+ 1964,
16
+ 1965,
17
+ 1966,
18
+ 1969,
19
+ 1970,
20
+ 1980,
21
+ 1982,
22
+ 1984,
23
+ 1985,
24
+ 1986,
25
+ 1987,
26
+ 1988,
27
+ 1989,
28
+ 1990,
29
+ ].map(x => new Date(x, 0, 1)); // months are 0-indexed
30
+
31
+ const cprDate: Date = this.getCprDate(input);
32
+
33
+ return exceptionDates.some(x => x.getDate() === cprDate.getDate());
34
+ }
35
+
36
+ private checkCprDate(input: string): boolean {
37
+ let year: number = +input.substr(4, 2) + 2000;
38
+ year -= year > new Date().getFullYear() ? 100 : 0; // is 20xx or 19xx
39
+ const month: number = +input.substr(2, 2) - 1;
40
+ const day: number = +input.substr(0, 2);
41
+ const date: Date = new Date(year, month, day);
42
+ return (
43
+ date.getFullYear() === year &&
44
+ date.getMonth() === month &&
45
+ date.getDate() === day
46
+ );
47
+ }
48
+
49
+ private getCprDate(input: string): Date {
50
+ let year: number = +input.substr(4, 2) + 2000;
51
+ year -= year > new Date().getFullYear() ? 100 : 0; // is 20xx or 19xx
52
+ const month: number = +input.substr(2, 2) - 1;
53
+ const day: number = +input.substr(0, 2);
54
+ return new Date(year, month, day);
55
+ }
56
+
57
+ private checkCpr(input: string, allowEmpty: boolean = true): boolean {
58
+ if (!input) {
59
+ return allowEmpty;
60
+ }
61
+ const cprnr: string = input.replace(' ', '').replace('-', '');
62
+ if (!cprnr.match(/^\d{10}$/)) {
63
+ return false;
64
+ }
65
+ if (!this.checkCprDate(cprnr)) {
66
+ return false;
67
+ }
68
+ if (this.modulus11Exceptions(cprnr)) {
69
+ return true;
70
+ }
71
+
72
+ let output: number = 0;
73
+ for (let i: number = 0; i < 10; i++) {
74
+ output += this.modulus11Multiply(
75
+ parseInt(cprnr.substr(i, 1), 10),
76
+ i,
77
+ );
78
+ }
79
+
80
+ return output % 11 === 0; // hvis output går op i 11, er det et gyldigt cpr.
81
+ }
82
+ }