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