@ng-formworks/core 17.2.7 → 18.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 (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +834 -0
  3. package/esm2022/lib/framework-library/framework-library.service.mjs +175 -0
  4. package/esm2022/lib/framework-library/framework.mjs +15 -0
  5. package/esm2022/lib/framework-library/no-framework.component.mjs +18 -0
  6. package/esm2022/lib/framework-library/no-framework.module.mjs +27 -0
  7. package/esm2022/lib/framework-library/no.framework.mjs +19 -0
  8. package/esm2022/lib/json-schema-form.component.mjs +765 -0
  9. package/esm2022/lib/json-schema-form.module.mjs +26 -0
  10. package/esm2022/lib/json-schema-form.service.mjs +676 -0
  11. package/esm2022/lib/locale/de-validation-messages.mjs +60 -0
  12. package/esm2022/lib/locale/en-validation-messages.mjs +60 -0
  13. package/esm2022/lib/locale/es-validation-messages.mjs +57 -0
  14. package/esm2022/lib/locale/fr-validation-messages.mjs +60 -0
  15. package/esm2022/lib/locale/index.mjs +8 -0
  16. package/esm2022/lib/locale/it-validation-messages.mjs +60 -0
  17. package/esm2022/lib/locale/pt-validation-messages.mjs +60 -0
  18. package/esm2022/lib/locale/zh-validation-messages.mjs +60 -0
  19. package/esm2022/lib/shared/convert-schema-to-draft6.function.mjs +300 -0
  20. package/esm2022/lib/shared/form-group.functions.mjs +442 -0
  21. package/esm2022/lib/shared/format-regex.constants.mjs +54 -0
  22. package/esm2022/lib/shared/index.mjs +12 -0
  23. package/esm2022/lib/shared/json-schema.functions.mjs +784 -0
  24. package/esm2022/lib/shared/json.validators.mjs +884 -0
  25. package/esm2022/lib/shared/jsonpointer.functions.mjs +1026 -0
  26. package/esm2022/lib/shared/layout.functions.mjs +1158 -0
  27. package/esm2022/lib/shared/merge-schemas.function.mjs +345 -0
  28. package/esm2022/lib/shared/utility.functions.mjs +380 -0
  29. package/esm2022/lib/shared/validator.functions.mjs +584 -0
  30. package/esm2022/lib/widget-library/add-reference.component.mjs +61 -0
  31. package/esm2022/lib/widget-library/button.component.mjs +72 -0
  32. package/esm2022/lib/widget-library/checkbox.component.mjs +105 -0
  33. package/esm2022/lib/widget-library/checkboxes.component.mjs +147 -0
  34. package/esm2022/lib/widget-library/file.component.mjs +35 -0
  35. package/esm2022/lib/widget-library/hidden.component.mjs +54 -0
  36. package/esm2022/lib/widget-library/index.mjs +55 -0
  37. package/esm2022/lib/widget-library/input.component.mjs +119 -0
  38. package/esm2022/lib/widget-library/message.component.mjs +38 -0
  39. package/esm2022/lib/widget-library/none.component.mjs +21 -0
  40. package/esm2022/lib/widget-library/number.component.mjs +123 -0
  41. package/esm2022/lib/widget-library/one-of.component.mjs +35 -0
  42. package/esm2022/lib/widget-library/orderable.directive.mjs +123 -0
  43. package/esm2022/lib/widget-library/radios.component.mjs +153 -0
  44. package/esm2022/lib/widget-library/root.component.mjs +79 -0
  45. package/esm2022/lib/widget-library/section.component.mjs +199 -0
  46. package/esm2022/lib/widget-library/select-framework.component.mjs +51 -0
  47. package/esm2022/lib/widget-library/select-widget.component.mjs +46 -0
  48. package/esm2022/lib/widget-library/select.component.mjs +150 -0
  49. package/esm2022/lib/widget-library/submit.component.mjs +82 -0
  50. package/esm2022/lib/widget-library/tab.component.mjs +41 -0
  51. package/esm2022/lib/widget-library/tabs.component.mjs +108 -0
  52. package/esm2022/lib/widget-library/template.component.mjs +46 -0
  53. package/esm2022/lib/widget-library/textarea.component.mjs +104 -0
  54. package/esm2022/lib/widget-library/widget-library.module.mjs +42 -0
  55. package/esm2022/lib/widget-library/widget-library.service.mjs +226 -0
  56. package/esm2022/ng-formworks-core.mjs +5 -0
  57. package/esm2022/public_api.mjs +13 -0
  58. package/fesm2022/ng-formworks-core.mjs +10151 -0
  59. package/fesm2022/ng-formworks-core.mjs.map +1 -0
  60. package/index.d.ts +5 -0
  61. package/lib/framework-library/framework-library.service.d.ts +55 -0
  62. package/lib/framework-library/framework.d.ts +13 -0
  63. package/lib/framework-library/no-framework.component.d.ts +8 -0
  64. package/lib/framework-library/no-framework.module.d.ts +9 -0
  65. package/lib/framework-library/no.framework.d.ts +10 -0
  66. package/lib/json-schema-form.component.d.ts +218 -0
  67. package/lib/json-schema-form.module.d.ts +11 -0
  68. package/lib/json-schema-form.service.d.ts +115 -0
  69. package/lib/locale/de-validation-messages.d.ts +1 -0
  70. package/lib/locale/en-validation-messages.d.ts +1 -0
  71. package/lib/locale/es-validation-messages.d.ts +1 -0
  72. package/lib/locale/fr-validation-messages.d.ts +1 -0
  73. package/{src/lib/locale/index.ts → lib/locale/index.d.ts} +7 -7
  74. package/lib/locale/it-validation-messages.d.ts +1 -0
  75. package/lib/locale/pt-validation-messages.d.ts +1 -0
  76. package/lib/locale/zh-validation-messages.d.ts +1 -0
  77. package/lib/shared/convert-schema-to-draft6.function.d.ts +21 -0
  78. package/lib/shared/form-group.functions.d.ts +100 -0
  79. package/lib/shared/format-regex.constants.d.ts +19 -0
  80. package/lib/shared/index.d.ts +9 -0
  81. package/lib/shared/json-schema.functions.d.ts +193 -0
  82. package/lib/shared/json.validators.d.ts +441 -0
  83. package/lib/shared/jsonpointer.functions.d.ts +416 -0
  84. package/lib/shared/layout.functions.d.ts +83 -0
  85. package/lib/shared/merge-schemas.function.d.ts +19 -0
  86. package/lib/shared/utility.functions.d.ts +165 -0
  87. package/{src/lib/shared/validator.functions.ts → lib/shared/validator.functions.d.ts} +364 -601
  88. package/lib/widget-library/add-reference.component.d.ts +20 -0
  89. package/lib/widget-library/button.component.d.ts +21 -0
  90. package/lib/widget-library/checkbox.component.d.ts +24 -0
  91. package/lib/widget-library/checkboxes.component.d.ts +24 -0
  92. package/lib/widget-library/file.component.d.ts +21 -0
  93. package/lib/widget-library/hidden.component.d.ts +19 -0
  94. package/{src/lib/widget-library/index.ts → lib/widget-library/index.d.ts} +47 -56
  95. package/lib/widget-library/input.component.d.ts +22 -0
  96. package/lib/widget-library/message.component.d.ts +15 -0
  97. package/lib/widget-library/none.component.d.ts +8 -0
  98. package/lib/widget-library/number.component.d.ts +25 -0
  99. package/lib/widget-library/one-of.component.d.ts +21 -0
  100. package/lib/widget-library/orderable.directive.d.ts +41 -0
  101. package/lib/widget-library/radios.component.d.ts +23 -0
  102. package/lib/widget-library/root.component.d.ts +17 -0
  103. package/lib/widget-library/section.component.d.ts +19 -0
  104. package/lib/widget-library/select-framework.component.d.ts +18 -0
  105. package/lib/widget-library/select-widget.component.d.ts +18 -0
  106. package/lib/widget-library/select.component.d.ts +24 -0
  107. package/lib/widget-library/submit.component.d.ts +24 -0
  108. package/lib/widget-library/tab.component.d.ts +14 -0
  109. package/lib/widget-library/tabs.component.d.ts +20 -0
  110. package/lib/widget-library/template.component.d.ts +18 -0
  111. package/lib/widget-library/textarea.component.d.ts +21 -0
  112. package/lib/widget-library/widget-library.module.d.ts +31 -0
  113. package/lib/widget-library/widget-library.service.d.ts +22 -0
  114. package/package.json +66 -53
  115. package/{src/public_api.ts → public_api.d.ts} +9 -21
  116. package/karma.conf.js +0 -46
  117. package/ng-package.json +0 -11
  118. package/src/lib/framework-library/framework-library.service.ts +0 -195
  119. package/src/lib/framework-library/framework.ts +0 -11
  120. package/src/lib/framework-library/no-framework.component.html +0 -2
  121. package/src/lib/framework-library/no-framework.component.ts +0 -11
  122. package/src/lib/framework-library/no-framework.module.ts +0 -18
  123. package/src/lib/framework-library/no.framework.ts +0 -11
  124. package/src/lib/json-schema-form.component.html +0 -7
  125. package/src/lib/json-schema-form.component.ts +0 -809
  126. package/src/lib/json-schema-form.module.ts +0 -17
  127. package/src/lib/json-schema-form.service.ts +0 -907
  128. package/src/lib/locale/de-validation-messages.ts +0 -58
  129. package/src/lib/locale/en-validation-messages.ts +0 -58
  130. package/src/lib/locale/es-validation-messages.ts +0 -55
  131. package/src/lib/locale/fr-validation-messages.ts +0 -58
  132. package/src/lib/locale/it-validation-messages.ts +0 -58
  133. package/src/lib/locale/pt-validation-messages.ts +0 -58
  134. package/src/lib/locale/zh-validation-messages.ts +0 -58
  135. package/src/lib/locale-dates/en-US.ts +0 -5
  136. package/src/lib/shared/convert-schema-to-draft6.function.ts +0 -321
  137. package/src/lib/shared/form-group.functions.ts +0 -522
  138. package/src/lib/shared/format-regex.constants.ts +0 -73
  139. package/src/lib/shared/index.ts +0 -40
  140. package/src/lib/shared/json-schema.functions.ts +0 -788
  141. package/src/lib/shared/json.validators.ts +0 -878
  142. package/src/lib/shared/jsonpointer.functions.ts +0 -1012
  143. package/src/lib/shared/jspointer.functions.json.spec.ts +0 -103
  144. package/src/lib/shared/layout.functions.ts +0 -1233
  145. package/src/lib/shared/merge-schemas.function.ts +0 -329
  146. package/src/lib/shared/utility.functions.ts +0 -373
  147. package/src/lib/shared/validator.functions.spec.ts +0 -55
  148. package/src/lib/widget-library/add-reference.component.ts +0 -59
  149. package/src/lib/widget-library/button.component.ts +0 -54
  150. package/src/lib/widget-library/checkbox.component.ts +0 -74
  151. package/src/lib/widget-library/checkboxes.component.ts +0 -104
  152. package/src/lib/widget-library/file.component.ts +0 -36
  153. package/src/lib/widget-library/hidden.component.ts +0 -39
  154. package/src/lib/widget-library/input.component.ts +0 -76
  155. package/src/lib/widget-library/message.component.ts +0 -29
  156. package/src/lib/widget-library/none.component.ts +0 -12
  157. package/src/lib/widget-library/number.component.ts +0 -79
  158. package/src/lib/widget-library/one-of.component.ts +0 -36
  159. package/src/lib/widget-library/orderable.directive.ts +0 -130
  160. package/src/lib/widget-library/radios.component.ts +0 -101
  161. package/src/lib/widget-library/root.component.ts +0 -78
  162. package/src/lib/widget-library/section.component.ts +0 -133
  163. package/src/lib/widget-library/select-framework.component.ts +0 -50
  164. package/src/lib/widget-library/select-widget.component.ts +0 -46
  165. package/src/lib/widget-library/select.component.ts +0 -96
  166. package/src/lib/widget-library/submit.component.ts +0 -68
  167. package/src/lib/widget-library/tab.component.ts +0 -29
  168. package/src/lib/widget-library/tabs.component.ts +0 -83
  169. package/src/lib/widget-library/template.component.ts +0 -52
  170. package/src/lib/widget-library/textarea.component.ts +0 -68
  171. package/src/lib/widget-library/widget-library.module.ts +0 -13
  172. package/src/lib/widget-library/widget-library.service.ts +0 -234
  173. package/src/test.ts +0 -18
  174. package/tsconfig.lib.json +0 -25
  175. package/tsconfig.lib.prod.json +0 -9
  176. package/tsconfig.spec.json +0 -17
  177. package/tslint.json +0 -11
@@ -1,601 +1,364 @@
1
- import { AbstractControl } from '@angular/forms';
2
- import { from, Observable } from 'rxjs';
3
-
4
- /**
5
- * Validator utility function library:
6
- *
7
- * Validator and error utilities:
8
- * _executeValidators, _executeAsyncValidators, _mergeObjects, _mergeErrors
9
- *
10
- * Individual value checking:
11
- * isDefined, hasValue, isEmpty
12
- *
13
- * Individual type checking:
14
- * isString, isNumber, isInteger, isBoolean, isFunction, isObject, isArray,
15
- * isMap, isSet, isPromise, isObservable
16
- *
17
- * Multiple type checking and fixing:
18
- * getType, isType, isPrimitive, toJavaScriptType, toSchemaType,
19
- * _toPromise, toObservable
20
- *
21
- * Utility functions:
22
- * inArray, xor
23
- *
24
- * Typescript types and interfaces:
25
- * SchemaPrimitiveType, SchemaType, JavaScriptPrimitiveType, JavaScriptType,
26
- * PrimitiveValue, PlainObject, IValidatorFn, AsyncIValidatorFn
27
- *
28
- * Note: 'IValidatorFn' is short for 'invertable validator function',
29
- * which is a validator functions that accepts an optional second
30
- * argument which, if set to TRUE, causes the validator to perform
31
- * the opposite of its original function.
32
- */
33
-
34
- export type SchemaPrimitiveType =
35
- 'string' | 'number' | 'integer' | 'boolean' | 'null';
36
- export type SchemaType =
37
- 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'object' | 'array';
38
- export type JavaScriptPrimitiveType =
39
- 'string' | 'number' | 'boolean' | 'null' | 'undefined';
40
- export type JavaScriptType =
41
- 'string' | 'number' | 'boolean' | 'null' | 'undefined' | 'object' | 'array' |
42
- 'map' | 'set' | 'arguments' | 'date' | 'error' | 'function' | 'json' |
43
- 'math' | 'regexp'; // Note: this list is incomplete
44
- export type PrimitiveValue = string | number | boolean | null | undefined;
45
- export interface PlainObject { [k: string]: any; }
46
-
47
- export type IValidatorFn = (c: AbstractControl, i?: boolean) => PlainObject;
48
- export type AsyncIValidatorFn = (c: AbstractControl, i?: boolean) => any;
49
-
50
- /**
51
- * '_executeValidators' utility function
52
- *
53
- * Validates a control against an array of validators, and returns
54
- * an array of the same length containing a combination of error messages
55
- * (from invalid validators) and null values (from valid validators)
56
- *
57
- * // { AbstractControl } control - control to validate
58
- * // { IValidatorFn[] } validators - array of validators
59
- * // { boolean } invert - invert?
60
- * // { PlainObject[] } - array of nulls and error message
61
- */
62
- export function _executeValidators(control, validators, invert = false) {
63
- return validators.map(validator => validator(control, invert));
64
- }
65
-
66
- /**
67
- * '_executeAsyncValidators' utility function
68
- *
69
- * Validates a control against an array of async validators, and returns
70
- * an array of observabe results of the same length containing a combination of
71
- * error messages (from invalid validators) and null values (from valid ones)
72
- *
73
- * // { AbstractControl } control - control to validate
74
- * // { AsyncIValidatorFn[] } validators - array of async validators
75
- * // { boolean } invert - invert?
76
- * // - array of observable nulls and error message
77
- */
78
- export function _executeAsyncValidators(control, validators, invert = false) {
79
- return validators.map(validator => validator(control, invert));
80
- }
81
-
82
- /**
83
- * '_mergeObjects' utility function
84
- *
85
- * Recursively Merges one or more objects into a single object with combined keys.
86
- * Automatically detects and ignores null and undefined inputs.
87
- * Also detects duplicated boolean 'not' keys and XORs their values.
88
- *
89
- * // { PlainObject[] } objects - one or more objects to merge
90
- * // { PlainObject } - merged object
91
- */
92
- export function _mergeObjects(...objects) {
93
- const mergedObject: PlainObject = { };
94
- for (const currentObject of objects) {
95
- if (isObject(currentObject)) {
96
- for (const key of Object.keys(currentObject)) {
97
- const currentValue = currentObject[key];
98
- const mergedValue = mergedObject[key];
99
- mergedObject[key] = !isDefined(mergedValue) ? currentValue :
100
- key === 'not' && isBoolean(mergedValue, 'strict') &&
101
- isBoolean(currentValue, 'strict') ? xor(mergedValue, currentValue) :
102
- getType(mergedValue) === 'object' && getType(currentValue) === 'object' ?
103
- _mergeObjects(mergedValue, currentValue) :
104
- currentValue;
105
- }
106
- }
107
- }
108
- return mergedObject;
109
- }
110
-
111
- /**
112
- * '_mergeErrors' utility function
113
- *
114
- * Merges an array of objects.
115
- * Used for combining the validator errors returned from 'executeValidators'
116
- *
117
- * // { PlainObject[] } arrayOfErrors - array of objects
118
- * // { PlainObject } - merged object, or null if no usable input objectcs
119
- */
120
- export function _mergeErrors(arrayOfErrors) {
121
- const mergedErrors = _mergeObjects(...arrayOfErrors);
122
- return isEmpty(mergedErrors) ? null : mergedErrors;
123
- }
124
-
125
- /**
126
- * 'isDefined' utility function
127
- *
128
- * Checks if a variable contains a value of any type.
129
- * Returns true even for otherwise 'falsey' values of 0, '', and false.
130
- *
131
- * // value - the value to check
132
- * // { boolean } - false if undefined or null, otherwise true
133
- */
134
- export function isDefined(value) {
135
- return value !== undefined && value !== null;
136
- }
137
-
138
- /**
139
- * 'hasValue' utility function
140
- *
141
- * Checks if a variable contains a value.
142
- * Returs false for null, undefined, or a zero-length strng, '',
143
- * otherwise returns true.
144
- * (Stricter than 'isDefined' because it also returns false for '',
145
- * though it stil returns true for otherwise 'falsey' values 0 and false.)
146
- *
147
- * // value - the value to check
148
- * // { boolean } - false if undefined, null, or '', otherwise true
149
- */
150
- export function hasValue(value) {
151
- return value !== undefined && value !== null && value !== '';
152
- }
153
-
154
- /**
155
- * 'isEmpty' utility function
156
- *
157
- * Similar to !hasValue, but also returns true for empty arrays and objects.
158
- *
159
- * // value - the value to check
160
- * // { boolean } - false if undefined, null, or '', otherwise true
161
- */
162
- export function isEmpty(value) {
163
- if (isArray(value)) { return !value.length; }
164
- if (isObject(value)) { return !Object.keys(value).length; }
165
- return value === undefined || value === null || value === '';
166
- }
167
-
168
- /**
169
- * 'isString' utility function
170
- *
171
- * Checks if a value is a string.
172
- *
173
- * // value - the value to check
174
- * // { boolean } - true if string, false if not
175
- */
176
- export function isString(value) {
177
- return typeof value === 'string';
178
- }
179
-
180
- /**
181
- * 'isNumber' utility function
182
- *
183
- * Checks if a value is a regular number, numeric string, or JavaScript Date.
184
- *
185
- * // value - the value to check
186
- * // { any = false } strict - if truthy, also checks JavaScript tyoe
187
- * // { boolean } - true if number, false if not
188
- */
189
- export function isNumber(value, strict: any = false) {
190
- if (strict && typeof value !== 'number') { return false; }
191
- return !isNaN(value) && value !== value / 0;
192
- }
193
-
194
- /**
195
- * 'isInteger' utility function
196
- *
197
- * Checks if a value is an integer.
198
- *
199
- * // value - the value to check
200
- * // { any = false } strict - if truthy, also checks JavaScript tyoe
201
- * // {boolean } - true if number, false if not
202
- */
203
- export function isInteger(value, strict: any = false) {
204
- if (strict && typeof value !== 'number') { return false; }
205
- return !isNaN(value) && value !== value / 0 && value % 1 === 0;
206
- }
207
-
208
- /**
209
- * 'isBoolean' utility function
210
- *
211
- * Checks if a value is a boolean.
212
- *
213
- * // value - the value to check
214
- * // { any = null } option - if 'strict', also checks JavaScript type
215
- * if TRUE or FALSE, checks only for that value
216
- * // { boolean } - true if boolean, false if not
217
- */
218
- export function isBoolean(value, option: any = null) {
219
- if (option === 'strict') { return value === true || value === false; }
220
- if (option === true) {
221
- return value === true || value === 1 || value === 'true' || value === '1';
222
- }
223
- if (option === false) {
224
- return value === false || value === 0 || value === 'false' || value === '0';
225
- }
226
- return value === true || value === 1 || value === 'true' || value === '1' ||
227
- value === false || value === 0 || value === 'false' || value === '0';
228
- }
229
-
230
- export function isFunction(item: any): boolean {
231
- return typeof item === 'function';
232
- }
233
-
234
- export function isObject(item: any): boolean {
235
- return item !== null && typeof item === 'object';
236
- }
237
-
238
- export function isArray(item: any): boolean {
239
- return Array.isArray(item);
240
- }
241
-
242
- export function isDate(item: any): boolean {
243
- return !!item && Object.prototype.toString.call(item) === '[object Date]';
244
- }
245
-
246
- export function isMap(item: any): boolean {
247
- return !!item && Object.prototype.toString.call(item) === '[object Map]';
248
- }
249
-
250
- export function isSet(item: any): boolean {
251
- return !!item && Object.prototype.toString.call(item) === '[object Set]';
252
- }
253
-
254
- export function isSymbol(item: any): boolean {
255
- return typeof item === 'symbol';
256
- }
257
-
258
- /**
259
- * 'getType' function
260
- *
261
- * Detects the JSON Schema Type of a value.
262
- * By default, detects numbers and integers even if formatted as strings.
263
- * (So all integers are also numbers, and any number may also be a string.)
264
- * However, it only detects true boolean values (to detect boolean values
265
- * in non-boolean formats, use isBoolean() instead).
266
- *
267
- * If passed a second optional parameter of 'strict', it will only detect
268
- * numbers and integers if they are formatted as JavaScript numbers.
269
- *
270
- * Examples:
271
- * getType('10.5') = 'number'
272
- * getType(10.5) = 'number'
273
- * getType('10') = 'integer'
274
- * getType(10) = 'integer'
275
- * getType('true') = 'string'
276
- * getType(true) = 'boolean'
277
- * getType(null) = 'null'
278
- * getType({ }) = 'object'
279
- * getType([]) = 'array'
280
- *
281
- * getType('10.5', 'strict') = 'string'
282
- * getType(10.5, 'strict') = 'number'
283
- * getType('10', 'strict') = 'string'
284
- * getType(10, 'strict') = 'integer'
285
- * getType('true', 'strict') = 'string'
286
- * getType(true, 'strict') = 'boolean'
287
- *
288
- * // value - value to check
289
- * // { any = false } strict - if truthy, also checks JavaScript tyoe
290
- * // { SchemaType }
291
- */
292
- export function getType(value, strict: any = false) {
293
- if (!isDefined(value)) { return 'null'; }
294
- if (isArray(value)) { return 'array'; }
295
- if (isObject(value)) { return 'object'; }
296
- if (isBoolean(value, 'strict')) { return 'boolean'; }
297
- if (isInteger(value, strict)) { return 'integer'; }
298
- if (isNumber(value, strict)) { return 'number'; }
299
- if (isString(value) || (!strict && isDate(value))) { return 'string'; }
300
- return null;
301
- }
302
-
303
- /**
304
- * 'isType' function
305
- *
306
- * Checks wether an input (probably string) value contains data of
307
- * a specified JSON Schema type
308
- *
309
- * // { PrimitiveValue } value - value to check
310
- * // { SchemaPrimitiveType } type - type to check
311
- * // { boolean }
312
- */
313
- export function isType(value, type) {
314
- switch (type) {
315
- case 'string':
316
- return isString(value) || isDate(value);
317
- case 'number':
318
- return isNumber(value);
319
- case 'integer':
320
- return isInteger(value);
321
- case 'boolean':
322
- return isBoolean(value);
323
- case 'null':
324
- return !hasValue(value);
325
- default:
326
- console.error(`isType error: "${type}" is not a recognized type.`);
327
- return null;
328
- }
329
- }
330
-
331
- /**
332
- * 'isPrimitive' function
333
- *
334
- * Checks wether an input value is a JavaScript primitive type:
335
- * string, number, boolean, or null.
336
- *
337
- * // value - value to check
338
- * // { boolean }
339
- */
340
- export function isPrimitive(value) {
341
- return (isString(value) || isNumber(value) ||
342
- isBoolean(value, 'strict') || value === null);
343
- }
344
-
345
- /**
346
- *
347
- * @param date
348
- * @returns {string}
349
- * exmaple:
350
- * toDateString('2018-01-01') = '2018-01-01'
351
- * toDateString('2018-01-30T00:00:00.000Z') = '2018-01-30'
352
- */
353
- export const toIsoString = (date: Date) => {
354
- const day = date.getDate();
355
- const month = date.getMonth() + 1;
356
- const year = date.getFullYear();
357
- return `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
358
- }
359
-
360
- /**
361
- * 'toJavaScriptType' function
362
- *
363
- * Converts an input (probably string) value to a JavaScript primitive type -
364
- * 'string', 'number', 'boolean', or 'null' - before storing in a JSON object.
365
- *
366
- * Does not coerce values (other than null), and only converts the types
367
- * of values that would otherwise be valid.
368
- *
369
- * If the optional third parameter 'strictIntegers' is TRUE, and the
370
- * JSON Schema type 'integer' is specified, it also verifies the input value
371
- * is an integer and, if it is, returns it as a JaveScript number.
372
- * If 'strictIntegers' is FALSE (or not set) the type 'integer' is treated
373
- * exactly the same as 'number', and allows decimals.
374
- *
375
- * Valid Examples:
376
- * toJavaScriptType('10', 'number' ) = 10 // '10' is a number
377
- * toJavaScriptType('10', 'integer') = 10 // '10' is also an integer
378
- * toJavaScriptType( 10, 'integer') = 10 // 10 is still an integer
379
- * toJavaScriptType( 10, 'string' ) = '10' // 10 can be made into a string
380
- * toJavaScriptType('10.5', 'number' ) = 10.5 // '10.5' is a number
381
- *
382
- * Invalid Examples:
383
- * toJavaScriptType('10.5', 'integer') = null // '10.5' is not an integer
384
- * toJavaScriptType( 10.5, 'integer') = null // 10.5 is still not an integer
385
- *
386
- * // { PrimitiveValue } value - value to convert
387
- * // { SchemaPrimitiveType | SchemaPrimitiveType[] } types - types to convert to
388
- * // { boolean = false } strictIntegers - if FALSE, treat integers as numbers
389
- * // { PrimitiveValue }
390
- */
391
- export function toJavaScriptType(value, types, strictIntegers = true) {
392
- if (!isDefined(value)) { return null; }
393
- if (isString(types)) { types = [types]; }
394
- if (strictIntegers && inArray('integer', types)) {
395
- if (isInteger(value, 'strict')) { return value; }
396
- if (isInteger(value)) { return parseInt(value, 10); }
397
- }
398
- if (inArray('number', types) || (!strictIntegers && inArray('integer', types))) {
399
- if (isNumber(value, 'strict')) { return value; }
400
- if (isNumber(value)) { return parseFloat(value); }
401
- }
402
- if (inArray('string', types)) {
403
- if (isString(value)) { return value; }
404
- // If value is a date, and types includes 'string',
405
- // convert the date to a string
406
- if (isDate(value)) { return toIsoString(value); }
407
- if (isNumber(value)) { return value.toString(); }
408
- }
409
- // If value is a date, and types includes 'integer' or 'number',
410
- // but not 'string', convert the date to a number
411
- if (isDate(value) && (inArray('integer', types) || inArray('number', types))) {
412
- return value.getTime();
413
- }
414
- if (inArray('boolean', types)) {
415
- if (isBoolean(value, true)) { return true; }
416
- if (isBoolean(value, false)) { return false; }
417
- }
418
- return null;
419
- }
420
-
421
- /**
422
- * 'toSchemaType' function
423
- *
424
- * Converts an input (probably string) value to the "best" JavaScript
425
- * equivalent available from an allowed list of JSON Schema types, which may
426
- * contain 'string', 'number', 'integer', 'boolean', and/or 'null'.
427
- * If necssary, it does progressively agressive type coersion.
428
- * It will not return null unless null is in the list of allowed types.
429
- *
430
- * Number conversion examples:
431
- * toSchemaType('10', ['number','integer','string']) = 10 // integer
432
- * toSchemaType('10', ['number','string']) = 10 // number
433
- * toSchemaType('10', ['string']) = '10' // string
434
- * toSchemaType('10.5', ['number','integer','string']) = 10.5 // number
435
- * toSchemaType('10.5', ['integer','string']) = '10.5' // string
436
- * toSchemaType('10.5', ['integer']) = 10 // integer
437
- * toSchemaType(10.5, ['null','boolean','string']) = '10.5' // string
438
- * toSchemaType(10.5, ['null','boolean']) = true // boolean
439
- *
440
- * String conversion examples:
441
- * toSchemaType('1.5x', ['boolean','number','integer','string']) = '1.5x' // string
442
- * toSchemaType('1.5x', ['boolean','number','integer']) = '1.5' // number
443
- * toSchemaType('1.5x', ['boolean','integer']) = '1' // integer
444
- * toSchemaType('1.5x', ['boolean']) = true // boolean
445
- * toSchemaType('xyz', ['number','integer','boolean','null']) = true // boolean
446
- * toSchemaType('xyz', ['number','integer','null']) = null // null
447
- * toSchemaType('xyz', ['number','integer']) = 0 // number
448
- *
449
- * Boolean conversion examples:
450
- * toSchemaType('1', ['integer','number','string','boolean']) = 1 // integer
451
- * toSchemaType('1', ['number','string','boolean']) = 1 // number
452
- * toSchemaType('1', ['string','boolean']) = '1' // string
453
- * toSchemaType('1', ['boolean']) = true // boolean
454
- * toSchemaType('true', ['number','string','boolean']) = 'true' // string
455
- * toSchemaType('true', ['boolean']) = true // boolean
456
- * toSchemaType('true', ['number']) = 0 // number
457
- * toSchemaType(true, ['number','string','boolean']) = true // boolean
458
- * toSchemaType(true, ['number','string']) = 'true' // string
459
- * toSchemaType(true, ['number']) = 1 // number
460
- *
461
- * // { PrimitiveValue } value - value to convert
462
- * // { SchemaPrimitiveType | SchemaPrimitiveType[] } types - allowed types to convert to
463
- * // { PrimitiveValue }
464
- */
465
- export function toSchemaType(value, types) {
466
- if (!isArray(<SchemaPrimitiveType>types)) {
467
- types = <SchemaPrimitiveType[]>[types];
468
- }
469
- if ((<SchemaPrimitiveType[]>types).includes('null') && !hasValue(value)) {
470
- return null;
471
- }
472
- if ((<SchemaPrimitiveType[]>types).includes('boolean') && !isBoolean(value, 'strict')) {
473
- return value;
474
- }
475
- if ((<SchemaPrimitiveType[]>types).includes('integer')) {
476
- const testValue = toJavaScriptType(value, 'integer');
477
- if (testValue !== null) { return +testValue; }
478
- }
479
- if ((<SchemaPrimitiveType[]>types).includes('number')) {
480
- const testValue = toJavaScriptType(value, 'number');
481
- if (testValue !== null) { return +testValue; }
482
- }
483
- if (
484
- (isString(value) || isNumber(value, 'strict')) &&
485
- (<SchemaPrimitiveType[]>types).includes('string')
486
- ) { // Convert number to string
487
- return toJavaScriptType(value, 'string');
488
- }
489
- if ((<SchemaPrimitiveType[]>types).includes('boolean') && isBoolean(value)) {
490
- return toJavaScriptType(value, 'boolean');
491
- }
492
- if ((<SchemaPrimitiveType[]>types).includes('string')) { // Convert null & boolean to string
493
- if (value === null) { return ''; }
494
- const testValue = toJavaScriptType(value, 'string');
495
- if (testValue !== null) { return testValue; }
496
- }
497
- if ((
498
- (<SchemaPrimitiveType[]>types).includes('number') ||
499
- (<SchemaPrimitiveType[]>types).includes('integer'))
500
- ) {
501
- if (value === true) { return 1; } // Convert boolean & null to number
502
- if (value === false || value === null || value === '') { return 0; }
503
- }
504
- if ((<SchemaPrimitiveType[]>types).includes('number')) { // Convert mixed string to number
505
- const testValue = parseFloat(<string>value);
506
- if (!!testValue) { return testValue; }
507
- }
508
- if ((<SchemaPrimitiveType[]>types).includes('integer')) { // Convert string or number to integer
509
- const testValue = parseInt(<string>value, 10);
510
- if (!!testValue) { return testValue; }
511
- }
512
- if ((<SchemaPrimitiveType[]>types).includes('boolean')) { // Convert anything to boolean
513
- return !!value;
514
- }
515
- if ((
516
- (<SchemaPrimitiveType[]>types).includes('number') ||
517
- (<SchemaPrimitiveType[]>types).includes('integer')
518
- ) && !(<SchemaPrimitiveType[]>types).includes('null')
519
- ) {
520
- return 0; // If null not allowed, return 0 for non-convertable values
521
- }
522
- }
523
-
524
- /**
525
- * 'isPromise' function
526
- *
527
- * // object
528
- * // { boolean }
529
- */
530
- export function isPromise(object): object is Promise<any> {
531
- return !!object && typeof object.then === 'function';
532
- }
533
-
534
- /**
535
- * 'isObservable' function
536
- *
537
- * // object
538
- * // { boolean }
539
- */
540
- export function isObservable(object): object is Observable<any> {
541
- return !!object && typeof object.subscribe === 'function';
542
- }
543
-
544
- /**
545
- * '_toPromise' function
546
- *
547
- * // { object } object
548
- * // { Promise<any> }
549
- */
550
- export function _toPromise(object): Promise<any> {
551
- return isPromise(object) ? object : object.toPromise();
552
- }
553
-
554
- /**
555
- * 'toObservable' function
556
- *
557
- * // { object } object
558
- * // { Observable<any> }
559
- */
560
- export function toObservable(object): Observable<any> {
561
- const observable = isPromise(object) ? from(object) : object;
562
- if (isObservable(observable)) { return observable; }
563
- console.error('toObservable error: Expected validator to return Promise or Observable.');
564
- return new Observable();
565
- }
566
-
567
- /**
568
- * 'inArray' function
569
- *
570
- * Searches an array for an item, or one of a list of items, and returns true
571
- * as soon as a match is found, or false if no match.
572
- *
573
- * If the optional third parameter allIn is set to TRUE, and the item to find
574
- * is an array, then the function returns true only if all elements from item
575
- * are found in the array list, and false if any element is not found. If the
576
- * item to find is not an array, setting allIn to TRUE has no effect.
577
- *
578
- * // { any|any[] } item - the item to search for
579
- * // array - the array to search
580
- * // { boolean = false } allIn - if TRUE, all items must be in array
581
- * // { boolean } - true if item(s) in array, false otherwise
582
- */
583
- export function inArray(item, array, allIn = false) {
584
- if (!isDefined(item) || !isArray(array)) { return false; }
585
- return isArray(item) ?
586
- item[allIn ? 'every' : 'some'](subItem => array.includes(subItem)) :
587
- array.includes(item);
588
- }
589
-
590
- /**
591
- * 'xor' utility function - exclusive or
592
- *
593
- * Returns true if exactly one of two values is truthy.
594
- *
595
- * // value1 - first value to check
596
- * // value2 - second value to check
597
- * // { boolean } - true if exactly one input value is truthy, false if not
598
- */
599
- export function xor(value1, value2) {
600
- return (!!value1 && !value2) || (!value1 && !!value2);
601
- }
1
+ import { AbstractControl } from '@angular/forms';
2
+ import { Observable } from 'rxjs';
3
+ /**
4
+ * Validator utility function library:
5
+ *
6
+ * Validator and error utilities:
7
+ * _executeValidators, _executeAsyncValidators, _mergeObjects, _mergeErrors
8
+ *
9
+ * Individual value checking:
10
+ * isDefined, hasValue, isEmpty
11
+ *
12
+ * Individual type checking:
13
+ * isString, isNumber, isInteger, isBoolean, isFunction, isObject, isArray,
14
+ * isMap, isSet, isPromise, isObservable
15
+ *
16
+ * Multiple type checking and fixing:
17
+ * getType, isType, isPrimitive, toJavaScriptType, toSchemaType,
18
+ * _toPromise, toObservable
19
+ *
20
+ * Utility functions:
21
+ * inArray, xor
22
+ *
23
+ * Typescript types and interfaces:
24
+ * SchemaPrimitiveType, SchemaType, JavaScriptPrimitiveType, JavaScriptType,
25
+ * PrimitiveValue, PlainObject, IValidatorFn, AsyncIValidatorFn
26
+ *
27
+ * Note: 'IValidatorFn' is short for 'invertable validator function',
28
+ * which is a validator functions that accepts an optional second
29
+ * argument which, if set to TRUE, causes the validator to perform
30
+ * the opposite of its original function.
31
+ */
32
+ export type SchemaPrimitiveType = 'string' | 'number' | 'integer' | 'boolean' | 'null';
33
+ export type SchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'object' | 'array';
34
+ export type JavaScriptPrimitiveType = 'string' | 'number' | 'boolean' | 'null' | 'undefined';
35
+ export type JavaScriptType = 'string' | 'number' | 'boolean' | 'null' | 'undefined' | 'object' | 'array' | 'map' | 'set' | 'arguments' | 'date' | 'error' | 'function' | 'json' | 'math' | 'regexp';
36
+ export type PrimitiveValue = string | number | boolean | null | undefined;
37
+ export interface PlainObject {
38
+ [k: string]: any;
39
+ }
40
+ export type IValidatorFn = (c: AbstractControl, i?: boolean) => PlainObject;
41
+ export type AsyncIValidatorFn = (c: AbstractControl, i?: boolean) => any;
42
+ /**
43
+ * '_executeValidators' utility function
44
+ *
45
+ * Validates a control against an array of validators, and returns
46
+ * an array of the same length containing a combination of error messages
47
+ * (from invalid validators) and null values (from valid validators)
48
+ *
49
+ * // { AbstractControl } control - control to validate
50
+ * // { IValidatorFn[] } validators - array of validators
51
+ * // { boolean } invert - invert?
52
+ * // { PlainObject[] } - array of nulls and error message
53
+ */
54
+ export declare function _executeValidators(control: any, validators: any, invert?: boolean): any;
55
+ /**
56
+ * '_executeAsyncValidators' utility function
57
+ *
58
+ * Validates a control against an array of async validators, and returns
59
+ * an array of observabe results of the same length containing a combination of
60
+ * error messages (from invalid validators) and null values (from valid ones)
61
+ *
62
+ * // { AbstractControl } control - control to validate
63
+ * // { AsyncIValidatorFn[] } validators - array of async validators
64
+ * // { boolean } invert - invert?
65
+ * // - array of observable nulls and error message
66
+ */
67
+ export declare function _executeAsyncValidators(control: any, validators: any, invert?: boolean): any;
68
+ /**
69
+ * '_mergeObjects' utility function
70
+ *
71
+ * Recursively Merges one or more objects into a single object with combined keys.
72
+ * Automatically detects and ignores null and undefined inputs.
73
+ * Also detects duplicated boolean 'not' keys and XORs their values.
74
+ *
75
+ * // { PlainObject[] } objects - one or more objects to merge
76
+ * // { PlainObject } - merged object
77
+ */
78
+ export declare function _mergeObjects(...objects: any[]): PlainObject;
79
+ /**
80
+ * '_mergeErrors' utility function
81
+ *
82
+ * Merges an array of objects.
83
+ * Used for combining the validator errors returned from 'executeValidators'
84
+ *
85
+ * // { PlainObject[] } arrayOfErrors - array of objects
86
+ * // { PlainObject } - merged object, or null if no usable input objectcs
87
+ */
88
+ export declare function _mergeErrors(arrayOfErrors: any): PlainObject;
89
+ /**
90
+ * 'isDefined' utility function
91
+ *
92
+ * Checks if a variable contains a value of any type.
93
+ * Returns true even for otherwise 'falsey' values of 0, '', and false.
94
+ *
95
+ * // value - the value to check
96
+ * // { boolean } - false if undefined or null, otherwise true
97
+ */
98
+ export declare function isDefined(value: any): boolean;
99
+ /**
100
+ * 'hasValue' utility function
101
+ *
102
+ * Checks if a variable contains a value.
103
+ * Returs false for null, undefined, or a zero-length strng, '',
104
+ * otherwise returns true.
105
+ * (Stricter than 'isDefined' because it also returns false for '',
106
+ * though it stil returns true for otherwise 'falsey' values 0 and false.)
107
+ *
108
+ * // value - the value to check
109
+ * // { boolean } - false if undefined, null, or '', otherwise true
110
+ */
111
+ export declare function hasValue(value: any): boolean;
112
+ /**
113
+ * 'isEmpty' utility function
114
+ *
115
+ * Similar to !hasValue, but also returns true for empty arrays and objects.
116
+ *
117
+ * // value - the value to check
118
+ * // { boolean } - false if undefined, null, or '', otherwise true
119
+ */
120
+ export declare function isEmpty(value: any): boolean;
121
+ /**
122
+ * 'isString' utility function
123
+ *
124
+ * Checks if a value is a string.
125
+ *
126
+ * // value - the value to check
127
+ * // { boolean } - true if string, false if not
128
+ */
129
+ export declare function isString(value: any): value is string;
130
+ /**
131
+ * 'isNumber' utility function
132
+ *
133
+ * Checks if a value is a regular number, numeric string, or JavaScript Date.
134
+ *
135
+ * // value - the value to check
136
+ * // { any = false } strict - if truthy, also checks JavaScript tyoe
137
+ * // { boolean } - true if number, false if not
138
+ */
139
+ export declare function isNumber(value: any, strict?: any): boolean;
140
+ /**
141
+ * 'isInteger' utility function
142
+ *
143
+ * Checks if a value is an integer.
144
+ *
145
+ * // value - the value to check
146
+ * // { any = false } strict - if truthy, also checks JavaScript tyoe
147
+ * // {boolean } - true if number, false if not
148
+ */
149
+ export declare function isInteger(value: any, strict?: any): boolean;
150
+ /**
151
+ * 'isBoolean' utility function
152
+ *
153
+ * Checks if a value is a boolean.
154
+ *
155
+ * // value - the value to check
156
+ * // { any = null } option - if 'strict', also checks JavaScript type
157
+ * if TRUE or FALSE, checks only for that value
158
+ * // { boolean } - true if boolean, false if not
159
+ */
160
+ export declare function isBoolean(value: any, option?: any): boolean;
161
+ export declare function isFunction(item: any): boolean;
162
+ export declare function isObject(item: any): boolean;
163
+ export declare function isArray(item: any): boolean;
164
+ export declare function isDate(item: any): boolean;
165
+ export declare function isMap(item: any): boolean;
166
+ export declare function isSet(item: any): boolean;
167
+ export declare function isSymbol(item: any): boolean;
168
+ /**
169
+ * 'getType' function
170
+ *
171
+ * Detects the JSON Schema Type of a value.
172
+ * By default, detects numbers and integers even if formatted as strings.
173
+ * (So all integers are also numbers, and any number may also be a string.)
174
+ * However, it only detects true boolean values (to detect boolean values
175
+ * in non-boolean formats, use isBoolean() instead).
176
+ *
177
+ * If passed a second optional parameter of 'strict', it will only detect
178
+ * numbers and integers if they are formatted as JavaScript numbers.
179
+ *
180
+ * Examples:
181
+ * getType('10.5') = 'number'
182
+ * getType(10.5) = 'number'
183
+ * getType('10') = 'integer'
184
+ * getType(10) = 'integer'
185
+ * getType('true') = 'string'
186
+ * getType(true) = 'boolean'
187
+ * getType(null) = 'null'
188
+ * getType({ }) = 'object'
189
+ * getType([]) = 'array'
190
+ *
191
+ * getType('10.5', 'strict') = 'string'
192
+ * getType(10.5, 'strict') = 'number'
193
+ * getType('10', 'strict') = 'string'
194
+ * getType(10, 'strict') = 'integer'
195
+ * getType('true', 'strict') = 'string'
196
+ * getType(true, 'strict') = 'boolean'
197
+ *
198
+ * // value - value to check
199
+ * // { any = false } strict - if truthy, also checks JavaScript tyoe
200
+ * // { SchemaType }
201
+ */
202
+ export declare function getType(value: any, strict?: any): "null" | "number" | "string" | "integer" | "boolean" | "object" | "array";
203
+ /**
204
+ * 'isType' function
205
+ *
206
+ * Checks wether an input (probably string) value contains data of
207
+ * a specified JSON Schema type
208
+ *
209
+ * // { PrimitiveValue } value - value to check
210
+ * // { SchemaPrimitiveType } type - type to check
211
+ * // { boolean }
212
+ */
213
+ export declare function isType(value: any, type: any): boolean;
214
+ /**
215
+ * 'isPrimitive' function
216
+ *
217
+ * Checks wether an input value is a JavaScript primitive type:
218
+ * string, number, boolean, or null.
219
+ *
220
+ * // value - value to check
221
+ * // { boolean }
222
+ */
223
+ export declare function isPrimitive(value: any): boolean;
224
+ /**
225
+ *
226
+ * @param date
227
+ * @returns {string}
228
+ * exmaple:
229
+ * toDateString('2018-01-01') = '2018-01-01'
230
+ * toDateString('2018-01-30T00:00:00.000Z') = '2018-01-30'
231
+ */
232
+ export declare const toIsoString: (date: Date) => string;
233
+ /**
234
+ * 'toJavaScriptType' function
235
+ *
236
+ * Converts an input (probably string) value to a JavaScript primitive type -
237
+ * 'string', 'number', 'boolean', or 'null' - before storing in a JSON object.
238
+ *
239
+ * Does not coerce values (other than null), and only converts the types
240
+ * of values that would otherwise be valid.
241
+ *
242
+ * If the optional third parameter 'strictIntegers' is TRUE, and the
243
+ * JSON Schema type 'integer' is specified, it also verifies the input value
244
+ * is an integer and, if it is, returns it as a JaveScript number.
245
+ * If 'strictIntegers' is FALSE (or not set) the type 'integer' is treated
246
+ * exactly the same as 'number', and allows decimals.
247
+ *
248
+ * Valid Examples:
249
+ * toJavaScriptType('10', 'number' ) = 10 // '10' is a number
250
+ * toJavaScriptType('10', 'integer') = 10 // '10' is also an integer
251
+ * toJavaScriptType( 10, 'integer') = 10 // 10 is still an integer
252
+ * toJavaScriptType( 10, 'string' ) = '10' // 10 can be made into a string
253
+ * toJavaScriptType('10.5', 'number' ) = 10.5 // '10.5' is a number
254
+ *
255
+ * Invalid Examples:
256
+ * toJavaScriptType('10.5', 'integer') = null // '10.5' is not an integer
257
+ * toJavaScriptType( 10.5, 'integer') = null // 10.5 is still not an integer
258
+ *
259
+ * // { PrimitiveValue } value - value to convert
260
+ * // { SchemaPrimitiveType | SchemaPrimitiveType[] } types - types to convert to
261
+ * // { boolean = false } strictIntegers - if FALSE, treat integers as numbers
262
+ * // { PrimitiveValue }
263
+ */
264
+ export declare function toJavaScriptType(value: any, types: any, strictIntegers?: boolean): any;
265
+ /**
266
+ * 'toSchemaType' function
267
+ *
268
+ * Converts an input (probably string) value to the "best" JavaScript
269
+ * equivalent available from an allowed list of JSON Schema types, which may
270
+ * contain 'string', 'number', 'integer', 'boolean', and/or 'null'.
271
+ * If necssary, it does progressively agressive type coersion.
272
+ * It will not return null unless null is in the list of allowed types.
273
+ *
274
+ * Number conversion examples:
275
+ * toSchemaType('10', ['number','integer','string']) = 10 // integer
276
+ * toSchemaType('10', ['number','string']) = 10 // number
277
+ * toSchemaType('10', ['string']) = '10' // string
278
+ * toSchemaType('10.5', ['number','integer','string']) = 10.5 // number
279
+ * toSchemaType('10.5', ['integer','string']) = '10.5' // string
280
+ * toSchemaType('10.5', ['integer']) = 10 // integer
281
+ * toSchemaType(10.5, ['null','boolean','string']) = '10.5' // string
282
+ * toSchemaType(10.5, ['null','boolean']) = true // boolean
283
+ *
284
+ * String conversion examples:
285
+ * toSchemaType('1.5x', ['boolean','number','integer','string']) = '1.5x' // string
286
+ * toSchemaType('1.5x', ['boolean','number','integer']) = '1.5' // number
287
+ * toSchemaType('1.5x', ['boolean','integer']) = '1' // integer
288
+ * toSchemaType('1.5x', ['boolean']) = true // boolean
289
+ * toSchemaType('xyz', ['number','integer','boolean','null']) = true // boolean
290
+ * toSchemaType('xyz', ['number','integer','null']) = null // null
291
+ * toSchemaType('xyz', ['number','integer']) = 0 // number
292
+ *
293
+ * Boolean conversion examples:
294
+ * toSchemaType('1', ['integer','number','string','boolean']) = 1 // integer
295
+ * toSchemaType('1', ['number','string','boolean']) = 1 // number
296
+ * toSchemaType('1', ['string','boolean']) = '1' // string
297
+ * toSchemaType('1', ['boolean']) = true // boolean
298
+ * toSchemaType('true', ['number','string','boolean']) = 'true' // string
299
+ * toSchemaType('true', ['boolean']) = true // boolean
300
+ * toSchemaType('true', ['number']) = 0 // number
301
+ * toSchemaType(true, ['number','string','boolean']) = true // boolean
302
+ * toSchemaType(true, ['number','string']) = 'true' // string
303
+ * toSchemaType(true, ['number']) = 1 // number
304
+ *
305
+ * // { PrimitiveValue } value - value to convert
306
+ * // { SchemaPrimitiveType | SchemaPrimitiveType[] } types - allowed types to convert to
307
+ * // { PrimitiveValue }
308
+ */
309
+ export declare function toSchemaType(value: any, types: any): any;
310
+ /**
311
+ * 'isPromise' function
312
+ *
313
+ * // object
314
+ * // { boolean }
315
+ */
316
+ export declare function isPromise(object: any): object is Promise<any>;
317
+ /**
318
+ * 'isObservable' function
319
+ *
320
+ * // object
321
+ * // { boolean }
322
+ */
323
+ export declare function isObservable(object: any): object is Observable<any>;
324
+ /**
325
+ * '_toPromise' function
326
+ *
327
+ * // { object } object
328
+ * // { Promise<any> }
329
+ */
330
+ export declare function _toPromise(object: any): Promise<any>;
331
+ /**
332
+ * 'toObservable' function
333
+ *
334
+ * // { object } object
335
+ * // { Observable<any> }
336
+ */
337
+ export declare function toObservable(object: any): Observable<any>;
338
+ /**
339
+ * 'inArray' function
340
+ *
341
+ * Searches an array for an item, or one of a list of items, and returns true
342
+ * as soon as a match is found, or false if no match.
343
+ *
344
+ * If the optional third parameter allIn is set to TRUE, and the item to find
345
+ * is an array, then the function returns true only if all elements from item
346
+ * are found in the array list, and false if any element is not found. If the
347
+ * item to find is not an array, setting allIn to TRUE has no effect.
348
+ *
349
+ * // { any|any[] } item - the item to search for
350
+ * // array - the array to search
351
+ * // { boolean = false } allIn - if TRUE, all items must be in array
352
+ * // { boolean } - true if item(s) in array, false otherwise
353
+ */
354
+ export declare function inArray(item: any, array: any, allIn?: boolean): any;
355
+ /**
356
+ * 'xor' utility function - exclusive or
357
+ *
358
+ * Returns true if exactly one of two values is truthy.
359
+ *
360
+ * // value1 - first value to check
361
+ * // value2 - second value to check
362
+ * // { boolean } - true if exactly one input value is truthy, false if not
363
+ */
364
+ export declare function xor(value1: any, value2: any): boolean;