@carbon/ai-chat 0.1.6 → 0.1.7-alpha0

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 (144) hide show
  1. package/dist/cjs/{cds-aichat-internal.js → AppContainer.js} +615 -7203
  2. package/dist/cjs/Carousel.js +24 -16
  3. package/dist/cjs/Chat.js +813 -805
  4. package/dist/cjs/GenesysMessengerServiceDesk.js +60 -52
  5. package/dist/cjs/HumanAgentServiceImpl.js +103 -95
  6. package/dist/cjs/NiceDFOServiceDesk.js +56 -48
  7. package/dist/cjs/PDFViewerContainer.js +58 -149
  8. package/dist/cjs/ReactPlayer.js +2 -2
  9. package/dist/cjs/SFServiceDesk.js +66 -58
  10. package/dist/cjs/ServiceDeskImpl.js +2 -2
  11. package/dist/cjs/Table.js +457 -341
  12. package/dist/cjs/ZendeskServiceDesk.js +36 -28
  13. package/dist/cjs/_node-resolve_empty.js +2 -2
  14. package/dist/cjs/agentActions.js +5 -5
  15. package/dist/cjs/aiChatEntry.js +163 -144
  16. package/dist/cjs/anonymousUserIDStorage.js +8 -8
  17. package/dist/cjs/ar-dz.js +4 -4
  18. package/dist/cjs/ar-kw.js +4 -4
  19. package/dist/cjs/ar-ly.js +4 -4
  20. package/dist/cjs/ar-ma.js +4 -4
  21. package/dist/cjs/ar-sa.js +4 -4
  22. package/dist/cjs/ar-tn.js +4 -4
  23. package/dist/cjs/ar.js +4 -4
  24. package/dist/cjs/ar2.js +2 -2
  25. package/dist/cjs/cds-aichat-container.js +111 -23
  26. package/dist/cjs/cds-aichat-custom-element.js +42 -30
  27. package/dist/cjs/cs.js +4 -4
  28. package/dist/cjs/cs2.js +2 -2
  29. package/dist/cjs/de-at.js +4 -4
  30. package/dist/cjs/de-ch.js +4 -4
  31. package/dist/cjs/de.js +4 -4
  32. package/dist/cjs/de2.js +2 -2
  33. package/dist/cjs/en-au.js +4 -4
  34. package/dist/cjs/en-ca.js +4 -4
  35. package/dist/cjs/en-gb.js +4 -4
  36. package/dist/cjs/en-ie.js +4 -4
  37. package/dist/cjs/en-il.js +4 -4
  38. package/dist/cjs/en-nz.js +4 -4
  39. package/dist/cjs/es-do.js +4 -4
  40. package/dist/cjs/es-us.js +4 -4
  41. package/dist/cjs/es.js +4 -4
  42. package/dist/cjs/es2.js +2 -2
  43. package/dist/cjs/export.js +3 -3
  44. package/dist/cjs/export.legacy.js +3 -3
  45. package/dist/cjs/fontUtils.js +2 -2
  46. package/dist/cjs/fr-ca.js +4 -4
  47. package/dist/cjs/fr-ch.js +4 -4
  48. package/dist/cjs/fr.js +4 -4
  49. package/dist/cjs/fr2.js +2 -2
  50. package/dist/cjs/highlight_js.js +2 -2
  51. package/dist/cjs/it-ch.js +4 -4
  52. package/dist/cjs/it.js +4 -4
  53. package/dist/cjs/it2.js +2 -2
  54. package/dist/cjs/ja.js +4 -4
  55. package/dist/cjs/ja2.js +2 -2
  56. package/dist/cjs/ko.js +4 -4
  57. package/dist/cjs/ko2.js +2 -2
  58. package/dist/cjs/markdown.js +2362 -14
  59. package/dist/cjs/mockServiceDesk.js +42 -34
  60. package/dist/cjs/nl.js +4 -4
  61. package/dist/cjs/nl2.js +2 -2
  62. package/dist/cjs/pt-br.js +4 -4
  63. package/dist/cjs/pt-br2.js +2 -2
  64. package/dist/cjs/pt.js +4 -4
  65. package/dist/cjs/render.js +18 -10
  66. package/dist/cjs/zh-cn.js +4 -4
  67. package/dist/cjs/zh-tw.js +4 -4
  68. package/dist/cjs/zh-tw2.js +2 -2
  69. package/dist/cjs/zh.js +2 -2
  70. package/dist/es/{cds-aichat-internal.js → AppContainer.js} +1117 -7671
  71. package/dist/es/Carousel.js +16 -8
  72. package/dist/es/Chat.js +16 -8
  73. package/dist/es/GenesysMessengerServiceDesk.js +16 -8
  74. package/dist/es/HumanAgentServiceImpl.js +16 -8
  75. package/dist/es/NiceDFOServiceDesk.js +16 -8
  76. package/dist/es/PDFViewerContainer.js +16 -107
  77. package/dist/es/ReactPlayer.js +2 -2
  78. package/dist/es/SFServiceDesk.js +16 -8
  79. package/dist/es/ServiceDeskImpl.js +2 -2
  80. package/dist/es/Table.js +426 -310
  81. package/dist/es/ZendeskServiceDesk.js +16 -8
  82. package/dist/es/_node-resolve_empty.js +2 -2
  83. package/dist/es/agentActions.js +3 -3
  84. package/dist/es/aiChatEntry.js +136 -117
  85. package/dist/es/anonymousUserIDStorage.js +3 -3
  86. package/dist/es/ar-dz.js +3 -3
  87. package/dist/es/ar-kw.js +3 -3
  88. package/dist/es/ar-ly.js +3 -3
  89. package/dist/es/ar-ma.js +3 -3
  90. package/dist/es/ar-sa.js +3 -3
  91. package/dist/es/ar-tn.js +3 -3
  92. package/dist/es/ar.js +3 -3
  93. package/dist/es/ar2.js +2 -2
  94. package/dist/es/cds-aichat-container.js +103 -15
  95. package/dist/es/cds-aichat-custom-element.js +30 -18
  96. package/dist/es/cs.js +3 -3
  97. package/dist/es/cs2.js +2 -2
  98. package/dist/es/de-at.js +3 -3
  99. package/dist/es/de-ch.js +3 -3
  100. package/dist/es/de.js +3 -3
  101. package/dist/es/de2.js +2 -2
  102. package/dist/es/en-au.js +3 -3
  103. package/dist/es/en-ca.js +3 -3
  104. package/dist/es/en-gb.js +3 -3
  105. package/dist/es/en-ie.js +3 -3
  106. package/dist/es/en-il.js +3 -3
  107. package/dist/es/en-nz.js +3 -3
  108. package/dist/es/es-do.js +3 -3
  109. package/dist/es/es-us.js +3 -3
  110. package/dist/es/es.js +3 -3
  111. package/dist/es/es2.js +2 -2
  112. package/dist/es/export.js +3 -3
  113. package/dist/es/export.legacy.js +3 -3
  114. package/dist/es/fontUtils.js +2 -2
  115. package/dist/es/fr-ca.js +3 -3
  116. package/dist/es/fr-ch.js +3 -3
  117. package/dist/es/fr.js +3 -3
  118. package/dist/es/fr2.js +2 -2
  119. package/dist/es/highlight_js.js +2 -2
  120. package/dist/es/it-ch.js +3 -3
  121. package/dist/es/it.js +3 -3
  122. package/dist/es/it2.js +2 -2
  123. package/dist/es/ja.js +3 -3
  124. package/dist/es/ja2.js +2 -2
  125. package/dist/es/ko.js +3 -3
  126. package/dist/es/ko2.js +2 -2
  127. package/dist/es/markdown.js +2361 -15
  128. package/dist/es/mockServiceDesk.js +16 -8
  129. package/dist/es/nl.js +3 -3
  130. package/dist/es/nl2.js +2 -2
  131. package/dist/es/pt-br.js +3 -3
  132. package/dist/es/pt-br2.js +2 -2
  133. package/dist/es/pt.js +3 -3
  134. package/dist/es/render.js +17 -9
  135. package/dist/es/zh-cn.js +3 -3
  136. package/dist/es/zh-tw.js +3 -3
  137. package/dist/es/zh-tw2.js +2 -2
  138. package/dist/es/zh.js +2 -2
  139. package/dist/types/aiChatEntry.d.ts +69 -9
  140. package/package.json +27 -14
  141. package/dist/cjs/jstz.min.js +0 -43
  142. package/dist/cjs/markdown_attrs.js +0 -805
  143. package/dist/es/jstz.min.js +0 -41
  144. package/dist/es/markdown_attrs.js +0 -803
package/dist/es/Table.js CHANGED
@@ -13,39 +13,47 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
13
13
  or implied. See the License for the specific language governing permissions and limitations under
14
14
  the License.
15
15
 
16
- @carbon/ai-chat 0.1.6
16
+ @carbon/ai-chat 0.1.7-alpha0
17
17
 
18
- Built: Feb 3 2025 9:58 am -05:00
18
+ Built: Feb 12 2025 9:14 am -05:00
19
19
 
20
20
 
21
21
 
22
22
  */
23
- import { eu as toString$1, _ as __decorate, ev as _default, c as carbonElement, o } from './cds-aichat-internal.js';
23
+ import { el as _default, c as carbonElement, o } from './AppContainer.js';
24
24
  import React__default from 'react';
25
+ import { __decorate } from 'tslib';
25
26
  import { html, LitElement, css, unsafeCSS } from 'lit';
26
27
  import { property, state } from 'lit/decorators.js';
27
28
  import '@carbon/web-components/es/components/data-table/index.js';
28
29
  import '@carbon/web-components/es/components/checkbox/index.js';
29
30
  import '@carbon/web-components/es/components/button/index.js';
31
+ import { toString as toString$1 } from '@carbon/icon-helpers';
32
+ import { Download16 } from '@carbon/icons';
30
33
  import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
31
34
  import { repeat } from 'lit-html/directives/repeat.js';
32
35
  import '@carbon/web-components/es/components/pagination/index.js';
33
36
  import '@carbon/web-components/es/components/select/index.js';
34
37
  import '@carbon/web-components/es/components/data-table/table-skeleton.js';
35
- import 'react-dom';
36
38
  import './highlight_js.js';
37
39
  import '@carbon/react';
40
+ import 'classnames';
38
41
  import 'react-intl';
39
42
  import 'react-redux';
43
+ import 'tabbable';
44
+ import '@carbon/icons-react';
40
45
  import './markdown.js';
41
- import './markdown_attrs.js';
42
46
  import '@carbon/web-components/es/components/overflow-menu/index.js';
43
47
  import 'lit/directives/unsafe-html.js';
48
+ import 'prop-types';
44
49
  import '@carbon/web-components/es/components/slug/index.js';
45
50
  import '@carbon/web-components/es/components/popover/defs.js';
46
51
  import '@carbon/web-components/es/components/slug/defs.js';
52
+ import '@floating-ui/react';
53
+ import 'react-dom';
47
54
  import '@carbon/web-components/es/components/slug/slug-action-button.js';
48
55
  import '@carbon/web-components/es/components/slug/slug.js';
56
+ import '@carbon/web-components/es/components/inline-loading/index.js';
49
57
  import '@carbon/web-components/es/components/textarea/index.js';
50
58
  import '@carbon/web-components/es/components/icon-button/index.js';
51
59
  import '@carbon/web-components/es/components/tag/index.js';
@@ -53,33 +61,6 @@ import '@carbon/web-components/es/components/chat-button/index.js';
53
61
  import '@carbon/web-components/es/components/button/button.js';
54
62
  import '@carbon/web-components/es/components/layer/index.js';
55
63
 
56
- /**
57
- * Copyright IBM Corp. 2016, 2023
58
- *
59
- * This source code is licensed under the Apache-2.0 license found in the
60
- * LICENSE file in the root directory of this source tree.
61
- *
62
- * Code generated by @carbon/icon-build-helpers. DO NOT EDIT.
63
- */
64
- var _16 = {
65
- "elem": "svg",
66
- "attrs": {
67
- "xmlns": "http://www.w3.org/2000/svg",
68
- "viewBox": "0 0 16 16",
69
- "fill": "currentColor",
70
- "width": 16,
71
- "height": 16
72
- },
73
- "content": [{
74
- "elem": "path",
75
- "attrs": {
76
- "d": "M13 7L12.3 6.3 8.5 10.1 8.5 1 7.5 1 7.5 10.1 3.7 6.3 3 7 8 12zM13 12v2H3v-2H2v2l0 0c0 .6.4 1 1 1h10c.6 0 1-.4 1-1l0 0v-2H13z"
77
- }
78
- }],
79
- "name": "download",
80
- "size": 16
81
- };
82
-
83
64
  var global$1 = (typeof global !== "undefined" ? global :
84
65
  typeof self !== "undefined" ? self :
85
66
  typeof window !== "undefined" ? window : {});
@@ -2054,119 +2035,149 @@ function isSlowBuffer (obj) {
2054
2035
 
2055
2036
  // Lodash implementation of `get`
2056
2037
 
2057
- const charCodeOfDot = '.'.charCodeAt(0);
2038
+ const charCodeOfDot = ".".charCodeAt(0);
2058
2039
  const reEscapeChar = /\\(\\)?/g;
2059
2040
  const rePropName = RegExp(
2060
2041
  // Match anything that isn't a dot or bracket.
2061
- '[^.[\\]]+' + '|' +
2062
- // Or match property names within brackets.
2063
- '\\[(?:' +
2042
+ "[^.[\\]]+" +
2043
+ "|" +
2044
+ // Or match property names within brackets.
2045
+ "\\[(?:" +
2064
2046
  // Match a non-string expression.
2065
- '([^"\'][^[]*)' + '|' +
2047
+ "([^\"'][^[]*)" +
2048
+ "|" +
2066
2049
  // Or match strings (supports escaping characters).
2067
- '(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
2068
- ')\\]'+ '|' +
2069
- // Or match "" as the space between consecutive dots or empty brackets.
2070
- '(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))'
2071
- , 'g');
2050
+ "([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2" +
2051
+ ")\\]" +
2052
+ "|" +
2053
+ // Or match "" as the space between consecutive dots or empty brackets.
2054
+ "(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))",
2055
+ "g",
2056
+ );
2072
2057
  const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
2073
2058
  const reIsPlainProp = /^\w*$/;
2074
- const getTag = function(value){
2059
+
2060
+ const getTag = function (value) {
2075
2061
  return Object.prototype.toString.call(value);
2076
2062
  };
2077
- const isSymbol = function(value){
2063
+
2064
+ const isSymbol = function (value) {
2078
2065
  const type = typeof value;
2079
- return type === 'symbol' || (type === 'object' && value && getTag(value) === '[object Symbol]');
2066
+ return (
2067
+ type === "symbol" ||
2068
+ (type === "object" && value && getTag(value) === "[object Symbol]")
2069
+ );
2080
2070
  };
2081
- const isKey = function(value, object){
2082
- if(Array.isArray(value)){
2071
+
2072
+ const isKey = function (value, object) {
2073
+ if (Array.isArray(value)) {
2083
2074
  return false;
2084
2075
  }
2085
2076
  const type = typeof value;
2086
- if(type === 'number' || type === 'symbol' || type === 'boolean' || !value || isSymbol(value)){
2077
+ if (
2078
+ type === "number" ||
2079
+ type === "symbol" ||
2080
+ type === "boolean" ||
2081
+ !value ||
2082
+ isSymbol(value)
2083
+ ) {
2087
2084
  return true;
2088
2085
  }
2089
- return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
2090
- (object != null && value in Object(object));
2086
+ return (
2087
+ reIsPlainProp.test(value) ||
2088
+ !reIsDeepProp.test(value) ||
2089
+ (object != null && value in Object(object))
2090
+ );
2091
2091
  };
2092
- const stringToPath = function(string){
2092
+
2093
+ const stringToPath = function (string) {
2093
2094
  const result = [];
2094
- if(string.charCodeAt(0) === charCodeOfDot){
2095
- result.push('');
2095
+ if (string.charCodeAt(0) === charCodeOfDot) {
2096
+ result.push("");
2096
2097
  }
2097
- string.replace(rePropName, function(match, expression, quote, subString){
2098
+ string.replace(rePropName, function (match, expression, quote, subString) {
2098
2099
  let key = match;
2099
- if(quote){
2100
- key = subString.replace(reEscapeChar, '$1');
2101
- }else if(expression){
2100
+ if (quote) {
2101
+ key = subString.replace(reEscapeChar, "$1");
2102
+ } else if (expression) {
2102
2103
  key = expression.trim();
2103
2104
  }
2104
2105
  result.push(key);
2105
2106
  });
2106
2107
  return result;
2107
2108
  };
2108
- const castPath = function(value, object){
2109
- if(Array.isArray(value)){
2109
+
2110
+ const castPath = function (value, object) {
2111
+ if (Array.isArray(value)) {
2110
2112
  return value;
2111
2113
  } else {
2112
2114
  return isKey(value, object) ? [value] : stringToPath(value);
2113
2115
  }
2114
2116
  };
2115
- const toKey = function(value){
2116
- if(typeof value === 'string' || isSymbol(value))
2117
- return value;
2117
+
2118
+ const toKey = function (value) {
2119
+ if (typeof value === "string" || isSymbol(value)) return value;
2118
2120
  const result = `${value}`;
2119
2121
  // eslint-disable-next-line
2120
- return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
2122
+ return result == "0" && 1 / value == -INFINITY ? "-0" : result;
2121
2123
  };
2122
- const get = function(object, path){
2124
+
2125
+ const get = function (object, path) {
2123
2126
  path = castPath(path, object);
2124
2127
  let index = 0;
2125
2128
  const length = path.length;
2126
- while(object != null && index < length){
2129
+ while (object != null && index < length) {
2127
2130
  object = object[toKey(path[index++])];
2128
2131
  }
2129
- return (index && index === length) ? object : undefined;
2132
+ return index && index === length ? object : undefined;
2130
2133
  };
2131
2134
 
2132
- const is_object = function(obj){
2133
- return typeof obj === 'object' && obj !== null && ! Array.isArray(obj);
2135
+ const is_object = function (obj) {
2136
+ return typeof obj === "object" && obj !== null && !Array.isArray(obj);
2134
2137
  };
2135
2138
 
2136
- const normalize_columns = function(columns){
2137
- if(columns === undefined || columns === null){
2139
+ const normalize_columns = function (columns) {
2140
+ if (columns === undefined || columns === null) {
2138
2141
  return [undefined, undefined];
2139
2142
  }
2140
- if(typeof columns !== 'object'){
2143
+ if (typeof columns !== "object") {
2141
2144
  return [Error('Invalid option "columns": expect an array or an object')];
2142
2145
  }
2143
- if(!Array.isArray(columns)){
2146
+ if (!Array.isArray(columns)) {
2144
2147
  const newcolumns = [];
2145
- for(const k in columns){
2148
+ for (const k in columns) {
2146
2149
  newcolumns.push({
2147
2150
  key: k,
2148
- header: columns[k]
2151
+ header: columns[k],
2149
2152
  });
2150
2153
  }
2151
2154
  columns = newcolumns;
2152
- }else {
2155
+ } else {
2153
2156
  const newcolumns = [];
2154
- for(const column of columns){
2155
- if(typeof column === 'string'){
2157
+ for (const column of columns) {
2158
+ if (typeof column === "string") {
2156
2159
  newcolumns.push({
2157
2160
  key: column,
2158
- header: column
2161
+ header: column,
2159
2162
  });
2160
- }else if(typeof column === 'object' && column !== null && !Array.isArray(column)){
2161
- if(!column.key){
2162
- return [Error('Invalid column definition: property "key" is required')];
2163
+ } else if (
2164
+ typeof column === "object" &&
2165
+ column !== null &&
2166
+ !Array.isArray(column)
2167
+ ) {
2168
+ if (!column.key) {
2169
+ return [
2170
+ Error('Invalid column definition: property "key" is required'),
2171
+ ];
2163
2172
  }
2164
- if(column.header === undefined){
2173
+ if (column.header === undefined) {
2165
2174
  column.header = column.key;
2166
2175
  }
2167
2176
  newcolumns.push(column);
2168
- }else {
2169
- return [Error('Invalid column definition: expect a string or an object')];
2177
+ } else {
2178
+ return [
2179
+ Error("Invalid column definition: expect a string or an object"),
2180
+ ];
2170
2181
  }
2171
2182
  }
2172
2183
  columns = newcolumns;
@@ -2176,253 +2187,307 @@ const normalize_columns = function(columns){
2176
2187
 
2177
2188
  class CsvError extends Error {
2178
2189
  constructor(code, message, ...contexts) {
2179
- if(Array.isArray(message)) message = message.join(' ');
2190
+ if (Array.isArray(message)) message = message.join(" ");
2180
2191
  super(message);
2181
- if(Error.captureStackTrace !== undefined){
2192
+ if (Error.captureStackTrace !== undefined) {
2182
2193
  Error.captureStackTrace(this, CsvError);
2183
2194
  }
2184
2195
  this.code = code;
2185
- for(const context of contexts){
2186
- for(const key in context){
2196
+ for (const context of contexts) {
2197
+ for (const key in context) {
2187
2198
  const value = context[key];
2188
- this[key] = isBuffer(value) ? value.toString() : value == null ? value : JSON.parse(JSON.stringify(value));
2199
+ this[key] = isBuffer(value)
2200
+ ? value.toString()
2201
+ : value == null
2202
+ ? value
2203
+ : JSON.parse(JSON.stringify(value));
2189
2204
  }
2190
2205
  }
2191
2206
  }
2192
2207
  }
2193
2208
 
2194
- const underscore = function(str){
2195
- return str.replace(/([A-Z])/g, function(_, match){
2196
- return '_' + match.toLowerCase();
2209
+ const underscore = function (str) {
2210
+ return str.replace(/([A-Z])/g, function (_, match) {
2211
+ return "_" + match.toLowerCase();
2197
2212
  });
2198
2213
  };
2199
2214
 
2200
- const normalize_options = function(opts) {
2215
+ const normalize_options = function (opts) {
2201
2216
  const options = {};
2202
2217
  // Merge with user options
2203
- for(const opt in opts){
2218
+ for (const opt in opts) {
2204
2219
  options[underscore(opt)] = opts[opt];
2205
2220
  }
2206
2221
  // Normalize option `bom`
2207
- if(options.bom === undefined || options.bom === null || options.bom === false){
2222
+ if (
2223
+ options.bom === undefined ||
2224
+ options.bom === null ||
2225
+ options.bom === false
2226
+ ) {
2208
2227
  options.bom = false;
2209
- }else if(options.bom !== true){
2210
- return [new CsvError('CSV_OPTION_BOOLEAN_INVALID_TYPE', [
2211
- 'option `bom` is optional and must be a boolean value,',
2212
- `got ${JSON.stringify(options.bom)}`
2213
- ])];
2228
+ } else if (options.bom !== true) {
2229
+ return [
2230
+ new CsvError("CSV_OPTION_BOOLEAN_INVALID_TYPE", [
2231
+ "option `bom` is optional and must be a boolean value,",
2232
+ `got ${JSON.stringify(options.bom)}`,
2233
+ ]),
2234
+ ];
2214
2235
  }
2215
2236
  // Normalize option `delimiter`
2216
- if(options.delimiter === undefined || options.delimiter === null){
2217
- options.delimiter = ',';
2218
- }else if(isBuffer(options.delimiter)){
2237
+ if (options.delimiter === undefined || options.delimiter === null) {
2238
+ options.delimiter = ",";
2239
+ } else if (isBuffer(options.delimiter)) {
2219
2240
  options.delimiter = options.delimiter.toString();
2220
- }else if(typeof options.delimiter !== 'string'){
2221
- return [new CsvError('CSV_OPTION_DELIMITER_INVALID_TYPE', [
2222
- 'option `delimiter` must be a buffer or a string,',
2223
- `got ${JSON.stringify(options.delimiter)}`
2224
- ])];
2241
+ } else if (typeof options.delimiter !== "string") {
2242
+ return [
2243
+ new CsvError("CSV_OPTION_DELIMITER_INVALID_TYPE", [
2244
+ "option `delimiter` must be a buffer or a string,",
2245
+ `got ${JSON.stringify(options.delimiter)}`,
2246
+ ]),
2247
+ ];
2225
2248
  }
2226
2249
  // Normalize option `quote`
2227
- if(options.quote === undefined || options.quote === null){
2250
+ if (options.quote === undefined || options.quote === null) {
2228
2251
  options.quote = '"';
2229
- }else if(options.quote === true){
2252
+ } else if (options.quote === true) {
2230
2253
  options.quote = '"';
2231
- }else if(options.quote === false){
2232
- options.quote = '';
2233
- }else if (isBuffer(options.quote)){
2254
+ } else if (options.quote === false) {
2255
+ options.quote = "";
2256
+ } else if (isBuffer(options.quote)) {
2234
2257
  options.quote = options.quote.toString();
2235
- }else if(typeof options.quote !== 'string'){
2236
- return [new CsvError('CSV_OPTION_QUOTE_INVALID_TYPE', [
2237
- 'option `quote` must be a boolean, a buffer or a string,',
2238
- `got ${JSON.stringify(options.quote)}`
2239
- ])];
2258
+ } else if (typeof options.quote !== "string") {
2259
+ return [
2260
+ new CsvError("CSV_OPTION_QUOTE_INVALID_TYPE", [
2261
+ "option `quote` must be a boolean, a buffer or a string,",
2262
+ `got ${JSON.stringify(options.quote)}`,
2263
+ ]),
2264
+ ];
2240
2265
  }
2241
2266
  // Normalize option `quoted`
2242
- if(options.quoted === undefined || options.quoted === null){
2267
+ if (options.quoted === undefined || options.quoted === null) {
2243
2268
  options.quoted = false;
2244
2269
  }
2245
2270
  // Normalize option `escape_formulas`
2246
- if(options.escape_formulas === undefined || options.escape_formulas === null){
2271
+ if (
2272
+ options.escape_formulas === undefined ||
2273
+ options.escape_formulas === null
2274
+ ) {
2247
2275
  options.escape_formulas = false;
2248
- }else if(typeof options.escape_formulas !== 'boolean'){
2249
- return [new CsvError('CSV_OPTION_ESCAPE_FORMULAS_INVALID_TYPE', [
2250
- 'option `escape_formulas` must be a boolean,',
2251
- `got ${JSON.stringify(options.escape_formulas)}`
2252
- ])];
2276
+ } else if (typeof options.escape_formulas !== "boolean") {
2277
+ return [
2278
+ new CsvError("CSV_OPTION_ESCAPE_FORMULAS_INVALID_TYPE", [
2279
+ "option `escape_formulas` must be a boolean,",
2280
+ `got ${JSON.stringify(options.escape_formulas)}`,
2281
+ ]),
2282
+ ];
2253
2283
  }
2254
2284
  // Normalize option `quoted_empty`
2255
- if(options.quoted_empty === undefined || options.quoted_empty === null){
2285
+ if (options.quoted_empty === undefined || options.quoted_empty === null) {
2256
2286
  options.quoted_empty = undefined;
2257
2287
  }
2258
2288
  // Normalize option `quoted_match`
2259
- if(options.quoted_match === undefined || options.quoted_match === null || options.quoted_match === false){
2289
+ if (
2290
+ options.quoted_match === undefined ||
2291
+ options.quoted_match === null ||
2292
+ options.quoted_match === false
2293
+ ) {
2260
2294
  options.quoted_match = null;
2261
- }else if(!Array.isArray(options.quoted_match)){
2295
+ } else if (!Array.isArray(options.quoted_match)) {
2262
2296
  options.quoted_match = [options.quoted_match];
2263
2297
  }
2264
- if(options.quoted_match){
2265
- for(const quoted_match of options.quoted_match){
2266
- const isString = typeof quoted_match === 'string';
2298
+ if (options.quoted_match) {
2299
+ for (const quoted_match of options.quoted_match) {
2300
+ const isString = typeof quoted_match === "string";
2267
2301
  const isRegExp = quoted_match instanceof RegExp;
2268
- if(!isString && !isRegExp){
2269
- return [Error(`Invalid Option: quoted_match must be a string or a regex, got ${JSON.stringify(quoted_match)}`)];
2302
+ if (!isString && !isRegExp) {
2303
+ return [
2304
+ Error(
2305
+ `Invalid Option: quoted_match must be a string or a regex, got ${JSON.stringify(quoted_match)}`,
2306
+ ),
2307
+ ];
2270
2308
  }
2271
2309
  }
2272
2310
  }
2273
2311
  // Normalize option `quoted_string`
2274
- if(options.quoted_string === undefined || options.quoted_string === null){
2312
+ if (options.quoted_string === undefined || options.quoted_string === null) {
2275
2313
  options.quoted_string = false;
2276
2314
  }
2277
2315
  // Normalize option `eof`
2278
- if(options.eof === undefined || options.eof === null){
2316
+ if (options.eof === undefined || options.eof === null) {
2279
2317
  options.eof = true;
2280
2318
  }
2281
2319
  // Normalize option `escape`
2282
- if(options.escape === undefined || options.escape === null){
2320
+ if (options.escape === undefined || options.escape === null) {
2283
2321
  options.escape = '"';
2284
- }else if(isBuffer(options.escape)){
2322
+ } else if (isBuffer(options.escape)) {
2285
2323
  options.escape = options.escape.toString();
2286
- }else if(typeof options.escape !== 'string'){
2287
- return [Error(`Invalid Option: escape must be a buffer or a string, got ${JSON.stringify(options.escape)}`)];
2288
- }
2289
- if (options.escape.length > 1){
2290
- return [Error(`Invalid Option: escape must be one character, got ${options.escape.length} characters`)];
2324
+ } else if (typeof options.escape !== "string") {
2325
+ return [
2326
+ Error(
2327
+ `Invalid Option: escape must be a buffer or a string, got ${JSON.stringify(options.escape)}`,
2328
+ ),
2329
+ ];
2330
+ }
2331
+ if (options.escape.length > 1) {
2332
+ return [
2333
+ Error(
2334
+ `Invalid Option: escape must be one character, got ${options.escape.length} characters`,
2335
+ ),
2336
+ ];
2291
2337
  }
2292
2338
  // Normalize option `header`
2293
- if(options.header === undefined || options.header === null){
2339
+ if (options.header === undefined || options.header === null) {
2294
2340
  options.header = false;
2295
2341
  }
2296
2342
  // Normalize option `columns`
2297
2343
  const [errColumns, columns] = normalize_columns(options.columns);
2298
- if(errColumns !== undefined) return [errColumns];
2344
+ if (errColumns !== undefined) return [errColumns];
2299
2345
  options.columns = columns;
2300
2346
  // Normalize option `quoted`
2301
- if(options.quoted === undefined || options.quoted === null){
2347
+ if (options.quoted === undefined || options.quoted === null) {
2302
2348
  options.quoted = false;
2303
2349
  }
2304
2350
  // Normalize option `cast`
2305
- if(options.cast === undefined || options.cast === null){
2351
+ if (options.cast === undefined || options.cast === null) {
2306
2352
  options.cast = {};
2307
2353
  }
2308
2354
  // Normalize option cast.bigint
2309
- if(options.cast.bigint === undefined || options.cast.bigint === null){
2355
+ if (options.cast.bigint === undefined || options.cast.bigint === null) {
2310
2356
  // Cast boolean to string by default
2311
- options.cast.bigint = value => '' + value;
2357
+ options.cast.bigint = (value) => "" + value;
2312
2358
  }
2313
2359
  // Normalize option cast.boolean
2314
- if(options.cast.boolean === undefined || options.cast.boolean === null){
2360
+ if (options.cast.boolean === undefined || options.cast.boolean === null) {
2315
2361
  // Cast boolean to string by default
2316
- options.cast.boolean = value => value ? '1' : '';
2362
+ options.cast.boolean = (value) => (value ? "1" : "");
2317
2363
  }
2318
2364
  // Normalize option cast.date
2319
- if(options.cast.date === undefined || options.cast.date === null){
2365
+ if (options.cast.date === undefined || options.cast.date === null) {
2320
2366
  // Cast date to timestamp string by default
2321
- options.cast.date = value => '' + value.getTime();
2367
+ options.cast.date = (value) => "" + value.getTime();
2322
2368
  }
2323
2369
  // Normalize option cast.number
2324
- if(options.cast.number === undefined || options.cast.number === null){
2370
+ if (options.cast.number === undefined || options.cast.number === null) {
2325
2371
  // Cast number to string using native casting by default
2326
- options.cast.number = value => '' + value;
2372
+ options.cast.number = (value) => "" + value;
2327
2373
  }
2328
2374
  // Normalize option cast.object
2329
- if(options.cast.object === undefined || options.cast.object === null){
2375
+ if (options.cast.object === undefined || options.cast.object === null) {
2330
2376
  // Stringify object as JSON by default
2331
- options.cast.object = value => JSON.stringify(value);
2377
+ options.cast.object = (value) => JSON.stringify(value);
2332
2378
  }
2333
2379
  // Normalize option cast.string
2334
- if(options.cast.string === undefined || options.cast.string === null){
2380
+ if (options.cast.string === undefined || options.cast.string === null) {
2335
2381
  // Leave string untouched
2336
- options.cast.string = function(value){return value;};
2382
+ options.cast.string = function (value) {
2383
+ return value;
2384
+ };
2337
2385
  }
2338
2386
  // Normalize option `on_record`
2339
- if(options.on_record !== undefined && typeof options.on_record !== 'function'){
2387
+ if (
2388
+ options.on_record !== undefined &&
2389
+ typeof options.on_record !== "function"
2390
+ ) {
2340
2391
  return [Error(`Invalid Option: "on_record" must be a function.`)];
2341
2392
  }
2342
2393
  // Normalize option `record_delimiter`
2343
- if(options.record_delimiter === undefined || options.record_delimiter === null){
2344
- options.record_delimiter = '\n';
2345
- }else if(isBuffer(options.record_delimiter)){
2346
- options.record_delimiter = options.record_delimiter.toString();
2347
- }else if(typeof options.record_delimiter !== 'string'){
2348
- return [Error(`Invalid Option: record_delimiter must be a buffer or a string, got ${JSON.stringify(options.record_delimiter)}`)];
2349
- }
2350
- switch(options.record_delimiter){
2351
- case 'unix':
2394
+ if (
2395
+ options.record_delimiter === undefined ||
2396
+ options.record_delimiter === null
2397
+ ) {
2352
2398
  options.record_delimiter = "\n";
2353
- break;
2354
- case 'mac':
2355
- options.record_delimiter = "\r";
2356
- break;
2357
- case 'windows':
2358
- options.record_delimiter = "\r\n";
2359
- break;
2360
- case 'ascii':
2361
- options.record_delimiter = "\u001e";
2362
- break;
2363
- case 'unicode':
2364
- options.record_delimiter = "\u2028";
2365
- break;
2399
+ } else if (isBuffer(options.record_delimiter)) {
2400
+ options.record_delimiter = options.record_delimiter.toString();
2401
+ } else if (typeof options.record_delimiter !== "string") {
2402
+ return [
2403
+ Error(
2404
+ `Invalid Option: record_delimiter must be a buffer or a string, got ${JSON.stringify(options.record_delimiter)}`,
2405
+ ),
2406
+ ];
2407
+ }
2408
+ switch (options.record_delimiter) {
2409
+ case "unix":
2410
+ options.record_delimiter = "\n";
2411
+ break;
2412
+ case "mac":
2413
+ options.record_delimiter = "\r";
2414
+ break;
2415
+ case "windows":
2416
+ options.record_delimiter = "\r\n";
2417
+ break;
2418
+ case "ascii":
2419
+ options.record_delimiter = "\u001e";
2420
+ break;
2421
+ case "unicode":
2422
+ options.record_delimiter = "\u2028";
2423
+ break;
2366
2424
  }
2367
2425
  return [undefined, options];
2368
2426
  };
2369
2427
 
2370
2428
  const bom_utf8 = Buffer.from([239, 187, 191]);
2371
2429
 
2372
- const stringifier = function(options, state, info){
2430
+ const stringifier = function (options, state, info) {
2373
2431
  return {
2374
2432
  options: options,
2375
2433
  state: state,
2376
2434
  info: info,
2377
- __transform: function(chunk, push){
2435
+ __transform: function (chunk, push) {
2378
2436
  // Chunk validation
2379
- if(!Array.isArray(chunk) && typeof chunk !== 'object'){
2380
- return Error(`Invalid Record: expect an array or an object, got ${JSON.stringify(chunk)}`);
2437
+ if (!Array.isArray(chunk) && typeof chunk !== "object") {
2438
+ return Error(
2439
+ `Invalid Record: expect an array or an object, got ${JSON.stringify(chunk)}`,
2440
+ );
2381
2441
  }
2382
2442
  // Detect columns from the first record
2383
- if(this.info.records === 0){
2384
- if(Array.isArray(chunk)){
2385
- if(this.options.header === true && this.options.columns === undefined){
2386
- return Error('Undiscoverable Columns: header option requires column option or object records');
2443
+ if (this.info.records === 0) {
2444
+ if (Array.isArray(chunk)) {
2445
+ if (
2446
+ this.options.header === true &&
2447
+ this.options.columns === undefined
2448
+ ) {
2449
+ return Error(
2450
+ "Undiscoverable Columns: header option requires column option or object records",
2451
+ );
2387
2452
  }
2388
- }else if(this.options.columns === undefined){
2453
+ } else if (this.options.columns === undefined) {
2389
2454
  const [err, columns] = normalize_columns(Object.keys(chunk));
2390
- if(err) return;
2455
+ if (err) return;
2391
2456
  this.options.columns = columns;
2392
2457
  }
2393
2458
  }
2394
2459
  // Emit the header
2395
- if(this.info.records === 0){
2460
+ if (this.info.records === 0) {
2396
2461
  this.bom(push);
2397
2462
  const err = this.headers(push);
2398
- if(err) return err;
2463
+ if (err) return err;
2399
2464
  }
2400
2465
  // Emit and stringify the record if an object or an array
2401
- try{
2466
+ try {
2402
2467
  // this.emit('record', chunk, this.info.records);
2403
- if(this.options.on_record){
2468
+ if (this.options.on_record) {
2404
2469
  this.options.on_record(chunk, this.info.records);
2405
2470
  }
2406
- }catch(err){
2471
+ } catch (err) {
2407
2472
  return err;
2408
2473
  }
2409
2474
  // Convert the record into a string
2410
2475
  let err, chunk_string;
2411
- if(this.options.eof){
2476
+ if (this.options.eof) {
2412
2477
  [err, chunk_string] = this.stringify(chunk);
2413
- if(err) return err;
2414
- if(chunk_string === undefined){
2478
+ if (err) return err;
2479
+ if (chunk_string === undefined) {
2415
2480
  return;
2416
- }else {
2481
+ } else {
2417
2482
  chunk_string = chunk_string + this.options.record_delimiter;
2418
2483
  }
2419
- }else {
2484
+ } else {
2420
2485
  [err, chunk_string] = this.stringify(chunk);
2421
- if(err) return err;
2422
- if(chunk_string === undefined){
2486
+ if (err) return err;
2487
+ if (chunk_string === undefined) {
2423
2488
  return;
2424
- }else {
2425
- if(this.options.header || this.info.records){
2489
+ } else {
2490
+ if (this.options.header || this.info.records) {
2426
2491
  chunk_string = this.options.record_delimiter + chunk_string;
2427
2492
  }
2428
2493
  }
@@ -2431,96 +2496,136 @@ const stringifier = function(options, state, info){
2431
2496
  this.info.records++;
2432
2497
  push(chunk_string);
2433
2498
  },
2434
- stringify: function(chunk, chunkIsHeader=false){
2435
- if(typeof chunk !== 'object'){
2499
+ stringify: function (chunk, chunkIsHeader = false) {
2500
+ if (typeof chunk !== "object") {
2436
2501
  return [undefined, chunk];
2437
2502
  }
2438
- const {columns} = this.options;
2503
+ const { columns } = this.options;
2439
2504
  const record = [];
2440
2505
  // Record is an array
2441
- if(Array.isArray(chunk)){
2506
+ if (Array.isArray(chunk)) {
2442
2507
  // We are getting an array but the user has specified output columns. In
2443
2508
  // this case, we respect the columns indexes
2444
- if(columns){
2509
+ if (columns) {
2445
2510
  chunk.splice(columns.length);
2446
2511
  }
2447
2512
  // Cast record elements
2448
- for(let i=0; i<chunk.length; i++){
2513
+ for (let i = 0; i < chunk.length; i++) {
2449
2514
  const field = chunk[i];
2450
2515
  const [err, value] = this.__cast(field, {
2451
- index: i, column: i, records: this.info.records, header: chunkIsHeader
2516
+ index: i,
2517
+ column: i,
2518
+ records: this.info.records,
2519
+ header: chunkIsHeader,
2452
2520
  });
2453
- if(err) return [err];
2521
+ if (err) return [err];
2454
2522
  record[i] = [value, field];
2455
2523
  }
2456
- // Record is a literal object
2457
- // `columns` is always defined: it is either provided or discovered.
2458
- }else {
2459
- for(let i=0; i<columns.length; i++){
2524
+ // Record is a literal object
2525
+ // `columns` is always defined: it is either provided or discovered.
2526
+ } else {
2527
+ for (let i = 0; i < columns.length; i++) {
2460
2528
  const field = get(chunk, columns[i].key);
2461
2529
  const [err, value] = this.__cast(field, {
2462
- index: i, column: columns[i].key, records: this.info.records, header: chunkIsHeader
2530
+ index: i,
2531
+ column: columns[i].key,
2532
+ records: this.info.records,
2533
+ header: chunkIsHeader,
2463
2534
  });
2464
- if(err) return [err];
2535
+ if (err) return [err];
2465
2536
  record[i] = [value, field];
2466
2537
  }
2467
2538
  }
2468
- let csvrecord = '';
2469
- for(let i=0; i<record.length; i++){
2539
+ let csvrecord = "";
2540
+ for (let i = 0; i < record.length; i++) {
2470
2541
  let options, err;
2471
- // eslint-disable-next-line
2542
+
2472
2543
  let [value, field] = record[i];
2473
- if(typeof value === "string"){
2544
+ if (typeof value === "string") {
2474
2545
  options = this.options;
2475
- }else if(is_object(value)){
2546
+ } else if (is_object(value)) {
2476
2547
  options = value;
2477
2548
  value = options.value;
2478
2549
  delete options.value;
2479
- if(typeof value !== "string" && value !== undefined && value !== null){
2480
- if(err) return [Error(`Invalid Casting Value: returned value must return a string, null or undefined, got ${JSON.stringify(value)}`)];
2550
+ if (
2551
+ typeof value !== "string" &&
2552
+ value !== undefined &&
2553
+ value !== null
2554
+ ) {
2555
+ if (err)
2556
+ return [
2557
+ Error(
2558
+ `Invalid Casting Value: returned value must return a string, null or undefined, got ${JSON.stringify(value)}`,
2559
+ ),
2560
+ ];
2481
2561
  }
2482
- options = {...this.options, ...options};
2562
+ options = { ...this.options, ...options };
2483
2563
  [err, options] = normalize_options(options);
2484
- if(err !== undefined){
2564
+ if (err !== undefined) {
2485
2565
  return [err];
2486
2566
  }
2487
- }else if(value === undefined || value === null){
2567
+ } else if (value === undefined || value === null) {
2488
2568
  options = this.options;
2489
- }else {
2490
- return [Error(`Invalid Casting Value: returned value must return a string, an object, null or undefined, got ${JSON.stringify(value)}`)];
2569
+ } else {
2570
+ return [
2571
+ Error(
2572
+ `Invalid Casting Value: returned value must return a string, an object, null or undefined, got ${JSON.stringify(value)}`,
2573
+ ),
2574
+ ];
2491
2575
  }
2492
- const {delimiter, escape, quote, quoted, quoted_empty, quoted_string, quoted_match, record_delimiter, escape_formulas} = options;
2493
- if('' === value && '' === field){
2494
- let quotedMatch = quoted_match && quoted_match.filter(quoted_match => {
2495
- if(typeof quoted_match === 'string'){
2496
- return value.indexOf(quoted_match) !== -1;
2497
- }else {
2498
- return quoted_match.test(value);
2499
- }
2500
- });
2576
+ const {
2577
+ delimiter,
2578
+ escape,
2579
+ quote,
2580
+ quoted,
2581
+ quoted_empty,
2582
+ quoted_string,
2583
+ quoted_match,
2584
+ record_delimiter,
2585
+ escape_formulas,
2586
+ } = options;
2587
+ if ("" === value && "" === field) {
2588
+ let quotedMatch =
2589
+ quoted_match &&
2590
+ quoted_match.filter((quoted_match) => {
2591
+ if (typeof quoted_match === "string") {
2592
+ return value.indexOf(quoted_match) !== -1;
2593
+ } else {
2594
+ return quoted_match.test(value);
2595
+ }
2596
+ });
2501
2597
  quotedMatch = quotedMatch && quotedMatch.length > 0;
2502
- const shouldQuote = quotedMatch || true === quoted_empty ||
2598
+ const shouldQuote =
2599
+ quotedMatch ||
2600
+ true === quoted_empty ||
2503
2601
  (true === quoted_string && false !== quoted_empty);
2504
- if(shouldQuote === true){
2602
+ if (shouldQuote === true) {
2505
2603
  value = quote + value + quote;
2506
2604
  }
2507
2605
  csvrecord += value;
2508
- }else if(value){
2509
- if(typeof value !== 'string'){
2510
- return [Error(`Formatter must return a string, null or undefined, got ${JSON.stringify(value)}`)];
2606
+ } else if (value) {
2607
+ if (typeof value !== "string") {
2608
+ return [
2609
+ Error(
2610
+ `Formatter must return a string, null or undefined, got ${JSON.stringify(value)}`,
2611
+ ),
2612
+ ];
2511
2613
  }
2512
- const containsdelimiter = delimiter.length && value.indexOf(delimiter) >= 0;
2513
- const containsQuote = (quote !== '') && value.indexOf(quote) >= 0;
2514
- const containsEscape = value.indexOf(escape) >= 0 && (escape !== quote);
2614
+ const containsdelimiter =
2615
+ delimiter.length && value.indexOf(delimiter) >= 0;
2616
+ const containsQuote = quote !== "" && value.indexOf(quote) >= 0;
2617
+ const containsEscape = value.indexOf(escape) >= 0 && escape !== quote;
2515
2618
  const containsRecordDelimiter = value.indexOf(record_delimiter) >= 0;
2516
- const quotedString = quoted_string && typeof field === 'string';
2517
- let quotedMatch = quoted_match && quoted_match.filter(quoted_match => {
2518
- if(typeof quoted_match === 'string'){
2519
- return value.indexOf(quoted_match) !== -1;
2520
- }else {
2521
- return quoted_match.test(value);
2522
- }
2523
- });
2619
+ const quotedString = quoted_string && typeof field === "string";
2620
+ let quotedMatch =
2621
+ quoted_match &&
2622
+ quoted_match.filter((quoted_match) => {
2623
+ if (typeof quoted_match === "string") {
2624
+ return value.indexOf(quoted_match) !== -1;
2625
+ } else {
2626
+ return quoted_match.test(value);
2627
+ }
2628
+ });
2524
2629
  quotedMatch = quotedMatch && quotedMatch.length > 0;
2525
2630
  // See https://github.com/adaltas/node-csv/pull/387
2526
2631
  // More about CSV injection or formula injection, when websites embed
@@ -2530,121 +2635,132 @@ const stringifier = function(options, state, info){
2530
2635
  // Apple Numbers unicode normalization is empirical from testing
2531
2636
  if (escape_formulas) {
2532
2637
  switch (value[0]) {
2533
- case '=':
2534
- case '+':
2535
- case '-':
2536
- case '@':
2537
- case '\t':
2538
- case '\r':
2539
- case '\uFF1D': // Unicode '='
2540
- case '\uFF0B': // Unicode '+'
2541
- case '\uFF0D': // Unicode '-'
2542
- case '\uFF20': // Unicode '@'
2543
- value = `'${value}`;
2544
- break;
2638
+ case "=":
2639
+ case "+":
2640
+ case "-":
2641
+ case "@":
2642
+ case "\t":
2643
+ case "\r":
2644
+ case "\uFF1D": // Unicode '='
2645
+ case "\uFF0B": // Unicode '+'
2646
+ case "\uFF0D": // Unicode '-'
2647
+ case "\uFF20": // Unicode '@'
2648
+ value = `'${value}`;
2649
+ break;
2545
2650
  }
2546
2651
  }
2547
- const shouldQuote = containsQuote === true || containsdelimiter || containsRecordDelimiter || quoted || quotedString || quotedMatch;
2548
- if(shouldQuote === true && containsEscape === true){
2549
- const regexp = escape === '\\'
2550
- ? new RegExp(escape + escape, 'g')
2551
- : new RegExp(escape, 'g');
2652
+ const shouldQuote =
2653
+ containsQuote === true ||
2654
+ containsdelimiter ||
2655
+ containsRecordDelimiter ||
2656
+ quoted ||
2657
+ quotedString ||
2658
+ quotedMatch;
2659
+ if (shouldQuote === true && containsEscape === true) {
2660
+ const regexp =
2661
+ escape === "\\"
2662
+ ? new RegExp(escape + escape, "g")
2663
+ : new RegExp(escape, "g");
2552
2664
  value = value.replace(regexp, escape + escape);
2553
2665
  }
2554
- if(containsQuote === true){
2555
- const regexp = new RegExp(quote,'g');
2666
+ if (containsQuote === true) {
2667
+ const regexp = new RegExp(quote, "g");
2556
2668
  value = value.replace(regexp, escape + quote);
2557
2669
  }
2558
- if(shouldQuote === true){
2670
+ if (shouldQuote === true) {
2559
2671
  value = quote + value + quote;
2560
2672
  }
2561
2673
  csvrecord += value;
2562
- }else if(quoted_empty === true || (field === '' && quoted_string === true && quoted_empty !== false)){
2674
+ } else if (
2675
+ quoted_empty === true ||
2676
+ (field === "" && quoted_string === true && quoted_empty !== false)
2677
+ ) {
2563
2678
  csvrecord += quote + quote;
2564
2679
  }
2565
- if(i !== record.length - 1){
2680
+ if (i !== record.length - 1) {
2566
2681
  csvrecord += delimiter;
2567
2682
  }
2568
2683
  }
2569
2684
  return [undefined, csvrecord];
2570
2685
  },
2571
- bom: function(push){
2572
- if(this.options.bom !== true){
2686
+ bom: function (push) {
2687
+ if (this.options.bom !== true) {
2573
2688
  return;
2574
2689
  }
2575
2690
  push(bom_utf8);
2576
2691
  },
2577
- headers: function(push){
2578
- if(this.options.header === false){
2692
+ headers: function (push) {
2693
+ if (this.options.header === false) {
2579
2694
  return;
2580
2695
  }
2581
- if(this.options.columns === undefined){
2696
+ if (this.options.columns === undefined) {
2582
2697
  return;
2583
2698
  }
2584
2699
  let err;
2585
- let headers = this.options.columns.map(column => column.header);
2586
- if(this.options.eof){
2700
+ let headers = this.options.columns.map((column) => column.header);
2701
+ if (this.options.eof) {
2587
2702
  [err, headers] = this.stringify(headers, true);
2588
2703
  headers += this.options.record_delimiter;
2589
- }else {
2704
+ } else {
2590
2705
  [err, headers] = this.stringify(headers);
2591
2706
  }
2592
- if(err) return err;
2707
+ if (err) return err;
2593
2708
  push(headers);
2594
2709
  },
2595
- __cast: function(value, context){
2710
+ __cast: function (value, context) {
2596
2711
  const type = typeof value;
2597
- try{
2598
- if(type === 'string'){ // Fine for 99% of the cases
2712
+ try {
2713
+ if (type === "string") {
2714
+ // Fine for 99% of the cases
2599
2715
  return [undefined, this.options.cast.string(value, context)];
2600
- }else if(type === 'bigint'){
2716
+ } else if (type === "bigint") {
2601
2717
  return [undefined, this.options.cast.bigint(value, context)];
2602
- }else if(type === 'number'){
2718
+ } else if (type === "number") {
2603
2719
  return [undefined, this.options.cast.number(value, context)];
2604
- }else if(type === 'boolean'){
2720
+ } else if (type === "boolean") {
2605
2721
  return [undefined, this.options.cast.boolean(value, context)];
2606
- }else if(value instanceof Date){
2722
+ } else if (value instanceof Date) {
2607
2723
  return [undefined, this.options.cast.date(value, context)];
2608
- }else if(type === 'object' && value !== null){
2724
+ } else if (type === "object" && value !== null) {
2609
2725
  return [undefined, this.options.cast.object(value, context)];
2610
- }else {
2726
+ } else {
2611
2727
  return [undefined, value, value];
2612
2728
  }
2613
- }catch(err){
2729
+ } catch (err) {
2614
2730
  return [err];
2615
2731
  }
2616
- }
2732
+ },
2617
2733
  };
2618
2734
  };
2619
2735
 
2620
- const stringify = function(records, opts={}){
2736
+ const stringify = function (records, opts = {}) {
2621
2737
  const data = [];
2622
2738
  const [err, options] = normalize_options(opts);
2623
- if(err !== undefined) throw err;
2739
+ if (err !== undefined) throw err;
2624
2740
  const state = {
2625
- stop: false
2741
+ stop: false,
2626
2742
  };
2627
2743
  // Information
2628
2744
  const info = {
2629
- records: 0
2745
+ records: 0,
2630
2746
  };
2631
2747
  const api = stringifier(options, state, info);
2632
- for(const record of records){
2633
- const err = api.__transform(record, function(record){
2748
+ for (const record of records) {
2749
+ const err = api.__transform(record, function (record) {
2634
2750
  data.push(record);
2635
2751
  });
2636
- if(err !== undefined) throw err;
2752
+ if (err !== undefined) throw err;
2637
2753
  }
2638
- if(data.length === 0){
2754
+ if (data.length === 0) {
2639
2755
  api.bom((d) => {
2640
2756
  data.push(d);
2641
2757
  });
2642
2758
  const err = api.headers((headers) => {
2643
2759
  data.push(headers);
2644
2760
  });
2645
- if(err !== undefined) throw err;
2761
+ if (err !== undefined) throw err;
2646
2762
  }
2647
- return data.join('');
2763
+ return data.join("");
2648
2764
  };
2649
2765
 
2650
2766
  var styles = "/**\n *\n * IBM Confidential\n *\n * (C) Copyright IBM Corp. 2024\n *\n * The source code for this program is not published or otherwise\n * divested of its trade secrets, irrespective of what has been\n * deposited with the U. S. Copyright Office\n *\n * US Government Users Restricted Rights - Use, duplication or\n * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.\n *\n */\ncds-table-header-title,\ncds-table-header-description,\ncds-table-toolbar {\n position: sticky;\n width: var(--cds-chat-table-width, auto);\n left: 0;\n}\n\n:dir(rtl) cds-table-header-title,\n:dir(rtl) cds-table-header-description,\n:dir(rtl) cds-table-toolbar {\n left: unset;\n right: 0;\n}\n\ncds-table-header-title,\ncds-table-header-description {\n width: calc(var(--cds-chat-table-width, auto) - 1rem - 1rem);\n margin-left: -1rem;\n margin-right: -1rem;\n padding: 0 1rem;\n}\n\ncds-table-header-description {\n margin-bottom: -0.5rem;\n}\n\ncds-pagination {\n width: 100%;\n}";
@@ -2664,9 +2780,9 @@ var styles = "/**\n *\n * IBM Confidential\n *\n * (C) Copyright IBM Corp. 2024\
2664
2780
  *
2665
2781
  */
2666
2782
  const Download16svg = toString$1({
2667
- ..._16,
2783
+ ...Download16,
2668
2784
  attrs: {
2669
- ..._16.attrs,
2785
+ ...Download16.attrs,
2670
2786
  slot: 'icon',
2671
2787
  },
2672
2788
  });