@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,373 +0,0 @@
1
- import {hasValue, inArray, isArray, isDefined, isEmpty, isMap, isObject, isSet, isString, PlainObject} from './validator.functions';
2
-
3
- /**
4
- * Utility function library:
5
- *
6
- * addClasses, copy, forEach, forEachCopy, hasOwn, mergeFilteredObject,
7
- * uniqueItems, commonItems, fixTitle, toTitleCase
8
- */
9
-
10
- /**
11
- * 'addClasses' function
12
- *
13
- * Merges two space-delimited lists of CSS classes and removes duplicates.
14
- *
15
- * // {string | string[] | Set<string>} oldClasses
16
- * // {string | string[] | Set<string>} newClasses
17
- * // {string | string[] | Set<string>} - Combined classes
18
- */
19
- export function addClasses(
20
- oldClasses: string | string[] | Set<string>,
21
- newClasses: string | string[] | Set<string>
22
- ): string | string[] | Set<string> {
23
- const badType = i => !isSet(i) && !isArray(i) && !isString(i);
24
- if (badType(newClasses)) { return oldClasses; }
25
- if (badType(oldClasses)) { oldClasses = ''; }
26
- const toSet = i => isSet(i) ? i : isArray(i) ? new Set(i) : new Set(i.split(' '));
27
- const combinedSet: Set<any> = toSet(oldClasses);
28
- const newSet: Set<any> = toSet(newClasses);
29
- newSet.forEach(c => combinedSet.add(c));
30
- if (isSet(oldClasses)) { return combinedSet; }
31
- if (isArray(oldClasses)) { return Array.from(combinedSet); }
32
- return Array.from(combinedSet).join(' ');
33
- }
34
-
35
- /**
36
- * 'copy' function
37
- *
38
- * Makes a shallow copy of a JavaScript object, array, Map, or Set.
39
- * If passed a JavaScript primitive value (string, number, boolean, or null),
40
- * it returns the value.
41
- *
42
- * // {Object|Array|string|number|boolean|null} object - The object to copy
43
- * // {boolean = false} errors - Show errors?
44
- * // {Object|Array|string|number|boolean|null} - The copied object
45
- */
46
- export function copy(object: any, errors = false): any {
47
- if (typeof object !== 'object' || object === null) { return object; }
48
- if (isMap(object)) { return new Map(object); }
49
- if (isSet(object)) { return new Set(object); }
50
- if (isArray(object)) { return [ ...object ]; }
51
- if (isObject(object)) { return { ...object }; }
52
- if (errors) {
53
- console.error('copy error: Object to copy must be a JavaScript object or value.');
54
- }
55
- return object;
56
- }
57
-
58
- /**
59
- * 'forEach' function
60
- *
61
- * Iterates over all items in the first level of an object or array
62
- * and calls an iterator funciton on each item.
63
- *
64
- * The iterator function is called with four values:
65
- * 1. The current item's value
66
- * 2. The current item's key
67
- * 3. The parent object, which contains the current item
68
- * 4. The root object
69
- *
70
- * Setting the optional third parameter to 'top-down' or 'bottom-up' will cause
71
- * it to also recursively iterate over items in sub-objects or sub-arrays in the
72
- * specified direction.
73
- *
74
- * // {Object|Array} object - The object or array to iterate over
75
- * // {function} fn - the iterator funciton to call on each item
76
- * // {boolean = false} errors - Show errors?
77
- * // {void}
78
- */
79
- export function forEach(
80
- object: any, fn: (v: any, k?: string | number, c?: any, rc?: any) => any,
81
- recurse: boolean | string = false, rootObject: any = object, errors = false
82
- ): void {
83
- if (isEmpty(object)) { return; }
84
- if ((isObject(object) || isArray(object)) && typeof fn === 'function') {
85
- for (const key of Object.keys(object)) {
86
- const value = object[key];
87
- if (recurse === 'bottom-up' && (isObject(value) || isArray(value))) {
88
- forEach(value, fn, recurse, rootObject);
89
- }
90
- fn(value, key, object, rootObject);
91
- if (recurse === 'top-down' && (isObject(value) || isArray(value))) {
92
- forEach(value, fn, recurse, rootObject);
93
- }
94
- }
95
- }
96
- if (errors) {
97
- if (typeof fn !== 'function') {
98
- console.error('forEach error: Iterator must be a function.');
99
- console.error('function', fn);
100
- }
101
- if (!isObject(object) && !isArray(object)) {
102
- console.error('forEach error: Input object must be an object or array.');
103
- console.error('object', object);
104
- }
105
- }
106
- }
107
-
108
- /**
109
- * 'forEachCopy' function
110
- *
111
- * Iterates over all items in the first level of an object or array
112
- * and calls an iterator function on each item. Returns a new object or array
113
- * with the same keys or indexes as the original, and values set to the results
114
- * of the iterator function.
115
- *
116
- * Does NOT recursively iterate over items in sub-objects or sub-arrays.
117
- *
118
- * // {Object | Array} object - The object or array to iterate over
119
- * // {function} fn - The iterator funciton to call on each item
120
- * // {boolean = false} errors - Show errors?
121
- * // {Object | Array} - The resulting object or array
122
- */
123
- export function forEachCopy(
124
- object: any, fn: (v: any, k?: string | number, o?: any, p?: string) => any,
125
- errors = false
126
- ): any {
127
- if (!hasValue(object)) { return; }
128
- if ((isObject(object) || isArray(object)) && typeof object !== 'function') {
129
- const newObject: any = isArray(object) ? [] : {};
130
- for (const key of Object.keys(object)) {
131
- newObject[key] = fn(object[key], key, object);
132
- }
133
- return newObject;
134
- }
135
- if (errors) {
136
- if (typeof fn !== 'function') {
137
- console.error('forEachCopy error: Iterator must be a function.');
138
- console.error('function', fn);
139
- }
140
- if (!isObject(object) && !isArray(object)) {
141
- console.error('forEachCopy error: Input object must be an object or array.');
142
- console.error('object', object);
143
- }
144
- }
145
- }
146
-
147
- /**
148
- * 'hasOwn' utility function
149
- *
150
- * Checks whether an object or array has a particular property.
151
- *
152
- * // {any} object - the object to check
153
- * // {string} property - the property to look for
154
- * // {boolean} - true if object has property, false if not
155
- */
156
- export function hasOwn(object: any, property: string): boolean {
157
- if (!object || !['number', 'string', 'symbol'].includes(typeof property) ||
158
- (!isObject(object) && !isArray(object) && !isMap(object) && !isSet(object))
159
- ) { return false; }
160
- if (isMap(object) || isSet(object)) { return object.has(property); }
161
- if (typeof property === 'number') {
162
- if (isArray(object)) { return object[<number>property]; }
163
- property = property + '';
164
- }
165
- return object.hasOwnProperty(property);
166
- }
167
-
168
- /**
169
- * Types of possible expressions which the app is able to evaluate.
170
- */
171
- export enum ExpressionType {
172
- EQUALS,
173
- NOT_EQUALS,
174
- NOT_AN_EXPRESSION
175
- }
176
-
177
- /**
178
- * Detects the type of expression from the given candidate. `==` for equals,
179
- * `!=` for not equals. If none of these are contained in the candidate, the candidate
180
- * is not considered to be an expression at all and thus `NOT_AN_EXPRESSION` is returned.
181
- * // {expressionCandidate} expressionCandidate - potential expression
182
- */
183
- export function getExpressionType(expressionCandidate: string): ExpressionType {
184
- if (expressionCandidate.indexOf('==') !== -1) {
185
- return ExpressionType.EQUALS;
186
- }
187
-
188
- if (expressionCandidate.toString().indexOf('!=') !== -1) {
189
- return ExpressionType.NOT_EQUALS;
190
- }
191
-
192
- return ExpressionType.NOT_AN_EXPRESSION;
193
- }
194
-
195
- export function isEqual(expressionType) {
196
- return expressionType as ExpressionType === ExpressionType.EQUALS;
197
- }
198
-
199
- export function isNotEqual(expressionType) {
200
- return expressionType as ExpressionType === ExpressionType.NOT_EQUALS;
201
- }
202
-
203
- export function isNotExpression(expressionType) {
204
- return expressionType as ExpressionType === ExpressionType.NOT_AN_EXPRESSION;
205
- }
206
-
207
- /**
208
- * Splits the expression key by the expressionType on a pair of values
209
- * before and after the equals or nor equals sign.
210
- * // {expressionType} enum of an expression type
211
- * // {key} the given key from a for loop iver all conditions
212
- */
213
- export function getKeyAndValueByExpressionType(expressionType: ExpressionType, key: string) {
214
- if (isEqual(expressionType)) {
215
- return key.split('==', 2);
216
- }
217
-
218
- if (isNotEqual(expressionType)) {
219
- return key.split('!=', 2);
220
- }
221
-
222
- return null;
223
- }
224
-
225
- export function cleanValueOfQuotes(keyAndValue): String {
226
- if (keyAndValue.charAt(0) === '\'' && keyAndValue.charAt(keyAndValue.length - 1) === '\'') {
227
- return keyAndValue.replace('\'', '').replace('\'', '');
228
- }
229
- return keyAndValue;
230
- }
231
-
232
- /**
233
- * 'mergeFilteredObject' utility function
234
- *
235
- * Shallowly merges two objects, setting key and values from source object
236
- * in target object, excluding specified keys.
237
- *
238
- * Optionally, it can also use functions to transform the key names and/or
239
- * the values of the merging object.
240
- *
241
- * // {PlainObject} targetObject - Target object to add keys and values to
242
- * // {PlainObject} sourceObject - Source object to copy keys and values from
243
- * // {string[]} excludeKeys - Array of keys to exclude
244
- * // {(string: string) => string = (k) => k} keyFn - Function to apply to keys
245
- * // {(any: any) => any = (v) => v} valueFn - Function to apply to values
246
- * // {PlainObject} - Returns targetObject
247
- */
248
- export function mergeFilteredObject(
249
- targetObject: PlainObject,
250
- sourceObject: PlainObject,
251
- excludeKeys = <string[]>[],
252
- keyFn = (key: string): string => key,
253
- valFn = (val: any): any => val
254
- ): PlainObject {
255
- if (!isObject(sourceObject)) { return targetObject; }
256
- if (!isObject(targetObject)) { targetObject = {}; }
257
- for (const key of Object.keys(sourceObject)) {
258
- if (!inArray(key, excludeKeys) && isDefined(sourceObject[key])) {
259
- targetObject[keyFn(key)] = valFn(sourceObject[key]);
260
- }
261
- }
262
- return targetObject;
263
- }
264
-
265
- /**
266
- * 'uniqueItems' function
267
- *
268
- * Accepts any number of string value inputs,
269
- * and returns an array of all input vaues, excluding duplicates.
270
- *
271
- * // {...string} ...items -
272
- * // {string[]} -
273
- */
274
- export function uniqueItems(...items): string[] {
275
- const returnItems = [];
276
- for (const item of items) {
277
- if (!returnItems.includes(item)) { returnItems.push(item); }
278
- }
279
- return returnItems;
280
- }
281
-
282
- /**
283
- * 'commonItems' function
284
- *
285
- * Accepts any number of strings or arrays of string values,
286
- * and returns a single array containing only values present in all inputs.
287
- *
288
- * // {...string|string[]} ...arrays -
289
- * // {string[]} -
290
- */
291
- export function commonItems(...arrays): string[] {
292
- let returnItems = null;
293
- for (let array of arrays) {
294
- if (isString(array)) { array = [array]; }
295
- returnItems = returnItems === null ? [ ...array ] :
296
- returnItems.filter(item => array.includes(item));
297
- if (!returnItems.length) { return []; }
298
- }
299
- return returnItems;
300
- }
301
-
302
- /**
303
- * 'fixTitle' function
304
- *
305
- *
306
- * // {string} input -
307
- * // {string} -
308
- */
309
- export function fixTitle(name: string): string {
310
- return name && toTitleCase(name.replace(/([a-z])([A-Z])/g, '$1 $2').replace(/_/g, ' '));
311
- }
312
-
313
- /**
314
- * 'toTitleCase' function
315
- *
316
- * Intelligently converts an input string to Title Case.
317
- *
318
- * Accepts an optional second parameter with a list of additional
319
- * words and abbreviations to force into a particular case.
320
- *
321
- * This function is built on prior work by John Gruber and David Gouch:
322
- * http://daringfireball.net/2008/08/title_case_update
323
- * https://github.com/gouch/to-title-case
324
- *
325
- * // {string} input -
326
- * // {string|string[]} forceWords? -
327
- * // {string} -
328
- */
329
- export function toTitleCase(input: string, forceWords?: string|string[]): string {
330
- if (!isString(input)) { return input; }
331
- let forceArray: string[] = ['a', 'an', 'and', 'as', 'at', 'but', 'by', 'en',
332
- 'for', 'if', 'in', 'nor', 'of', 'on', 'or', 'per', 'the', 'to', 'v', 'v.',
333
- 'vs', 'vs.', 'via'];
334
- if (isString(forceWords)) { forceWords = (<string>forceWords).split('|'); }
335
- if (isArray(forceWords)) { forceArray = forceArray.concat(forceWords); }
336
- const forceArrayLower: string[] = forceArray.map(w => w.toLowerCase());
337
- const noInitialCase: boolean =
338
- input === input.toUpperCase() || input === input.toLowerCase();
339
- let prevLastChar = '';
340
- input = input.trim();
341
- return input.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, (word, idx) => {
342
- if (!noInitialCase && word.slice(1).search(/[A-Z]|\../) !== -1) {
343
- return word;
344
- } else {
345
- let newWord: string;
346
- const forceWord: string =
347
- forceArray[forceArrayLower.indexOf(word.toLowerCase())];
348
- if (!forceWord) {
349
- if (noInitialCase) {
350
- if (word.slice(1).search(/\../) !== -1) {
351
- newWord = word.toLowerCase();
352
- } else {
353
- newWord = word[0].toUpperCase() + word.slice(1).toLowerCase();
354
- }
355
- } else {
356
- newWord = word[0].toUpperCase() + word.slice(1);
357
- }
358
- } else if (
359
- forceWord === forceWord.toLowerCase() && (
360
- idx === 0 || idx + word.length === input.length ||
361
- prevLastChar === ':' || input[idx - 1].search(/[^\s-]/) !== -1 ||
362
- (input[idx - 1] !== '-' && input[idx + word.length] === '-')
363
- )
364
- ) {
365
- newWord = forceWord[0].toUpperCase() + forceWord.slice(1);
366
- } else {
367
- newWord = forceWord;
368
- }
369
- prevLastChar = word.slice(-1);
370
- return newWord;
371
- }
372
- });
373
- }
@@ -1,55 +0,0 @@
1
- import {
2
- toIsoString,
3
- toJavaScriptType,
4
- toSchemaType,
5
- } from "./validator.functions";
6
-
7
- describe("Validator functions", () => {
8
- describe("toIsoString", () => {
9
- it("should work with timezone", () => {
10
- expect(toIsoString(new Date("05 October 2011 14:48 UTC"))).toEqual(
11
- "2011-10-05"
12
- );
13
- });
14
- });
15
- describe("toJavaScriptType", () => {
16
- it("Converts an input (probably string) value to a JavaScript primitive type 'string', 'number', 'boolean', or 'null' - before storing in a JSON object.", () => {
17
- expect(toJavaScriptType("10", "number")).toEqual(10);
18
- expect(toJavaScriptType("10", "integer")).toEqual(10);
19
- expect(toJavaScriptType(10, "integer")).toEqual(10);
20
- expect(toJavaScriptType(10, "string")).toEqual("10");
21
- expect(toJavaScriptType("10.5", "integer")).toEqual(null);
22
- expect(toJavaScriptType(10.5, "integer")).toEqual(null);
23
- });
24
- });
25
- describe("toSchemaType", () => {
26
- it("Number conversion examples", () => {
27
- expect(toSchemaType(10, ["number", "integer", "string"])).toEqual(10);
28
- expect(toSchemaType(10, ["number", "string"])).toEqual(10);
29
- expect(toSchemaType(10, ["string"])).toEqual("10");
30
- expect(toSchemaType(10.5, ["number", "integer", "string"])).toEqual(10.5);
31
- expect(toSchemaType(10.5, ["integer", "string"])).toEqual("10.5");
32
- expect(toSchemaType(10.5, ["integer"])).toEqual(10);
33
- });
34
- it("Boolean conversion examples", () => {
35
- expect(
36
- toSchemaType("1", ["integer", "number", "string", "boolean"])
37
- ).toEqual("1");
38
- expect(toSchemaType("1", ["string", "boolean"])).toEqual("1");
39
- expect(toSchemaType("1", ["boolean"])).toEqual("1");
40
- expect(toSchemaType("true", ["number", "string", "boolean"])).toEqual(
41
- "true"
42
- );
43
- expect(toSchemaType("true", ["boolean"])).toEqual("true");
44
- expect(toSchemaType("true", ["number"])).toEqual(0);
45
- });
46
- it("string conversion examples", () => {
47
- expect(
48
- toSchemaType("1.58", ["boolean", "number", "integer", "string"])
49
- ).toEqual("1.58");
50
- expect(toSchemaType("1.5", ["boolean", "number", "integer"])).toEqual(
51
- "1.5"
52
- );
53
- });
54
- });
55
- });
@@ -1,59 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- Input,
5
- OnInit
6
- } from '@angular/core';
7
- import { JsonSchemaFormService } from '../json-schema-form.service';
8
-
9
-
10
- @Component({
11
- // tslint:disable-next-line:component-selector
12
- selector: 'add-reference-widget',
13
- template: `
14
- <button *ngIf="showAddButton"
15
- [class]="options?.fieldHtmlClass || ''"
16
- [disabled]="options?.readonly"
17
- (click)="addItem($event)">
18
- <span *ngIf="options?.icon" [class]="options?.icon"></span>
19
- <span *ngIf="options?.title" [innerHTML]="buttonText"></span>
20
- </button>`,
21
- changeDetection: ChangeDetectionStrategy.Default,
22
- })
23
- export class AddReferenceComponent implements OnInit {
24
- options: any;
25
- itemCount: number;
26
- previousLayoutIndex: number[];
27
- previousDataIndex: number[];
28
- @Input() layoutNode: any;
29
- @Input() layoutIndex: number[];
30
- @Input() dataIndex: number[];
31
-
32
- constructor(
33
- private jsf: JsonSchemaFormService
34
- ) { }
35
-
36
- ngOnInit() {
37
- this.options = this.layoutNode.options || {};
38
- }
39
-
40
- get showAddButton(): boolean {
41
- return !this.layoutNode.arrayItem ||
42
- this.layoutIndex[this.layoutIndex.length - 1] < this.options.maxItems;
43
- }
44
-
45
- addItem(event) {
46
- event.preventDefault();
47
- this.jsf.addItem(this);
48
- }
49
-
50
- get buttonText(): string {
51
- const parent: any = {
52
- dataIndex: this.dataIndex.slice(0, -1),
53
- layoutIndex: this.layoutIndex.slice(0, -1),
54
- layoutNode: this.jsf.getParentNode(this)
55
- };
56
- return parent.layoutNode.add ||
57
- this.jsf.setArrayItemTitle(parent, this.layoutNode, this.itemCount);
58
- }
59
- }
@@ -1,54 +0,0 @@
1
- import { AbstractControl } from '@angular/forms';
2
- import { Component, Input, OnInit } from '@angular/core';
3
- import { JsonSchemaFormService } from '../json-schema-form.service';
4
-
5
-
6
- @Component({
7
- // tslint:disable-next-line:component-selector
8
- selector: 'button-widget',
9
- template: `
10
- <div
11
- [class]="options?.htmlClass || ''">
12
- <button
13
- [attr.readonly]="options?.readonly ? 'readonly' : null"
14
- [attr.aria-describedby]="'control' + layoutNode?._id + 'Status'"
15
- [class]="options?.fieldHtmlClass || ''"
16
- [disabled]="controlDisabled"
17
- [name]="controlName"
18
- [type]="layoutNode?.type"
19
- [value]="controlValue"
20
- (click)="updateValue($event)">
21
- <span *ngIf="options?.icon || options?.title"
22
- [class]="options?.icon"
23
- [innerHTML]="options?.title"></span>
24
- </button>
25
- </div>`,
26
- })
27
- export class ButtonComponent implements OnInit {
28
- formControl: AbstractControl;
29
- controlName: string;
30
- controlValue: any;
31
- controlDisabled = false;
32
- boundControl = false;
33
- options: any;
34
- @Input() layoutNode: any;
35
- @Input() layoutIndex: number[];
36
- @Input() dataIndex: number[];
37
-
38
- constructor(
39
- private jsf: JsonSchemaFormService
40
- ) { }
41
-
42
- ngOnInit() {
43
- this.options = this.layoutNode.options || {};
44
- this.jsf.initializeControl(this);
45
- }
46
-
47
- updateValue(event) {
48
- if (typeof this.options.onClick === 'function') {
49
- this.options.onClick(event);
50
- } else {
51
- this.jsf.updateValue(this, event.target.value);
52
- }
53
- }
54
- }
@@ -1,74 +0,0 @@
1
- import { AbstractControl } from '@angular/forms';
2
- import { Component, Input, OnInit } from '@angular/core';
3
- import { JsonSchemaFormService } from '../json-schema-form.service';
4
-
5
-
6
- @Component({
7
- // tslint:disable-next-line:component-selector
8
- selector: 'checkbox-widget',
9
- template: `
10
- <label
11
- [attr.for]="'control' + layoutNode?._id"
12
- [class]="options?.itemLabelHtmlClass || ''">
13
- <input *ngIf="boundControl"
14
- [formControl]="formControl"
15
- [attr.aria-describedby]="'control' + layoutNode?._id + 'Status'"
16
- [class]="(options?.fieldHtmlClass || '') + (isChecked ?
17
- (' ' + (options?.activeClass || '') + ' ' + (options?.style?.selected || '')) :
18
- (' ' + (options?.style?.unselected || '')))"
19
- [id]="'control' + layoutNode?._id"
20
- [name]="controlName"
21
- [readonly]="options?.readonly ? 'readonly' : null"
22
- type="checkbox">
23
- <input *ngIf="!boundControl"
24
- [attr.aria-describedby]="'control' + layoutNode?._id + 'Status'"
25
- [checked]="isChecked ? 'checked' : null"
26
- [class]="(options?.fieldHtmlClass || '') + (isChecked ?
27
- (' ' + (options?.activeClass || '') + ' ' + (options?.style?.selected || '')) :
28
- (' ' + (options?.style?.unselected || '')))"
29
- [disabled]="controlDisabled"
30
- [id]="'control' + layoutNode?._id"
31
- [name]="controlName"
32
- [readonly]="options?.readonly ? 'readonly' : null"
33
- [value]="controlValue"
34
- type="checkbox"
35
- (change)="updateValue($event)">
36
- <span *ngIf="options?.title"
37
- [style.display]="options?.notitle ? 'none' : ''"
38
- [innerHTML]="options?.title"></span>
39
- </label>`,
40
- })
41
- export class CheckboxComponent implements OnInit {
42
- formControl: AbstractControl;
43
- controlName: string;
44
- controlValue: any;
45
- controlDisabled = false;
46
- boundControl = false;
47
- options: any;
48
- trueValue: any = true;
49
- falseValue: any = false;
50
- @Input() layoutNode: any;
51
- @Input() layoutIndex: number[];
52
- @Input() dataIndex: number[];
53
-
54
- constructor(
55
- private jsf: JsonSchemaFormService
56
- ) { }
57
-
58
- ngOnInit() {
59
- this.options = this.layoutNode.options || {};
60
- this.jsf.initializeControl(this);
61
- if (this.controlValue === null || this.controlValue === undefined) {
62
- this.controlValue = this.options.title;
63
- }
64
- }
65
-
66
- updateValue(event) {
67
- event.preventDefault();
68
- this.jsf.updateValue(this, event.target.checked ? this.trueValue : this.falseValue);
69
- }
70
-
71
- get isChecked() {
72
- return this.jsf.getFormControlValue(this) === this.trueValue;
73
- }
74
- }