@esri/solution-common 5.2.3 → 5.2.5

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 (190) hide show
  1. package/dist/cjs/completeItem.d.ts +29 -0
  2. package/dist/cjs/completeItem.js +92 -0
  3. package/dist/cjs/completeItem.js.map +1 -0
  4. package/dist/cjs/create-hub-request-options.d.ts +29 -0
  5. package/dist/cjs/create-hub-request-options.js +64 -0
  6. package/dist/cjs/create-hub-request-options.js.map +1 -0
  7. package/dist/cjs/deleteHelpers/deleteEmptyGroups.d.ts +24 -0
  8. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js +42 -0
  9. package/dist/cjs/deleteHelpers/deleteEmptyGroups.js.map +1 -0
  10. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.d.ts +27 -0
  11. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js +97 -0
  12. package/dist/cjs/deleteHelpers/deleteGroupIfEmpty.js.map +1 -0
  13. package/dist/cjs/deleteHelpers/deleteSolutionContents.d.ts +38 -0
  14. package/dist/cjs/deleteHelpers/deleteSolutionContents.js +130 -0
  15. package/dist/cjs/deleteHelpers/deleteSolutionContents.js.map +1 -0
  16. package/dist/cjs/deleteHelpers/deleteSolutionFolder.d.ts +29 -0
  17. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js +79 -0
  18. package/dist/cjs/deleteHelpers/deleteSolutionFolder.js.map +1 -0
  19. package/dist/cjs/deleteHelpers/deleteSolutionItem.d.ts +30 -0
  20. package/dist/cjs/deleteHelpers/deleteSolutionItem.js +54 -0
  21. package/dist/cjs/deleteHelpers/deleteSolutionItem.js.map +1 -0
  22. package/dist/cjs/deleteHelpers/index.d.ts +22 -0
  23. package/dist/cjs/deleteHelpers/index.js +26 -0
  24. package/dist/cjs/deleteHelpers/index.js.map +1 -0
  25. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.d.ts +27 -0
  26. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js +34 -0
  27. package/dist/cjs/deleteHelpers/reconstructBuildOrderIds.js.map +1 -0
  28. package/dist/cjs/deleteHelpers/removeItems.d.ts +34 -0
  29. package/dist/cjs/deleteHelpers/removeItems.js +112 -0
  30. package/dist/cjs/deleteHelpers/removeItems.js.map +1 -0
  31. package/dist/cjs/deleteHelpers/reportProgress.d.ts +27 -0
  32. package/dist/cjs/deleteHelpers/reportProgress.js +46 -0
  33. package/dist/cjs/deleteHelpers/reportProgress.js.map +1 -0
  34. package/dist/cjs/deleteSolution.d.ts +55 -0
  35. package/dist/cjs/deleteSolution.js +107 -0
  36. package/dist/cjs/deleteSolution.js.map +1 -0
  37. package/dist/cjs/dependencies.d.ts +26 -0
  38. package/dist/cjs/dependencies.js +171 -0
  39. package/dist/cjs/dependencies.js.map +1 -0
  40. package/dist/cjs/featureServiceHelpers.d.ts +799 -0
  41. package/dist/cjs/featureServiceHelpers.js +2438 -0
  42. package/dist/cjs/featureServiceHelpers.js.map +1 -0
  43. package/dist/cjs/formHelpers.d.ts +41 -0
  44. package/dist/cjs/formHelpers.js +78 -0
  45. package/dist/cjs/formHelpers.js.map +1 -0
  46. package/dist/cjs/generalHelpers.d.ts +433 -0
  47. package/dist/cjs/generalHelpers.js +925 -0
  48. package/dist/cjs/generalHelpers.js.map +1 -0
  49. package/dist/cjs/get-subscription-info.d.ts +27 -0
  50. package/dist/cjs/get-subscription-info.js +39 -0
  51. package/dist/cjs/get-subscription-info.js.map +1 -0
  52. package/dist/cjs/getDeletableSolutionInfo.d.ts +29 -0
  53. package/dist/cjs/getDeletableSolutionInfo.js +53 -0
  54. package/dist/cjs/getDeletableSolutionInfo.js.map +1 -0
  55. package/dist/cjs/getItemTypeAbbrev.d.ts +19 -0
  56. package/dist/cjs/getItemTypeAbbrev.js +186 -0
  57. package/dist/cjs/getItemTypeAbbrev.js.map +1 -0
  58. package/dist/cjs/getSolutionSummary.d.ts +27 -0
  59. package/dist/cjs/getSolutionSummary.js +101 -0
  60. package/dist/cjs/getSolutionSummary.js.map +1 -0
  61. package/dist/cjs/index.d.ts +46 -0
  62. package/dist/cjs/index.js +50 -0
  63. package/dist/cjs/index.js.map +1 -0
  64. package/dist/cjs/interfaces.d.ts +1362 -0
  65. package/dist/cjs/interfaces.js +77 -0
  66. package/dist/cjs/interfaces.js.map +1 -0
  67. package/dist/cjs/libConnectors.d.ts +73 -0
  68. package/dist/cjs/libConnectors.js +115 -0
  69. package/dist/cjs/libConnectors.js.map +1 -0
  70. package/dist/cjs/migrations/apply-schema.d.ts +24 -0
  71. package/dist/cjs/migrations/apply-schema.js +36 -0
  72. package/dist/cjs/migrations/apply-schema.js.map +1 -0
  73. package/dist/cjs/migrations/is-legacy-solution.d.ts +24 -0
  74. package/dist/cjs/migrations/is-legacy-solution.js +40 -0
  75. package/dist/cjs/migrations/is-legacy-solution.js.map +1 -0
  76. package/dist/cjs/migrations/upgrade-three-dot-one.d.ts +27 -0
  77. package/dist/cjs/migrations/upgrade-three-dot-one.js +49 -0
  78. package/dist/cjs/migrations/upgrade-three-dot-one.js.map +1 -0
  79. package/dist/cjs/migrations/upgrade-three-dot-zero.d.ts +27 -0
  80. package/dist/cjs/migrations/upgrade-three-dot-zero.js +43 -0
  81. package/dist/cjs/migrations/upgrade-three-dot-zero.js.map +1 -0
  82. package/dist/cjs/migrations/upgrade-two-dot-five.d.ts +24 -0
  83. package/dist/cjs/migrations/upgrade-two-dot-five.js +73 -0
  84. package/dist/cjs/migrations/upgrade-two-dot-five.js.map +1 -0
  85. package/dist/cjs/migrations/upgrade-two-dot-four.d.ts +24 -0
  86. package/dist/cjs/migrations/upgrade-two-dot-four.js +72 -0
  87. package/dist/cjs/migrations/upgrade-two-dot-four.js.map +1 -0
  88. package/dist/cjs/migrations/upgrade-two-dot-one.d.ts +7 -0
  89. package/dist/cjs/migrations/upgrade-two-dot-one.js +39 -0
  90. package/dist/cjs/migrations/upgrade-two-dot-one.js.map +1 -0
  91. package/dist/cjs/migrations/upgrade-two-dot-seven.d.ts +23 -0
  92. package/dist/cjs/migrations/upgrade-two-dot-seven.js +58 -0
  93. package/dist/cjs/migrations/upgrade-two-dot-seven.js.map +1 -0
  94. package/dist/cjs/migrations/upgrade-two-dot-six.d.ts +27 -0
  95. package/dist/cjs/migrations/upgrade-two-dot-six.js +61 -0
  96. package/dist/cjs/migrations/upgrade-two-dot-six.js.map +1 -0
  97. package/dist/cjs/migrations/upgrade-two-dot-three.d.ts +23 -0
  98. package/dist/cjs/migrations/upgrade-two-dot-three.js +55 -0
  99. package/dist/cjs/migrations/upgrade-two-dot-three.js.map +1 -0
  100. package/dist/cjs/migrations/upgrade-two-dot-two.d.ts +23 -0
  101. package/dist/cjs/migrations/upgrade-two-dot-two.js +58 -0
  102. package/dist/cjs/migrations/upgrade-two-dot-two.js.map +1 -0
  103. package/dist/cjs/migrations/upgrade-two-dot-zero.d.ts +44 -0
  104. package/dist/cjs/migrations/upgrade-two-dot-zero.js +95 -0
  105. package/dist/cjs/migrations/upgrade-two-dot-zero.js.map +1 -0
  106. package/dist/cjs/migrator.d.ts +25 -0
  107. package/dist/cjs/migrator.js +77 -0
  108. package/dist/cjs/migrator.js.map +1 -0
  109. package/dist/cjs/resourceHelpers.d.ts +191 -0
  110. package/dist/cjs/resourceHelpers.js +384 -0
  111. package/dist/cjs/resourceHelpers.js.map +1 -0
  112. package/dist/cjs/resources/add-resource-from-blob.d.ts +26 -0
  113. package/dist/cjs/resources/add-resource-from-blob.js +52 -0
  114. package/dist/cjs/resources/add-resource-from-blob.js.map +1 -0
  115. package/dist/cjs/resources/addMetadataFromBlob.d.ts +25 -0
  116. package/dist/cjs/resources/addMetadataFromBlob.js +43 -0
  117. package/dist/cjs/resources/addMetadataFromBlob.js.map +1 -0
  118. package/dist/cjs/resources/convert-item-resource-to-storage-resource.d.ts +32 -0
  119. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js +70 -0
  120. package/dist/cjs/resources/convert-item-resource-to-storage-resource.js.map +1 -0
  121. package/dist/cjs/resources/convert-storage-resource-to-item-resource.d.ts +29 -0
  122. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js +70 -0
  123. package/dist/cjs/resources/convert-storage-resource-to-item-resource.js.map +1 -0
  124. package/dist/cjs/resources/copyAssociatedFiles.d.ts +67 -0
  125. package/dist/cjs/resources/copyAssociatedFiles.js +304 -0
  126. package/dist/cjs/resources/copyAssociatedFiles.js.map +1 -0
  127. package/dist/cjs/resources/copyDataIntoItem.d.ts +33 -0
  128. package/dist/cjs/resources/copyDataIntoItem.js +62 -0
  129. package/dist/cjs/resources/copyDataIntoItem.js.map +1 -0
  130. package/dist/cjs/resources/copyMetadataIntoItem.d.ts +26 -0
  131. package/dist/cjs/resources/copyMetadataIntoItem.js +46 -0
  132. package/dist/cjs/resources/copyMetadataIntoItem.js.map +1 -0
  133. package/dist/cjs/resources/copyResourceIntoZip.d.ts +33 -0
  134. package/dist/cjs/resources/copyResourceIntoZip.js +78 -0
  135. package/dist/cjs/resources/copyResourceIntoZip.js.map +1 -0
  136. package/dist/cjs/resources/copyZipIntoItem.d.ts +25 -0
  137. package/dist/cjs/resources/copyZipIntoItem.js +54 -0
  138. package/dist/cjs/resources/copyZipIntoItem.js.map +1 -0
  139. package/dist/cjs/resources/createCopyResults.d.ts +25 -0
  140. package/dist/cjs/resources/createCopyResults.js +36 -0
  141. package/dist/cjs/resources/createCopyResults.js.map +1 -0
  142. package/dist/cjs/resources/get-blob.d.ts +26 -0
  143. package/dist/cjs/resources/get-blob.js +27 -0
  144. package/dist/cjs/resources/get-blob.js.map +1 -0
  145. package/dist/cjs/resources/getItemResourcesFilesFromPaths.d.ts +24 -0
  146. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js +49 -0
  147. package/dist/cjs/resources/getItemResourcesFilesFromPaths.js.map +1 -0
  148. package/dist/cjs/resources/getItemResourcesPaths.d.ts +26 -0
  149. package/dist/cjs/resources/getItemResourcesPaths.js +76 -0
  150. package/dist/cjs/resources/getItemResourcesPaths.js.map +1 -0
  151. package/dist/cjs/resources/index.d.ts +29 -0
  152. package/dist/cjs/resources/index.js +33 -0
  153. package/dist/cjs/resources/index.js.map +1 -0
  154. package/dist/cjs/resources/solution-resource.d.ts +35 -0
  155. package/dist/cjs/resources/solution-resource.js +31 -0
  156. package/dist/cjs/resources/solution-resource.js.map +1 -0
  157. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.d.ts +56 -0
  158. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js +146 -0
  159. package/dist/cjs/resources/transform-resource-paths-to-solution-resources.js.map +1 -0
  160. package/dist/cjs/restHelpers.d.ts +607 -0
  161. package/dist/cjs/restHelpers.js +1954 -0
  162. package/dist/cjs/restHelpers.js.map +1 -0
  163. package/dist/cjs/restHelpersGet.d.ts +288 -0
  164. package/dist/cjs/restHelpersGet.js +804 -0
  165. package/dist/cjs/restHelpersGet.js.map +1 -0
  166. package/dist/cjs/sharing/index.d.ts +16 -0
  167. package/dist/cjs/sharing/index.js +20 -0
  168. package/dist/cjs/sharing/index.js.map +1 -0
  169. package/dist/cjs/sharing/share-item-to-groups.d.ts +26 -0
  170. package/dist/cjs/sharing/share-item-to-groups.js +44 -0
  171. package/dist/cjs/sharing/share-item-to-groups.js.map +1 -0
  172. package/dist/cjs/templatization.d.ts +139 -0
  173. package/dist/cjs/templatization.js +316 -0
  174. package/dist/cjs/templatization.js.map +1 -0
  175. package/dist/cjs/trackingHelpers.d.ts +116 -0
  176. package/dist/cjs/trackingHelpers.js +217 -0
  177. package/dist/cjs/trackingHelpers.js.map +1 -0
  178. package/dist/cjs/velocityHelpers.d.ts +57 -0
  179. package/dist/cjs/velocityHelpers.js +135 -0
  180. package/dist/cjs/velocityHelpers.js.map +1 -0
  181. package/dist/cjs/workflowHelpers.d.ts +37 -0
  182. package/dist/cjs/workflowHelpers.js +77 -0
  183. package/dist/cjs/workflowHelpers.js.map +1 -0
  184. package/dist/cjs/workforceHelpers.d.ts +115 -0
  185. package/dist/cjs/workforceHelpers.js +749 -0
  186. package/dist/cjs/workforceHelpers.js.map +1 -0
  187. package/dist/cjs/zip-utils.d.ts +76 -0
  188. package/dist/cjs/zip-utils.js +142 -0
  189. package/dist/cjs/zip-utils.js.map +1 -0
  190. package/package.json +2 -2
@@ -0,0 +1,925 @@
1
+ "use strict";
2
+ /** @license
3
+ * Copyright 2018 Esri
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports._padPositiveNum = exports._getRandomNumberInRange = exports.uniqueStringList = exports.regExTest = exports.getTemplateById = exports.cleanLayerId = exports.cleanLayerBasedItemId = exports.cleanItemId = exports.hasDatasource = exports.globalStringReplace = exports.getUniqueTitle = exports.hasTypeKeyword = exports.hasAnyKeyword = exports.getUTCTimestamp = exports.setProp = exports.setCreateProp = exports.idTest = exports.getPropWithDefault = exports.getProps = exports.getProp = exports.getIDs = exports.getSubgroupIds = exports.failWithIds = exports.fail = exports.deleteProps = exports.deleteProp = exports.deleteItemProps = exports.sanitizeJSONAndReportChanges = exports.compareJSONProperties = exports.compareJSONNoEmptyStrings = exports.compareJSON = exports.cloneObject = exports.saveBlobAsFile = exports.jsonToJson = exports.jsonToFile = exports.jsonToBlob = exports.getSpecifiedWordRegEx = exports.getAgoIdTemplateRegEx = exports.getAgoIdRegEx = exports.generateEmptyCreationResponse = exports.delay = exports.dedupe = exports.createShortId = exports.createLongId = exports.convertIModel = exports.checkUrlPathTermination = exports.blobToText = exports.blobToFile = exports.blobToJson = exports.appendQueryParam = void 0;
19
+ /**
20
+ * Provides general helper functions.
21
+ *
22
+ * @module generalHelpers
23
+ */
24
+ const hub_common_1 = require("@esri/hub-common");
25
+ const libConnectors_1 = require("./libConnectors");
26
+ // ------------------------------------------------------------------------------------------------------------------ //
27
+ /**
28
+ * Returns a URL with a query parameter appended
29
+ *
30
+ * @param url URL to append to
31
+ * @param parameter Query parameter to append, prefixed with "?" or "&" as appropriate to what url already has
32
+ * @returns New URL combining url and parameter
33
+ */
34
+ function appendQueryParam(url, parameter) {
35
+ return url + (url.indexOf("?") === -1 ? "?" : "&") + parameter;
36
+ }
37
+ exports.appendQueryParam = appendQueryParam;
38
+ /**
39
+ * Extracts JSON from a Blob.
40
+ *
41
+ * @param blob Blob to use as source
42
+ * @returns A promise that will resolve with JSON or null
43
+ */
44
+ function blobToJson(blob) {
45
+ return new Promise(resolve => {
46
+ blobToText(blob).then(blobContents => {
47
+ try {
48
+ resolve(JSON.parse(blobContents));
49
+ }
50
+ catch (err) {
51
+ resolve(null);
52
+ }
53
+ }, () => resolve(null));
54
+ });
55
+ }
56
+ exports.blobToJson = blobToJson;
57
+ /**
58
+ * Converts a Blob to a File.
59
+ *
60
+ * @param blob Blob to use as source
61
+ * @param filename Name to use for file
62
+ * @param mimeType MIME type to override blob's MIME type
63
+ * @returns File created out of Blob and filename
64
+ */
65
+ function blobToFile(blob, filename, mimeType) {
66
+ return new File([blob], filename ? filename : "", {
67
+ type: mimeType ?? blob.type // Blobs default to type=""
68
+ });
69
+ }
70
+ exports.blobToFile = blobToFile;
71
+ /**
72
+ * Extracts text from a Blob.
73
+ *
74
+ * @param blob Blob to use as source
75
+ * @returns A promise that will resolve with text read from blob
76
+ */
77
+ function blobToText(blob) {
78
+ return new Promise(resolve => {
79
+ const reader = new FileReader();
80
+ reader.onload = function (evt) {
81
+ // Disable needed because Node requires cast
82
+ const blobContents = evt.target.result;
83
+ resolve(blobContents ? blobContents : ""); // not handling ArrayContents variant
84
+ };
85
+ reader.readAsText(blob);
86
+ });
87
+ }
88
+ exports.blobToText = blobToText;
89
+ /**
90
+ * Checks that a URL path ends with a slash.
91
+ *
92
+ * @param url URL to check
93
+ * @returns URL, appended with slash if missing
94
+ */
95
+ function checkUrlPathTermination(url) {
96
+ return url ? (url.endsWith("/") ? url : url + "/") : url;
97
+ }
98
+ exports.checkUrlPathTermination = checkUrlPathTermination;
99
+ /**
100
+ * Converts a hub-style item into a solutions-style item, the difference being handling of resources.
101
+ *
102
+ * @param hubModel Hub-style item
103
+ * @return solutions-style item
104
+ */
105
+ function convertIModel(hubModel) {
106
+ const item = {
107
+ ...hubModel
108
+ };
109
+ item.resources = hubModel?.resources ? Object.values(hubModel.resources) : [];
110
+ return item;
111
+ }
112
+ exports.convertIModel = convertIModel;
113
+ /**
114
+ * Creates a random 32-character alphanumeric string.
115
+ *
116
+ * @returns A lowercase 32-char alphanumeric string
117
+ * @internal
118
+ */
119
+ function createLongId() {
120
+ // createId gets a random number, converts it to base 36 representation, then grabs chars 2-8
121
+ return (0, hub_common_1.createId)("") + (0, hub_common_1.createId)("") + (0, hub_common_1.createId)("") + (0, hub_common_1.createId)("");
122
+ }
123
+ exports.createLongId = createLongId;
124
+ /**
125
+ * Creates a random 8-character alphanumeric string that begins with an alphabetic character.
126
+ *
127
+ * @returns An alphanumeric string in the range [a0000000..zzzzzzzz]
128
+ */
129
+ function createShortId() {
130
+ // Return a random number, but beginning with an alphabetic character so that it can be used as a valid
131
+ // dotable property name. Used for unique identifiers that do not require the rigor of a full UUID -
132
+ // i.e. node ids, process ids, etc.
133
+ const min = 0.2777777777777778; // 0.a in base 36
134
+ const max = 0.9999999999996456; // 0.zzzzzzzz in base 36
135
+ return (_getRandomNumberInRange(min, max).toString(36) + "0000000").substr(2, 8);
136
+ }
137
+ exports.createShortId = createShortId;
138
+ /**
139
+ * Copies an input list removing duplicates.
140
+ *
141
+ * @param input List to be deduped
142
+ * @returns Deduped list; order of items in input is not maintained
143
+ */
144
+ function dedupe(input = []) {
145
+ if (input.length === 0) {
146
+ return [];
147
+ }
148
+ const dedupedList = new Set(input);
149
+ const output = [];
150
+ dedupedList.forEach((value) => output.push(value));
151
+ return output;
152
+ }
153
+ exports.dedupe = dedupe;
154
+ /**
155
+ * Performs an asynchronous delay.
156
+ *
157
+ * @param ms Milliseconds to delay
158
+ * @returns Promise when delay is complete
159
+ */
160
+ function delay(ms) {
161
+ return new Promise(resolve => setTimeout(resolve, ms));
162
+ }
163
+ exports.delay = delay;
164
+ /**
165
+ * Flags a failure to create an item from a template.
166
+ *
167
+ * @param itemType The AGO item type
168
+ * @param id Item id to include in response
169
+ * @returns Empty creation response
170
+ */
171
+ function generateEmptyCreationResponse(itemType, id = "") {
172
+ return {
173
+ item: null,
174
+ id,
175
+ type: itemType,
176
+ postProcess: false
177
+ };
178
+ }
179
+ exports.generateEmptyCreationResponse = generateEmptyCreationResponse;
180
+ /**
181
+ * Returns a regular expression matching a global search for a 32-character AGO-style id.
182
+ *
183
+ * @returns Regular expression
184
+ */
185
+ function getAgoIdRegEx() {
186
+ return /\b([0-9A-Fa-f]){32}\b/g;
187
+ }
188
+ exports.getAgoIdRegEx = getAgoIdRegEx;
189
+ /**
190
+ * Returns a regular expression matching a global search for a 32-character AGO-style id as a Solution template variable.
191
+ *
192
+ * @returns Regular expression
193
+ */
194
+ function getAgoIdTemplateRegEx() {
195
+ return /{{\b([0-9A-Fa-f]){32}\b}}/g;
196
+ }
197
+ exports.getAgoIdTemplateRegEx = getAgoIdTemplateRegEx;
198
+ /**
199
+ * Returns a regular expression matching a global search for a word such as an AGO-style id.
200
+ *
201
+ * @param word Word to search for, bounded by regular expression word boundaries (\b)
202
+ * @returns Regular expression
203
+ */
204
+ function getSpecifiedWordRegEx(word) {
205
+ return new RegExp(`\\b${word}\\b`, "g");
206
+ }
207
+ exports.getSpecifiedWordRegEx = getSpecifiedWordRegEx;
208
+ /**
209
+ * Converts JSON to a Blob.
210
+ *
211
+ * @param json JSON to use as source
212
+ * @returns A blob from the source JSON
213
+ */
214
+ function jsonToBlob(json) {
215
+ const uint8array = new TextEncoder().encode(JSON.stringify(json));
216
+ const blobOptions = { type: "application/octet-stream" };
217
+ return new Blob([uint8array], blobOptions);
218
+ }
219
+ exports.jsonToBlob = jsonToBlob;
220
+ /**
221
+ * Converts JSON to a File.
222
+ *
223
+ * @param json JSON to use as source
224
+ * @param filename Name to use for file
225
+ * @param mimeType MIME type to override blob's MIME type
226
+ * @returns File created out of JSON and filename
227
+ */
228
+ function jsonToFile(json, filename, mimeType = "application/json") {
229
+ return blobToFile(jsonToBlob(json), filename, mimeType);
230
+ }
231
+ exports.jsonToFile = jsonToFile;
232
+ /**
233
+ * Makes a unique copy of JSON by stringifying and parsing.
234
+ *
235
+ * @param json JSON to use as source
236
+ * @returns A JSON object from the source JSON
237
+ */
238
+ function jsonToJson(json) {
239
+ return JSON.parse(JSON.stringify(json));
240
+ }
241
+ exports.jsonToJson = jsonToJson;
242
+ /**
243
+ * Saves a blob to a file.
244
+ *
245
+ * @param filename Name to give file
246
+ * @param blob Blob to save
247
+ * @returns Promise resolving when operation is complete
248
+ */
249
+ // Function is only used for live testing, so excluding it from coverage for now
250
+ /* istanbul ignore next */
251
+ function saveBlobAsFile(filename, blob) {
252
+ return new Promise(resolve => {
253
+ const dataUrl = URL.createObjectURL(blob);
254
+ const linkElement = document.createElement("a");
255
+ linkElement.setAttribute("href", dataUrl);
256
+ linkElement.setAttribute("download", filename);
257
+ linkElement.style.display = "none";
258
+ document.body.appendChild(linkElement);
259
+ linkElement.click();
260
+ document.body.removeChild(linkElement);
261
+ setTimeout(() => {
262
+ URL.revokeObjectURL(dataUrl);
263
+ resolve(null);
264
+ }, 500);
265
+ });
266
+ }
267
+ exports.saveBlobAsFile = saveBlobAsFile;
268
+ /**
269
+ * Makes a deep clone, including arrays but not functions.
270
+ *
271
+ * @param obj Object to be cloned
272
+ * @returns Clone of obj
273
+ * @example
274
+ * ```js
275
+ * import { cloneObject } from "utils/object-helpers";
276
+ * const original = { foo: "bar" }
277
+ * const copy = cloneObject(original)
278
+ * copy.foo // "bar"
279
+ * copy === original // false
280
+ * ```
281
+ */
282
+ function cloneObject(obj) {
283
+ let clone = {};
284
+ // first check array
285
+ if (Array.isArray(obj)) {
286
+ clone = obj.map(cloneObject);
287
+ }
288
+ else if (typeof obj === "object") {
289
+ if (obj instanceof File) {
290
+ const fileOptions = obj.type ? { type: obj.type } : undefined;
291
+ clone = new File([obj], obj.name, fileOptions);
292
+ }
293
+ else {
294
+ for (const i in obj) {
295
+ if (obj[i] != null && typeof obj[i] === "object") {
296
+ clone[i] = cloneObject(obj[i]);
297
+ }
298
+ else {
299
+ clone[i] = obj[i];
300
+ }
301
+ }
302
+ }
303
+ }
304
+ else {
305
+ clone = obj;
306
+ }
307
+ return clone;
308
+ }
309
+ exports.cloneObject = cloneObject;
310
+ /**
311
+ * Compares two JSON objects using JSON.stringify.
312
+ *
313
+ * @param json1 First object
314
+ * @param json2 Second object
315
+ * @returns True if objects are the same
316
+ */
317
+ function compareJSON(json1, json2) {
318
+ return JSON.stringify(json1) === JSON.stringify(json2);
319
+ }
320
+ exports.compareJSON = compareJSON;
321
+ /**
322
+ * Compares two JSON objects using JSON.stringify, converting empty strings to nulls.
323
+ *
324
+ * @param json1 First object
325
+ * @param json2 Second object
326
+ * @returns True if objects are the same
327
+ */
328
+ function compareJSONNoEmptyStrings(json1, json2) {
329
+ const jsonStr1 = JSON.stringify(json1).replace(/":""/g, '":null');
330
+ const jsonStr2 = JSON.stringify(json2).replace(/":""/g, '":null');
331
+ return jsonStr1 === jsonStr2;
332
+ }
333
+ exports.compareJSONNoEmptyStrings = compareJSONNoEmptyStrings;
334
+ /**
335
+ * Compares two JSON objects property by property and reports each mismatch.
336
+ *
337
+ * @param json1 First object
338
+ * @param json2 Second object
339
+ * @returns A list of mismatch report strings
340
+ */
341
+ function compareJSONProperties(json1, json2) {
342
+ let mismatches = [];
343
+ const type1 = _typeof_null(json1);
344
+ const type2 = _typeof_null(json2);
345
+ if (type1 !== type2) {
346
+ // Ignore "undefined" vs. "null" and vice versa
347
+ /* istanbul ignore else */
348
+ if ((type1 !== "undefined" && type1 !== "null") ||
349
+ (type2 !== "null" && type2 !== "undefined")) {
350
+ mismatches.push("Type difference: " + type1 + " vs. " + type2);
351
+ }
352
+ }
353
+ else {
354
+ if (json1 !== json2) {
355
+ switch (type1) {
356
+ case "boolean":
357
+ mismatches.push("Value difference: " + json1 + " vs. " + json2);
358
+ break;
359
+ case "number":
360
+ mismatches.push("Value difference: " + json1 + " vs. " + json2);
361
+ break;
362
+ case "string":
363
+ mismatches.push('String difference: "' + json1 + '" vs. "' + json2 + '"');
364
+ break;
365
+ case "object":
366
+ const keys1 = Object.keys(json1);
367
+ const keys2 = Object.keys(json2);
368
+ if (keys1.length !== keys2.length ||
369
+ JSON.stringify(keys1) !== JSON.stringify(keys2)) {
370
+ if (Array.isArray(json1) && Array.isArray(json2)) {
371
+ mismatches.push("Array length difference: [" +
372
+ keys1.length +
373
+ "] vs. [" +
374
+ keys2.length +
375
+ "]");
376
+ }
377
+ else {
378
+ mismatches.push("Props difference: " +
379
+ JSON.stringify(keys1) +
380
+ " vs. " +
381
+ JSON.stringify(keys2));
382
+ }
383
+ }
384
+ else {
385
+ for (let k = 0; k < keys1.length; ++k) {
386
+ const submismatches = compareJSONProperties(json1[keys1[k]], json2[keys2[k]]);
387
+ if (submismatches.length > 0) {
388
+ mismatches = mismatches.concat(submismatches);
389
+ }
390
+ }
391
+ }
392
+ break;
393
+ }
394
+ }
395
+ }
396
+ return mismatches;
397
+ }
398
+ exports.compareJSONProperties = compareJSONProperties;
399
+ /**
400
+ * Sanitizes JSON and echoes changes to console.
401
+ *
402
+ * @param json JSON to sanitize
403
+ * @param sanitizer Instance of Sanitizer class
404
+ * @returns Sanitized version of `json`
405
+ * @see https://github.com/esri/arcgis-html-sanitizer#sanitize-json
406
+ */
407
+ function sanitizeJSONAndReportChanges(json, sanitizer) {
408
+ const sanitizedJSON = (0, libConnectors_1.sanitizeJSON)(json, sanitizer);
409
+ const mismatches = compareJSONProperties(json, sanitizedJSON);
410
+ if (mismatches.length > 0) {
411
+ console.warn("Changed " +
412
+ mismatches.length +
413
+ (mismatches.length === 1 ? " property" : " properties"));
414
+ mismatches.forEach(mismatch => console.warn(" " + mismatch));
415
+ }
416
+ return sanitizedJSON;
417
+ }
418
+ exports.sanitizeJSONAndReportChanges = sanitizeJSONAndReportChanges;
419
+ function deleteItemProps(itemTemplate) {
420
+ const propsToRetain = [
421
+ "accessInformation",
422
+ "appCategories",
423
+ "banner",
424
+ "categories",
425
+ "culture",
426
+ "description",
427
+ "documentation",
428
+ "extent",
429
+ "groupDesignations",
430
+ "industries",
431
+ "languages",
432
+ "licenseInfo",
433
+ "listed",
434
+ "name",
435
+ "properties",
436
+ "proxyFilter",
437
+ "screenshots",
438
+ "size",
439
+ "snippet",
440
+ "spatialReference",
441
+ "tags",
442
+ "title",
443
+ "type",
444
+ "typeKeywords",
445
+ "url"
446
+ ];
447
+ const propsToDelete = Object.keys(itemTemplate).filter(k => propsToRetain.indexOf(k) < 0);
448
+ deleteProps(itemTemplate, propsToDelete);
449
+ return itemTemplate;
450
+ }
451
+ exports.deleteItemProps = deleteItemProps;
452
+ /**
453
+ * Deletes a property from an object.
454
+ *
455
+ * @param obj Object with property to delete
456
+ * @param path Path into an object to property, e.g., "data.values.webmap", where "data" is a top-level property
457
+ * in obj
458
+ */
459
+ function deleteProp(obj, path) {
460
+ const pathParts = path.split(".");
461
+ if (Array.isArray(obj)) {
462
+ obj.forEach((child) => deleteProp(child, path));
463
+ }
464
+ else {
465
+ const subpath = pathParts.slice(1).join(".");
466
+ if (typeof obj[pathParts[0]] !== "undefined") {
467
+ if (pathParts.length === 1) {
468
+ delete obj[path];
469
+ }
470
+ else {
471
+ deleteProp(obj[pathParts[0]], subpath);
472
+ }
473
+ }
474
+ }
475
+ }
476
+ exports.deleteProp = deleteProp;
477
+ /**
478
+ * Deletes properties from an object.
479
+ *
480
+ * @param obj Object with properties to delete
481
+ * @param props Array of properties on object that should be deleted
482
+ */
483
+ function deleteProps(obj, props) {
484
+ props.forEach(prop => {
485
+ deleteProp(obj, prop);
486
+ });
487
+ }
488
+ exports.deleteProps = deleteProps;
489
+ /**
490
+ * Creates an AGO-style JSON failure response with success property.
491
+ *
492
+ * @param e Optional error information
493
+ * @returns JSON structure with property success set to false and optionally including `e`
494
+ */
495
+ function fail(e) {
496
+ if (e) {
497
+ return { success: false, error: e.response?.error || e.error || e };
498
+ }
499
+ else {
500
+ return { success: false };
501
+ }
502
+ }
503
+ exports.fail = fail;
504
+ /**
505
+ * Creates an AGO-style JSON failure response with success property and extended with ids list.
506
+ *
507
+ * @param ids List of ids
508
+ * @param e Optional error information
509
+ * @returns JSON structure with property success set to false and optionally including `e`
510
+ */
511
+ function failWithIds(itemIds, e) {
512
+ if (e) {
513
+ return { success: false, itemIds, error: e.error || e };
514
+ }
515
+ else {
516
+ return { success: false, itemIds };
517
+ }
518
+ }
519
+ exports.failWithIds = failWithIds;
520
+ /**
521
+ * Extracts subgroup ids from item tags
522
+ *
523
+ * @param tags Tags in an item
524
+ * @returns List of subgroup ids; subgroups are identified using tags that begin with "group." and end with a group id,
525
+ * e.g., "group.8d515625ee9f49d7b4f6c6cb2a389151"; non-matching tags are ignored
526
+ */
527
+ function getSubgroupIds(tags) {
528
+ if (tags) {
529
+ const containedGroupPrefix = "group.";
530
+ return tags
531
+ .filter(tag => tag.startsWith(containedGroupPrefix))
532
+ .map(tag => tag.substring(containedGroupPrefix.length));
533
+ }
534
+ else {
535
+ return [];
536
+ }
537
+ }
538
+ exports.getSubgroupIds = getSubgroupIds;
539
+ /**
540
+ * Extracts the ids from a string
541
+ *
542
+ * @param v String to examine
543
+ * @returns List of id strings found
544
+ * @example
545
+ * get id from
546
+ * bad3483e025c47338d43df308c117308
547
+ * {bad3483e025c47338d43df308c117308
548
+ * =bad3483e025c47338d43df308c117308
549
+ * do not get id from
550
+ * http: *something/name_bad3483e025c47338d43df308c117308
551
+ * {{bad3483e025c47338d43df308c117308.itemId}}
552
+ * bad3483e025c47338d43df308c117308bad3483e025c47338d43df308c117308
553
+ */
554
+ function getIDs(v) {
555
+ // lookbehind is not supported in safari
556
+ // cannot use /(?<!_)(?<!{{)\b[0-9A-F]{32}/gi
557
+ // use groups and filter out the ids that start with {{
558
+ return regExTest(v, /({*)(\b[0-9A-F]{32}\b)/gi).reduce(function (acc, _v) {
559
+ /* istanbul ignore else */
560
+ if (_v.indexOf("{{") < 0) {
561
+ acc.push(_v.replace("{", ""));
562
+ }
563
+ return acc;
564
+ }, []);
565
+ }
566
+ exports.getIDs = getIDs;
567
+ /**
568
+ * Gets a property out of a deeply nested object.
569
+ * Does not handle anything but nested object graph
570
+ *
571
+ * @param obj Object to retrieve value from
572
+ * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property
573
+ * in obj
574
+ * @returns Value at end of path
575
+ */
576
+ function getProp(obj, path) {
577
+ return path.split(".").reduce(function (prev, curr) {
578
+ /* istanbul ignore next no need to test undefined scenario */
579
+ return prev ? prev[curr] : undefined;
580
+ }, obj);
581
+ }
582
+ exports.getProp = getProp;
583
+ /**
584
+ * Returns an array of values from an object based on an array of property paths.
585
+ *
586
+ * @param obj Object to retrieve values from
587
+ * @param props Array of paths into the object e.g., "data.values.webmap", where "data" is a top-level property
588
+ * @returns Array of the values plucked from the object; only defined values are returned
589
+ */
590
+ function getProps(obj, props) {
591
+ return props.reduce((a, p) => {
592
+ const v = getProp(obj, p);
593
+ if (v) {
594
+ a.push(v);
595
+ }
596
+ return a;
597
+ }, []);
598
+ }
599
+ exports.getProps = getProps;
600
+ /**
601
+ * Get a property out of a deeply nested object
602
+ * Does not handle anything but nested object graph
603
+ *
604
+ * @param obj Object to retrieve value from
605
+ * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property
606
+ * in obj
607
+ * @param defaultV Optional value to use if any part of path--including final value--is undefined
608
+ * @returns Value at end of path
609
+ */
610
+ function getPropWithDefault(obj, path, defaultV) {
611
+ const value = path.split(".").reduce(function (prev, curr) {
612
+ /* istanbul ignore next no need to test undefined scenario */
613
+ return prev ? prev[curr] : undefined;
614
+ }, obj);
615
+ if (typeof value === "undefined") {
616
+ return defaultV;
617
+ }
618
+ else {
619
+ return value;
620
+ }
621
+ }
622
+ exports.getPropWithDefault = getPropWithDefault;
623
+ /**
624
+ * Updates a list of the items dependencies if more are found in the
625
+ * provided value.
626
+ *
627
+ * @param v a string value to check for ids
628
+ * @param deps a list of the items dependencies
629
+ */
630
+ function idTest(v, deps) {
631
+ const ids = getIDs(v);
632
+ ids.forEach(id => {
633
+ /* istanbul ignore else */
634
+ if (deps.indexOf(id) === -1) {
635
+ deps.push(id);
636
+ }
637
+ });
638
+ }
639
+ exports.idTest = idTest;
640
+ /**
641
+ * Sets a deeply nested property of an object.
642
+ * Creates the full path if it does not exist.
643
+ *
644
+ * @param obj Object to set value of
645
+ * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property in obj
646
+ * @param value The value to set at the end of the path
647
+ */
648
+ function setCreateProp(obj, path, value) {
649
+ const pathParts = path.split(".");
650
+ pathParts.reduce((a, b, c) => {
651
+ if (c === pathParts.length - 1) {
652
+ a[b] = value;
653
+ return value;
654
+ }
655
+ else {
656
+ if (!a[b]) {
657
+ a[b] = {};
658
+ }
659
+ return a[b];
660
+ }
661
+ }, obj);
662
+ }
663
+ exports.setCreateProp = setCreateProp;
664
+ /**
665
+ * Sets a deeply nested property of an object.
666
+ * Does nothing if the full path does not exist.
667
+ *
668
+ * @param obj Object to set value of
669
+ * @param path Path into an object, e.g., "data.values.webmap", where "data" is a top-level property in obj
670
+ * @param value The value to set at the end of the path
671
+ */
672
+ function setProp(obj, path, value) {
673
+ if (getProp(obj, path)) {
674
+ const pathParts = path.split(".");
675
+ pathParts.reduce((a, b, c) => {
676
+ if (c === pathParts.length - 1) {
677
+ a[b] = value;
678
+ return value;
679
+ }
680
+ else {
681
+ return a[b];
682
+ }
683
+ }, obj);
684
+ }
685
+ }
686
+ exports.setProp = setProp;
687
+ /**
688
+ * Creates a timestamp string using the current UTC date and time.
689
+ *
690
+ * @returns Timestamp formatted as YYYYMMDD_hhmm_ssmmm, with month one-based and all values padded with zeroes on the
691
+ * left as needed (`ssmmm` stands for seconds from 0..59 and milliseconds from 0..999)
692
+ * @private
693
+ */
694
+ function getUTCTimestamp() {
695
+ const now = new Date();
696
+ return (_padPositiveNum(now.getUTCFullYear(), 4) +
697
+ _padPositiveNum(now.getUTCMonth() + 1, 2) +
698
+ _padPositiveNum(now.getUTCDate(), 2) +
699
+ "_" +
700
+ _padPositiveNum(now.getUTCHours(), 2) +
701
+ _padPositiveNum(now.getUTCMinutes(), 2) +
702
+ "_" +
703
+ _padPositiveNum(now.getUTCSeconds(), 2) +
704
+ _padPositiveNum(now.getUTCMilliseconds(), 3));
705
+ }
706
+ exports.getUTCTimestamp = getUTCTimestamp;
707
+ /**
708
+ * Tests if an object's `item.typeKeywords` or `typeKeywords` properties has any of a set of keywords.
709
+ *
710
+ * @param jsonObj Object to test
711
+ * @param keywords List of keywords to look for in jsonObj
712
+ * @returns Boolean indicating result
713
+ */
714
+ function hasAnyKeyword(jsonObj, keywords) {
715
+ const typeKeywords = getProp(jsonObj, "item.typeKeywords") || jsonObj.typeKeywords || [];
716
+ return keywords.reduce((a, kw) => {
717
+ if (!a) {
718
+ a = typeKeywords.includes(kw);
719
+ }
720
+ return a;
721
+ }, false);
722
+ }
723
+ exports.hasAnyKeyword = hasAnyKeyword;
724
+ /**
725
+ * Tests if an object's `item.typeKeywords` or `typeKeywords` properties has a specific keyword.
726
+ *
727
+ * @param jsonObj Object to test
728
+ * @param keyword Keyword to look for in jsonObj
729
+ * @returns Boolean indicating result
730
+ */
731
+ function hasTypeKeyword(jsonObj, keyword) {
732
+ const typeKeywords = getProp(jsonObj, "item.typeKeywords") || jsonObj.typeKeywords || [];
733
+ return typeKeywords.includes(keyword);
734
+ }
735
+ exports.hasTypeKeyword = hasTypeKeyword;
736
+ /**
737
+ * Will return the provided title if it does not exist as a property
738
+ * in one of the objects at the defined path. Otherwise the title will
739
+ * have a numerical value attached.
740
+ *
741
+ * @param title The root title to test
742
+ * @param templateDictionary Hash of the facts
743
+ * @param path to the objects to evaluate for potantial name clashes
744
+ * @returns string The unique title to use
745
+ */
746
+ function getUniqueTitle(title, templateDictionary, path) {
747
+ title = title ? title.trim() : "_";
748
+ const objs = getProp(templateDictionary, path) || [];
749
+ const titles = objs.map(obj => {
750
+ return obj.title;
751
+ });
752
+ let newTitle = title;
753
+ let i = 0;
754
+ while (titles.indexOf(newTitle) > -1) {
755
+ i++;
756
+ newTitle = title + " " + i;
757
+ }
758
+ return newTitle;
759
+ }
760
+ exports.getUniqueTitle = getUniqueTitle;
761
+ /**
762
+ * Performs string replacement on every string in an object.
763
+ *
764
+ * @param obj Object to scan and to modify
765
+ * @param pattern Search pattern in each string
766
+ * @param replacement Replacement for matches to search pattern
767
+ * @returns Modified obj is returned
768
+ */
769
+ function globalStringReplace(obj, pattern, replacement) {
770
+ if (obj) {
771
+ Object.keys(obj).forEach(prop => {
772
+ const propObj = obj[prop];
773
+ if (propObj) {
774
+ /* istanbul ignore else */
775
+ if (typeof propObj === "object") {
776
+ globalStringReplace(propObj, pattern, replacement);
777
+ }
778
+ else if (typeof propObj === "string") {
779
+ obj[prop] = obj[prop].replace(pattern, replacement);
780
+ }
781
+ }
782
+ });
783
+ }
784
+ return obj;
785
+ }
786
+ exports.globalStringReplace = globalStringReplace;
787
+ /**
788
+ * Tests if an array of DatasourceInfos has a given item and layer id already.
789
+ *
790
+ * @param datasourceInfos Array of DatasourceInfos to evaluate
791
+ * @param itemId The items id to check for
792
+ * @param layerId The layers id to check for
793
+ * @returns Boolean indicating result
794
+ */
795
+ function hasDatasource(datasourceInfos, itemId, layerId) {
796
+ return datasourceInfos.some(ds => ds.itemId === itemId && ds.layerId === layerId);
797
+ }
798
+ exports.hasDatasource = hasDatasource;
799
+ /**
800
+ * remove templatization from item id to compare
801
+ *
802
+ * @example
803
+ * \{\{934a9ef8efa7448fa8ddf7b13cef0240.itemId\}\}
804
+ * returns 934a9ef8efa7448fa8ddf7b13cef0240
805
+ */
806
+ function cleanItemId(id) {
807
+ return id ? id.replace("{{", "").replace(".itemId}}", "") : id;
808
+ }
809
+ exports.cleanItemId = cleanItemId;
810
+ /**
811
+ * remove templatization from layer based item id to compare
812
+ *
813
+ * @example
814
+ * \{\{934a9ef8efa7448fa8ddf7b13cef0240.layer0.itemId\}\}
815
+ * returns 934a9ef8efa7448fa8ddf7b13cef0240
816
+ */
817
+ function cleanLayerBasedItemId(id) {
818
+ return id
819
+ ? id
820
+ .replace("{{", "")
821
+ .replace(/([.]layer([0-9]|[1-9][0-9])[.](item|layer)Id)[}]{2}/, "")
822
+ : id;
823
+ }
824
+ exports.cleanLayerBasedItemId = cleanLayerBasedItemId;
825
+ /**
826
+ * remove templatization from layer id to compare
827
+ *
828
+ * @example
829
+ * \{\{934a9ef8efa7448fa8ddf7b13cef0240.layer0.layerId\}\}
830
+ * returns 0
831
+ */
832
+ function cleanLayerId(id) {
833
+ return id?.toString()
834
+ ? parseInt(id
835
+ .toString()
836
+ .replace(/[{]{2}.{32}[.]layer/, "")
837
+ .replace(/[.]layerId[}]{2}/, ""), 10)
838
+ : id;
839
+ }
840
+ exports.cleanLayerId = cleanLayerId;
841
+ /**
842
+ * Get template from list of templates by ID
843
+ *
844
+ * @param templates Array of item templates to search
845
+ * @param id of template we are searching for
846
+ *
847
+ * @returns Template associated with the user provided id argument
848
+ */
849
+ function getTemplateById(templates, id) {
850
+ let template;
851
+ templates.some(_template => {
852
+ if (_template.itemId === id) {
853
+ template = _template;
854
+ return true;
855
+ }
856
+ return false;
857
+ });
858
+ return template;
859
+ }
860
+ exports.getTemplateById = getTemplateById;
861
+ /**
862
+ * Evaluates a value with a regular expression
863
+ *
864
+ * @param v a string value to test with the expression
865
+ * @param ex the regular expresion to test with
866
+ * @returns an array of matches
867
+ */
868
+ function regExTest(v, ex) {
869
+ return v && ex.test(v) ? v.match(ex) : [];
870
+ }
871
+ exports.regExTest = regExTest;
872
+ /**
873
+ * Removes duplicates from a list of strings.
874
+ *
875
+ * @param list List to be de-duped
876
+ * @returns List of unique strings
877
+ */
878
+ function uniqueStringList(list) {
879
+ return list.filter(hub_common_1.unique);
880
+ }
881
+ exports.uniqueStringList = uniqueStringList;
882
+ // ------------------------------------------------------------------------------------------------------------------ //
883
+ /**
884
+ * Creates a random number between two values.
885
+ *
886
+ * @param min Inclusive minimum desired value
887
+ * @param max Non-inclusive maximum desired value
888
+ * @returns Random number in the range [min, max)
889
+ */
890
+ function _getRandomNumberInRange(min, max) {
891
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#Getting_a_random_number_between_two_values
892
+ // © 2006 IvanWills
893
+ // MIT license https://opensource.org/licenses/mit-license.php
894
+ return Math.random() * (max - min) + min;
895
+ }
896
+ exports._getRandomNumberInRange = _getRandomNumberInRange;
897
+ /**
898
+ * Pads the string representation of a number to a minimum width. Requires modern browser.
899
+ *
900
+ * @param n Number to pad
901
+ * @param totalSize Desired *minimum* width of number after padding with zeroes
902
+ * @returns Number converted to string and padded on the left as needed
903
+ * @private
904
+ */
905
+ function _padPositiveNum(n, totalSize) {
906
+ let numStr = n.toString();
907
+ const numPads = totalSize - numStr.length;
908
+ if (numPads > 0) {
909
+ numStr = "0".repeat(numPads) + numStr; // TODO IE11 does not support repeat()
910
+ }
911
+ return numStr;
912
+ }
913
+ exports._padPositiveNum = _padPositiveNum;
914
+ /**
915
+ * Implements rejected ECMA proposal to change `typeof null` from "object" to "null".
916
+ *
917
+ * @param value Value whose type is sought
918
+ * @returns "null" if `value` is null; `typeof value` otherwise
919
+ * @see https://web.archive.org/web/20160331031419/http://wiki.ecmascript.org:80/doku.php?id=harmony:typeof_null
920
+ * @private
921
+ */
922
+ function _typeof_null(value) {
923
+ return value === null ? "null" : typeof value;
924
+ }
925
+ //# sourceMappingURL=generalHelpers.js.map