@kwiz/common 1.0.2 → 1.0.3

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 (86) hide show
  1. package/package.json +1 -1
  2. package/src/_dependencies.ts +0 -2
  3. package/src/helpers/Guid.ts +0 -182
  4. package/src/helpers/_dependencies.ts +0 -3
  5. package/src/helpers/base64.ts +0 -174
  6. package/src/helpers/browser.test.js +0 -9
  7. package/src/helpers/browser.ts +0 -1299
  8. package/src/helpers/browserinfo.ts +0 -293
  9. package/src/helpers/collections.base.test.js +0 -26
  10. package/src/helpers/collections.base.ts +0 -439
  11. package/src/helpers/collections.ts +0 -108
  12. package/src/helpers/color.ts +0 -55
  13. package/src/helpers/cookies.ts +0 -55
  14. package/src/helpers/date.test.js +0 -97
  15. package/src/helpers/date.ts +0 -163
  16. package/src/helpers/debug.ts +0 -187
  17. package/src/helpers/emails.ts +0 -7
  18. package/src/helpers/eval.ts +0 -5
  19. package/src/helpers/file.test.js +0 -51
  20. package/src/helpers/file.ts +0 -59
  21. package/src/helpers/flatted.ts +0 -150
  22. package/src/helpers/functions.ts +0 -17
  23. package/src/helpers/graph/calendar.types.ts +0 -11
  24. package/src/helpers/http.ts +0 -70
  25. package/src/helpers/images.ts +0 -23
  26. package/src/helpers/index.ts +0 -29
  27. package/src/helpers/json.ts +0 -39
  28. package/src/helpers/md5.ts +0 -190
  29. package/src/helpers/objects.test.js +0 -27
  30. package/src/helpers/objects.ts +0 -256
  31. package/src/helpers/promises.test.js +0 -18
  32. package/src/helpers/promises.ts +0 -102
  33. package/src/helpers/random.ts +0 -27
  34. package/src/helpers/scheduler/scheduler.test.js +0 -104
  35. package/src/helpers/scheduler/scheduler.ts +0 -132
  36. package/src/helpers/sharepoint.ts +0 -681
  37. package/src/helpers/strings.test.js +0 -43
  38. package/src/helpers/strings.ts +0 -288
  39. package/src/helpers/typecheckers.test.js +0 -35
  40. package/src/helpers/typecheckers.ts +0 -263
  41. package/src/helpers/url.test.js +0 -18
  42. package/src/helpers/url.ts +0 -202
  43. package/src/helpers/urlhelper.ts +0 -104
  44. package/src/index.ts +0 -24
  45. package/src/types/common.types.ts +0 -16
  46. package/src/types/flatted.types.ts +0 -60
  47. package/src/types/globals.types.ts +0 -7
  48. package/src/types/graph/calendar.types.ts +0 -81
  49. package/src/types/graph/index.ts +0 -1
  50. package/src/types/index.ts +0 -12
  51. package/src/types/knownscript.types.ts +0 -19
  52. package/src/types/libs/datajs.types.ts +0 -29
  53. package/src/types/libs/ics.types.ts +0 -31
  54. package/src/types/libs/index.ts +0 -4
  55. package/src/types/libs/msal.types.ts +0 -79
  56. package/src/types/locales.ts +0 -125
  57. package/src/types/localstoragecache.types.ts +0 -9
  58. package/src/types/moment.ts +0 -7
  59. package/src/types/regex.types.ts +0 -17
  60. package/src/types/rest.types.ts +0 -94
  61. package/src/types/sharepoint.types.ts +0 -1413
  62. package/src/types/sharepoint.utils.types.ts +0 -246
  63. package/src/utils/_dependencies.ts +0 -4
  64. package/src/utils/base64.ts +0 -27
  65. package/src/utils/consolelogger.ts +0 -315
  66. package/src/utils/date.ts +0 -36
  67. package/src/utils/emails.ts +0 -25
  68. package/src/utils/index.ts +0 -13
  69. package/src/utils/knownscript.ts +0 -280
  70. package/src/utils/localstoragecache.ts +0 -419
  71. package/src/utils/rest.ts +0 -465
  72. package/src/utils/script.ts +0 -168
  73. package/src/utils/sharepoint.rest/common.ts +0 -149
  74. package/src/utils/sharepoint.rest/date.ts +0 -61
  75. package/src/utils/sharepoint.rest/file.folder.ts +0 -368
  76. package/src/utils/sharepoint.rest/index.ts +0 -11
  77. package/src/utils/sharepoint.rest/item.ts +0 -456
  78. package/src/utils/sharepoint.rest/list.ts +0 -1144
  79. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +0 -750
  80. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +0 -265
  81. package/src/utils/sharepoint.rest/listutils/common.ts +0 -202
  82. package/src/utils/sharepoint.rest/user-search.ts +0 -254
  83. package/src/utils/sharepoint.rest/user.ts +0 -447
  84. package/src/utils/sharepoint.rest/web.ts +0 -1031
  85. package/src/utils/sod.ts +0 -193
  86. package/tsconfig.json +0 -21
@@ -1,456 +0,0 @@
1
- import { LocaleKnownScript } from "../../utils/knownscript";
2
- import { DateTimeFieldFormatType, IAttachmentInfo, IDictionary, IFieldCurrencyInfo, IFieldDateTimeInfo, IFieldInfoEX, IFieldNumberInfo, IRestItem, TaxonomyValueType, chunkArray, encodeURIComponentEX, hasOwnProperty, isBoolean, isDate, isNotEmptyArray, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isNumber, isString, jsonTypes, promiseNParallel } from "../_dependencies";
3
- import { ConsoleLogger } from "../consolelogger";
4
- import { GetJson, GetJsonSync } from "../rest";
5
- import { GetFieldNameFromRawValues, GetSiteUrl, __getSPRestErrorData, getFieldNameForUpdate } from "./common";
6
- import { GetList, GetListFields, GetListFieldsAsHash, GetListRestUrl } from "./list";
7
- import { GetUserSync } from "./user";
8
-
9
- const logger = ConsoleLogger.get("SharePoint.Rest.Item");
10
-
11
- /** can only select FileSizeDisplay in REST api */
12
- export const FileSizeColumnInternalNames = ["FileSizeDisplay", "File_x0020_Size"];
13
-
14
- function _getListItemSelectExpandFields(fields: string[], listFields: IFieldInfoEX[]) {
15
- var $selectFields = [];
16
- var $expandFields = [];
17
-
18
- fields.forEach((fieldName) => {
19
- if (FileSizeColumnInternalNames.includes(fieldName)) {
20
- $selectFields.push(FileSizeColumnInternalNames[0]);//for some reason, can't select File_x0020_Size
21
- }
22
- else {
23
- let field = listFields.filter((listField) => { return listField.InternalName === fieldName; })[0];
24
- if (!isNullOrUndefined(field)) {
25
- if (field.TypeAsString === "User" || field.TypeAsString === "UserMulti") {
26
- $selectFields.push(`${field.InternalName}/ID`);
27
- $selectFields.push(`${field.InternalName}/Name`);
28
- $selectFields.push(`${field.InternalName}/UserName`);
29
- $selectFields.push(`${field.InternalName}/EMail`);
30
- $selectFields.push(`${field.InternalName}/Title`);
31
- $expandFields.push(field.InternalName);
32
- } else {
33
- $selectFields.push(field.InternalName);
34
- }
35
- }
36
- }
37
- });
38
-
39
- return {
40
- expandFields: $expandFields,
41
- selectFields: $selectFields
42
- };
43
- }
44
-
45
- function _parseValueFromRawValue(rawValue: any, asDisplayValue = false) {
46
- if (!isNullOrUndefined(rawValue)) {
47
- if (rawValue["ID"] && rawValue["Title"] && rawValue["Name"]) { //expanded user field from rest request
48
- return !asDisplayValue ? rawValue["ID"] : rawValue["Title"];
49
- } else if (Array.isArray(rawValue)) {
50
- return rawValue.map((value) => {
51
- if (value["ID"] && value["Title"] && value["Name"]) { //expanded user field from rest request
52
- return !asDisplayValue ? value["ID"] : value["Title"];
53
- }
54
- return value;
55
- }).filter((value) => {
56
- return value !== null;
57
- });
58
- } else {
59
- return rawValue;
60
- }
61
- }
62
- }
63
-
64
- async function _getListItemRawFieldValues(siteUrl: string, listIdOrTitle: string, itemId: number | string, fields: string[], options?: { refreshCache?: boolean; }): Promise<{ [fieldName: string]: any; }> {
65
- siteUrl = GetSiteUrl(siteUrl);
66
-
67
- options = options || {};
68
-
69
- let listFields = await GetListFields(siteUrl, listIdOrTitle);
70
- var { selectFields, expandFields } = _getListItemSelectExpandFields(fields, listFields);
71
-
72
- var $select = `$select=` + encodeURIComponent(selectFields.length ? `${selectFields.join(',')}` : fields.join(','));
73
- var $expand = expandFields.length ? `$expand=${encodeURIComponent(expandFields.join(','))}` : "";
74
-
75
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})?${$select}&${$expand}`;
76
- let result = await GetJson<{ d: { [field: string]: any; }; }>(url, null, { allowCache: options.refreshCache !== true });
77
-
78
- var values = {};
79
-
80
- if (result && typeof (result.d) !== "undefined") {
81
- var rawValues = result.d;
82
- fields.forEach((fieldName) => {
83
- let rawValue = (FileSizeColumnInternalNames.includes(fieldName)) ? rawValues[FileSizeColumnInternalNames[0]] : rawValues[fieldName];
84
- if (!isNullOrUndefined(rawValue)) {
85
- values[fieldName] = rawValue;
86
- }
87
- });
88
- }
89
-
90
- return values;
91
- }
92
-
93
- export function GetListItemFieldDisplayValueSync(siteUrl: string, listIdOrTitle: string, itemId: number | string, field: string): string {
94
- return GetListItemFieldDisplayValuesSync(siteUrl, listIdOrTitle, itemId, [field])[field];
95
- }
96
- export function GetListItemFieldDisplayValuesSync(siteUrl: string, listIdOrTitle: string, itemId: number | string, fields: string[]): IDictionary<string> {
97
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})/FieldValuesAsText?$select=${fields.join(',')}`;
98
- let result = GetJsonSync<IDictionary<string>>(url, null, { allowCache: true, jsonMetadata: jsonTypes.nometadata });
99
- return result.success ? result.result : {};
100
- }
101
-
102
- export async function GetListItemFieldDisplayValue(siteUrl: string, listIdOrTitle: string, itemId: number | string, field: string, options?: { refreshCache?: boolean; }): Promise<string> {
103
- var values = await GetListItemFieldDisplayValues(siteUrl, listIdOrTitle, itemId, [field], options);
104
- return values && values[field];
105
- }
106
-
107
- export async function GetListItemFieldDisplayValues(siteUrl: string, listIdOrTitle: string, itemId: number | string, fields: string[], options?: { refreshCache?: boolean; }): Promise<{ [fieldName: string]: string; }> {
108
- var rawValues = await _getListItemRawFieldValues(siteUrl, listIdOrTitle, itemId, fields, options);
109
-
110
- var values = {};
111
- Object.keys(rawValues).forEach(key => {
112
- var fieldValue = _parseValueFromRawValue(rawValues[key], true);
113
- if (!isNullOrUndefined(fieldValue)) {
114
- values[key] = fieldValue;
115
- }
116
- });
117
-
118
- return values;
119
- }
120
-
121
- export async function GetListItemFieldValue(siteUrl: string, listIdOrTitle: string, itemId: number | string, field: string, options?: { refreshCache?: boolean; }): Promise<any> {
122
- var values = await GetListItemFieldValues(siteUrl, listIdOrTitle, itemId, [field], options);
123
- return values && values[field];
124
- }
125
-
126
- export async function GetListItemFieldValues(siteUrl: string, listIdOrTitle: string, itemId: number | string, fields: string[], options?: { refreshCache?: boolean; }): Promise<{ [fieldName: string]: any; }> {
127
- var rawValues = await _getListItemRawFieldValues(siteUrl, listIdOrTitle, itemId, fields, options);
128
-
129
- var values = {};
130
- Object.keys(rawValues).forEach(key => {
131
- var fieldValue = _parseValueFromRawValue(rawValues[key]);
132
- if (!isNullOrUndefined(fieldValue)) {
133
- values[key] = fieldValue;
134
- }
135
- });
136
-
137
- return values;
138
- }
139
-
140
- /** Returns version array, newest version first */
141
- export async function GetListItemFieldValuesHistory(siteUrl: string, listIdOrTitle: string, itemId: number | string, fields: string[], options?: { refreshCache?: boolean; }) {
142
- siteUrl = GetSiteUrl(siteUrl);
143
-
144
- options = options || {};
145
- var $select = isNotEmptyArray(fields) ? `$select=` + encodeURIComponent(`${fields.join(',')}`) : "";
146
-
147
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})/versions?${$select}`;
148
- let result = await GetJson<{ value: IRestItem[]; }>(url, null, {
149
- allowCache: options.refreshCache !== true,
150
- jsonMetadata: jsonTypes.nometadata
151
- });
152
-
153
- return result && result.value || [];
154
- }
155
-
156
- export async function DeleteListItem(siteUrl: string, listIdOrTitle: string, itemId: number | string): Promise<{ deleted: boolean; errorMessage?: string; }> {
157
- siteUrl = GetSiteUrl(siteUrl);
158
-
159
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})`;
160
-
161
- let result: { deleted: boolean; errorMessage?: string; } = { deleted: true };
162
- try {
163
- await GetJson<string>(url, null, { method: "POST", spWebUrl: siteUrl, xHttpMethod: "DELETE" });
164
- //empty string means deleted
165
- } catch (e) {
166
- result.deleted = false;
167
- result.errorMessage = __getSPRestErrorData(e).message;
168
- }
169
-
170
- return result;
171
- }
172
-
173
- export async function RecycleListItem(siteUrl: string, listIdOrTitle: string, itemId: number | string): Promise<{ recycled: boolean; errorMessage?: string; }> {
174
- siteUrl = GetSiteUrl(siteUrl);
175
-
176
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})/recycle()`;
177
-
178
- let result: { recycled: boolean; errorMessage?: string; } = { recycled: true };
179
- try {
180
- await GetJson<{ d: { Recycle: string; }; }>(url, null, { method: "POST", spWebUrl: siteUrl });
181
- //value.d.Recycle will hold guide reference id
182
- } catch (e) {
183
- result.recycled = false;
184
- result.errorMessage = __getSPRestErrorData(e).message;
185
- }
186
-
187
- return result;
188
- }
189
-
190
- export async function GetListItemAttachments(siteUrl: string, listIdOrTitle: string, itemId: number): Promise<IAttachmentInfo[]> {
191
- siteUrl = GetSiteUrl(siteUrl);
192
-
193
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})/AttachmentFiles`;
194
-
195
- try {
196
- let result = await GetJson<{ d: { results: IAttachmentInfo[]; }; }>(url, null, { includeDigestInGet: true });
197
- let attachmentFiles = result.d && result.d.results ? result.d.results : [];
198
- return attachmentFiles;
199
- } catch (e) {
200
- }
201
- return [];
202
- }
203
-
204
- export async function GetListItemsAttachments(siteUrl: string, listIdOrTitle: string, itemIds: number[]): Promise<{ Id: number, AttachmentFiles: IAttachmentInfo[] }[]> {
205
- siteUrl = GetSiteUrl(siteUrl);
206
- let chunks = chunkArray(itemIds, 30);
207
- let select = `$select=ID,AttachmentFiles`;
208
- let expand = `$expand=AttachmentFiles`;
209
- let baseUrl = GetListRestUrl(siteUrl, listIdOrTitle) + `/items`;
210
- let promises = chunks.map((chunk) => {
211
- return () => {
212
- let filter = `$filter=${chunk.map(i => `ID eq ${i}`).join(" or ")}`;
213
- let url = `${baseUrl}?${select}&${filter}&${expand}`
214
- return GetJson<{ value: { Id: number, AttachmentFiles: IAttachmentInfo[] } }>(url, null, { includeDigestInGet: true, jsonMetadata: jsonTypes.nometadata });
215
- };
216
- });
217
- try {
218
- let result = await promiseNParallel(promises, 5);
219
- return result && result.length > 0 ? result.map(v => v.value) : [];
220
- } catch {
221
-
222
- }
223
- return [];
224
- }
225
-
226
- export async function AddAttachment(siteUrl: string, listIdOrTitle: string, itemId: number, filename: string, buffer: ArrayBuffer) {
227
- siteUrl = GetSiteUrl(siteUrl);
228
-
229
- //Issue 999
230
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})/AttachmentFiles/add(FileName='${encodeURIComponentEX(filename, { singleQuoteMultiplier: 2 })}')`;
231
-
232
- try {
233
- let result = await GetJson<{ d: IAttachmentInfo; }>(url, buffer, { includeDigestInPost: true, method: "POST" });
234
- let attachmentFile = result && result.d;
235
- return attachmentFile;
236
- } catch (e) {
237
- }
238
- return null;
239
- }
240
-
241
- export async function DeleteAttachment(siteUrl: string, listIdOrTitle: string, itemId: number, filename: string) {
242
- siteUrl = GetSiteUrl(siteUrl);
243
-
244
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})/AttachmentFiles('${encodeURIComponentEX(filename, { singleQuoteMultiplier: 2 })}')`;
245
-
246
- try {
247
- let result = await GetJson<{ d: IAttachmentInfo; }>(url, null, { includeDigestInGet: true, includeDigestInPost: true, xHttpMethod: "DELETE" });
248
- let attachmentFile = result && result.d;
249
- return attachmentFile;
250
- } catch (e) {
251
- }
252
- return null;
253
- }
254
-
255
- //** Update value of taxonomy multi-value field. See issue 7585 for more info */
256
- export async function UpdateMultiTaxonomyValue(siteUrl: string, listIdOrTitle: string, itemId: number,
257
- updates: IDictionary<TaxonomyValueType[]>) {
258
-
259
- let fields = updates && Object.keys(updates) || [];
260
-
261
- if (isNullOrEmptyArray(fields)) return [];
262
-
263
- siteUrl = GetSiteUrl(siteUrl);
264
-
265
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items(${itemId})/ValidateUpdateListItem()`;
266
-
267
- try {
268
- let result = await GetJson<{
269
- d: {
270
- ValidateUpdateListItem: {
271
- results: {
272
- ErrorCode: number;
273
- ErrorMEssage?: string;
274
- FieldName: string;
275
- FieldValue: string;
276
- HasException: boolean;
277
- ItemId: number;
278
- }[];
279
- };
280
- };
281
- }>(url, JSON.stringify({
282
- bNewDocumentUpdate: false,
283
- checkInComment: null,
284
- formValues: fields.map(field => ({
285
- ErrorMessage: null,
286
- FieldName: field,
287
- FieldValue: updates[field].map(v => `${v.Label}|${v.TermGuid};`).join(''),
288
- HasException: false
289
- }))
290
- }), { includeDigestInPost: true, method: "POST" });
291
- return result && result.d && result.d.ValidateUpdateListItem.results.map(v => ({ field: v.FieldName, error: v.ErrorMEssage })) || [];
292
- } catch (e) {
293
- logger.error(`Error updating UpdateMultiTaxonomyValue ${e}`);
294
- }
295
- return fields.map(f => ({ field: f, error: 'Unspecified update error' }));
296
- }
297
-
298
- export async function AddItem(siteUrl: string, listIdOrTitle: string, fieldValues: IDictionary<any>) {
299
- //we must force creating even if no values, otherwise the item won't be created at all.
300
- return UpdateItem(siteUrl, listIdOrTitle, null, fieldValues, { updateIfNoFields: true });
301
- }
302
- export interface UpdateItemType {
303
- updateProps: {
304
- success: boolean;
305
- itemId: number;
306
- errorMessage?: undefined;
307
- } | {
308
- success: boolean;
309
- errorMessage: string;
310
- itemId: number;
311
- }
312
- }
313
- export async function UpdateItem(siteUrl: string, listIdOrTitle: string, itemId: number, fieldValues: IDictionary<any>, options?: { updateIfNoFields?: boolean; }) {
314
- var success = false;
315
- var error: string = null;
316
- try {
317
- siteUrl = GetSiteUrl(siteUrl);
318
-
319
- let isNewItem = itemId > 0 ? false : true;
320
- let listInfo = await GetList(siteUrl, listIdOrTitle);
321
- let fields = await GetListFieldsAsHash(siteUrl, listIdOrTitle);
322
- let url = GetListRestUrl(siteUrl, listIdOrTitle) + `/items${isNewItem ? '' : `(${itemId})`}`;
323
-
324
- var itemUpdateInfo: { [key: string]: any; } = {
325
- '__metadata': { 'type': `SP.Data.${listInfo.EntityTypeName}Item` }
326
- };
327
- let hasUpdates = false;
328
- Object.keys(fieldValues).forEach(updateField => {
329
- let listField = fields[updateField];
330
- if (listField)//make sure this field exists on the list
331
- {
332
- //todo: we might want to get the value first, make sure it is formatted correctly for the field type.
333
- itemUpdateInfo[getFieldNameForUpdate(listField)] = fieldValues[updateField];
334
- hasUpdates = true;
335
- }
336
- });
337
-
338
- if (!hasUpdates) {
339
- let forceUpdate = options && options.updateIfNoFields;
340
- if (!forceUpdate)
341
- return { success: true, itemId: itemId };
342
- }
343
-
344
- var xHttpMethod: "MERGE" = isNewItem ? null : "MERGE";
345
-
346
- try {
347
- let result = await GetJson<{ d: { Id: number; }; }>(url, JSON.stringify(itemUpdateInfo), { method: "POST", xHttpMethod: xHttpMethod });
348
- if (result)
349
- if (isNewItem)
350
- itemId = result.d.Id;// update item will not return data. only new item will.
351
- success = true;
352
- } catch (e) {
353
- error = __getSPRestErrorData(e).message;
354
- }
355
- } catch (e) {
356
- logger.group(() => logger.error(e), 'Update item failed');
357
- }
358
- return { success: success, errorMessage: error, itemId: itemId };
359
- }
360
- /** Get a sharepoint field value as text, from a rest item */
361
- export function GetSPRestItemValueAsText(item: IRestItem, field: IFieldInfoEX): string {
362
-
363
- var otherName = field.InternalName.replace(/_/g, "_x005f_");//sometimes _ gets replaced with _x005f_
364
- if (!isNullOrUndefined(item.FieldValuesAsText)) {
365
- if (hasOwnProperty(item.FieldValuesAsText, field.InternalName))
366
- return item.FieldValuesAsText[field.InternalName];
367
- if (hasOwnProperty(item.FieldValuesAsText, otherName))
368
- return item.FieldValuesAsText[otherName];
369
- }
370
-
371
- return GetSPFieldValueAsText(item[GetFieldNameFromRawValues(field)], field).join(', ');
372
- }
373
- /** Get a sharepoint field value as text array, from a rest item */
374
- export function GetSPRestItemValueAsTextArray(item: IRestItem, field: IFieldInfoEX): string[] {
375
- //get value as text first
376
- let valueAsText = null;
377
- var otherName = field.InternalName.replace(/_/g, "_x005f_");//sometimes _ gets replaced with _x005f_
378
- if (!isNullOrUndefined(item.FieldValuesAsText)) {
379
- if (hasOwnProperty(item.FieldValuesAsText, field.InternalName))
380
- valueAsText = item.FieldValuesAsText[field.InternalName];
381
- if (hasOwnProperty(item.FieldValuesAsText, otherName))
382
- valueAsText = item.FieldValuesAsText[otherName];
383
- }
384
- if (!isNullOrEmptyString(valueAsText) && valueAsText.indexOf(',') < 0)//not empty, and we do not suspect a multi-value field
385
- return [valueAsText];
386
-
387
- return GetSPFieldValueAsText(item[GetFieldNameFromRawValues(field)], field);
388
- }
389
- /** prefer to use GetSPRestValueAsText instead */
390
- export function GetSPFieldValueAsText(value: any, field: IFieldInfoEX): string[] {
391
- let locales = window.kLocales || LocaleKnownScript.loadSync();
392
- let culture = locales.GetCurrentCulture();
393
-
394
- let rawValues: (string | number | boolean | Date | { Id: string | number; Title: string; })[] =
395
- isNullOrEmptyString(value)
396
- ? []
397
- : Array.isArray(value)
398
- ? value//value.raw is an array
399
- : [value];//value.raw is not an array - wrap it.
400
-
401
- let isLookup = field.TypeAsString === "Lookup" || field.TypeAsString === "LookupMulti";
402
- let isUser = field.TypeAsString === "User" || field.TypeAsString === "UserMulti";
403
- let isCounter = field.TypeAsString === "Counter" || field.TypeAsString === "Integer";
404
- if (field.TypeAsString === "DateTime") {
405
- //Issue 8190 - date field might come as string
406
- rawValues = rawValues.map(v => isDate(v) ? v : new Date(v as string));
407
- }
408
- else if (isUser || isLookup) {
409
- rawValues = rawValues.map(v => isNumber(v) ? v : !isNullOrEmptyString(v && (v as any).Title) ? (v as any).Title : isNumber(v && (v as any).Id) ? (v as any).Id : null);
410
- }
411
-
412
- let textResults: string[] = [];
413
- if (isNotEmptyArray(rawValues)) {
414
- rawValues.forEach(raw => {
415
- if (isNullOrEmptyString(raw)) {/** skip */ }
416
- else if (isNumber(raw))
417
- if (isUser) {
418
- //todo - try not sync...
419
- try {
420
- let userInfo = GetUserSync(_spPageContextInfo.siteServerRelativeUrl, raw);
421
- textResults.push(userInfo.Title);
422
- } catch (e) {
423
- textResults.push(`${raw}`);
424
- }
425
- }
426
- else if (isLookup) {
427
- //todo - not supported
428
- try {
429
- textResults.push(`Lookup #${raw}`);
430
- }
431
- catch (e) {
432
- textResults.push(`${raw}`);
433
- }
434
- } else if (isCounter) {
435
- textResults.push(raw.toString());
436
- } else {
437
- textResults.push(locales.NumberToString(raw, culture, {
438
- isCurrency: isNumber((field as IFieldCurrencyInfo).CurrencyLocaleId),
439
- isPercent: (field as IFieldNumberInfo).ShowAsPercentage
440
- }));
441
- }
442
- else if (isString(raw))
443
- textResults.push(raw);
444
- else if (isBoolean(raw)) {
445
- textResults.push(raw ? "Yes" : "No");
446
- }
447
- else if (isDate(raw)) {
448
- textResults.push(locales.DateToString(raw, culture, {
449
- includeDate: true,
450
- includeTime: (field as IFieldDateTimeInfo).DisplayFormat === DateTimeFieldFormatType.DateTime
451
- }));
452
- }
453
- });
454
- }
455
- return textResults;
456
- }