@elliemae/ds-csv-converter 3.0.0-next.2 → 3.0.0-next.6

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.
@@ -0,0 +1,87 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __reExport = (target, module2, copyDefault, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
+ __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
+ }
18
+ return target;
19
+ };
20
+ var __toESM = (module2, isNodeMode) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
+ };
23
+ var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
+ return (module2, temp) => {
25
+ return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
+ };
27
+ })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
+ var src_exports = {};
29
+ __export(src_exports, {
30
+ list2csv: () => list2csv,
31
+ listToCsvBlob: () => listToCsvBlob,
32
+ listToCsvFile: () => listToCsvFile
33
+ });
34
+ var React = __toESM(require("react"));
35
+ const argIsRecord = (arg) => !!arg && arg instanceof Map === false;
36
+ function list2csv(list, map) {
37
+ let headerMap;
38
+ if (argIsRecord(map)) {
39
+ headerMap = new Map(Object.entries(map));
40
+ } else {
41
+ headerMap = map;
42
+ }
43
+ const columns = headerMap && Array.from(headerMap.keys()) || Object.keys(list[0] || {});
44
+ const header = columns.map((v) => `"${headerMap ? headerMap.get(v) : v}"`).join(",");
45
+ const content = list.map((item) => columns.map((key) => {
46
+ let finalCell;
47
+ const cell = item[key];
48
+ finalCell = cell;
49
+ if (typeof cell === "string")
50
+ finalCell = cell.replace(/"/g, '""');
51
+ return `"${finalCell}"`;
52
+ }).join(",")).join("\r\n");
53
+ return `${header}\r
54
+ ${content}`;
55
+ }
56
+ function listToCsvBlob(list, map) {
57
+ const data = list2csv(list, map);
58
+ return new Blob([data], {
59
+ type: "text/csv;charset=utf-8;"
60
+ });
61
+ }
62
+ function listToCsvFile(list, fileName = "list", map) {
63
+ if (!document.createElement && !navigator.msSaveBlob) {
64
+ throw new Error(`
65
+ Can not export to file without document/navigator msSaveBlob functionality.
66
+ Use listToCsvBlob and handle file creation on your side instead.
67
+ `);
68
+ }
69
+ const blob = listToCsvBlob(list, map);
70
+ const finalFileName = `${fileName}.csv`;
71
+ if (navigator.msSaveBlob) {
72
+ navigator.msSaveBlob(blob, finalFileName);
73
+ } else {
74
+ const link = document.createElement("a");
75
+ if (link.download !== void 0) {
76
+ const url = URL.createObjectURL(blob);
77
+ link.setAttribute("href", url);
78
+ link.setAttribute("download", finalFileName);
79
+ link.style.visibility = "hidden";
80
+ document.body.appendChild(link);
81
+ link.click();
82
+ document.body.removeChild(link);
83
+ }
84
+ }
85
+ }
86
+ module.exports = __toCommonJS(src_exports);
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.tsx", "../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["const argIsRecord = (arg: unknown): arg is Record<string, string> => !!arg && arg instanceof Map === false;\n// https://github.com/BubbleBear/list2csv/blob/master/src/index.ts\nexport function list2csv(list: Record<string, string>[], map: Record<string, string> | Map<string, string>): string {\n let headerMap: Map<string, string>;\n\n if (argIsRecord(map)) {\n headerMap = new Map(Object.entries(map));\n } else {\n headerMap = map;\n }\n\n const columns = (headerMap && Array.from(headerMap.keys())) || Object.keys(list[0] || {});\n\n const header = columns.map((v) => `\"${headerMap ? headerMap.get(v) : v}\"`).join(',');\n\n const content = list\n .map((item) =>\n columns\n .map((key) => {\n let finalCell;\n const cell = item[key];\n finalCell = cell;\n if (typeof cell === 'string') finalCell = cell.replace(/\"/g, '\"\"');\n return `\"${finalCell}\"`;\n })\n .join(','),\n )\n .join('\\r\\n');\n\n return `${header}\\r\\n${content}`;\n}\n\nexport function listToCsvBlob(list: Record<string, string>[], map: Record<string, string> | Map<string, string>): Blob {\n const data = list2csv(list, map);\n return new Blob([data], {\n type: 'text/csv;charset=utf-8;',\n });\n}\n\nexport function listToCsvFile(\n list: Record<string, string>[],\n fileName = 'list',\n map: Record<string, string> | Map<string, string>,\n): void {\n if (!document.createElement && !navigator.msSaveBlob) {\n throw new Error(`\n Can not export to file without document/navigator msSaveBlob functionality.\n Use listToCsvBlob and handle file creation on your side instead.\n `);\n }\n const blob = listToCsvBlob(list, map);\n const finalFileName = `${fileName}.csv`;\n\n if (navigator.msSaveBlob) {\n // IE 10+\n navigator.msSaveBlob(blob, finalFileName);\n } else {\n const link = document.createElement('a');\n if (link.download !== undefined) {\n // feature detection\n // Browsers that support HTML5 download attribute\n const url = URL.createObjectURL(blob);\n link.setAttribute('href', url);\n link.setAttribute('download', finalFileName);\n link.style.visibility = 'hidden';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n }\n }\n}\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,MAAM,cAAc,CAAC,QAAgD,CAAC,CAAC,OAAO,eA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* as React from "react";
2
+ const argIsRecord = (arg) => !!arg && arg instanceof Map === false;
3
+ function list2csv(list, map) {
4
+ let headerMap;
5
+ if (argIsRecord(map)) {
6
+ headerMap = new Map(Object.entries(map));
7
+ } else {
8
+ headerMap = map;
9
+ }
10
+ const columns = headerMap && Array.from(headerMap.keys()) || Object.keys(list[0] || {});
11
+ const header = columns.map((v) => `"${headerMap ? headerMap.get(v) : v}"`).join(",");
12
+ const content = list.map((item) => columns.map((key) => {
13
+ let finalCell;
14
+ const cell = item[key];
15
+ finalCell = cell;
16
+ if (typeof cell === "string")
17
+ finalCell = cell.replace(/"/g, '""');
18
+ return `"${finalCell}"`;
19
+ }).join(",")).join("\r\n");
20
+ return `${header}\r
21
+ ${content}`;
22
+ }
23
+ function listToCsvBlob(list, map) {
24
+ const data = list2csv(list, map);
25
+ return new Blob([data], {
26
+ type: "text/csv;charset=utf-8;"
27
+ });
28
+ }
29
+ function listToCsvFile(list, fileName = "list", map) {
30
+ if (!document.createElement && !navigator.msSaveBlob) {
31
+ throw new Error(`
32
+ Can not export to file without document/navigator msSaveBlob functionality.
33
+ Use listToCsvBlob and handle file creation on your side instead.
34
+ `);
35
+ }
36
+ const blob = listToCsvBlob(list, map);
37
+ const finalFileName = `${fileName}.csv`;
38
+ if (navigator.msSaveBlob) {
39
+ navigator.msSaveBlob(blob, finalFileName);
40
+ } else {
41
+ const link = document.createElement("a");
42
+ if (link.download !== void 0) {
43
+ const url = URL.createObjectURL(blob);
44
+ link.setAttribute("href", url);
45
+ link.setAttribute("download", finalFileName);
46
+ link.style.visibility = "hidden";
47
+ document.body.appendChild(link);
48
+ link.click();
49
+ document.body.removeChild(link);
50
+ }
51
+ }
52
+ }
53
+ export {
54
+ list2csv,
55
+ listToCsvBlob,
56
+ listToCsvFile
57
+ };
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/index.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "const argIsRecord = (arg: unknown): arg is Record<string, string> => !!arg && arg instanceof Map === false;\n// https://github.com/BubbleBear/list2csv/blob/master/src/index.ts\nexport function list2csv(list: Record<string, string>[], map: Record<string, string> | Map<string, string>): string {\n let headerMap: Map<string, string>;\n\n if (argIsRecord(map)) {\n headerMap = new Map(Object.entries(map));\n } else {\n headerMap = map;\n }\n\n const columns = (headerMap && Array.from(headerMap.keys())) || Object.keys(list[0] || {});\n\n const header = columns.map((v) => `\"${headerMap ? headerMap.get(v) : v}\"`).join(',');\n\n const content = list\n .map((item) =>\n columns\n .map((key) => {\n let finalCell;\n const cell = item[key];\n finalCell = cell;\n if (typeof cell === 'string') finalCell = cell.replace(/\"/g, '\"\"');\n return `\"${finalCell}\"`;\n })\n .join(','),\n )\n .join('\\r\\n');\n\n return `${header}\\r\\n${content}`;\n}\n\nexport function listToCsvBlob(list: Record<string, string>[], map: Record<string, string> | Map<string, string>): Blob {\n const data = list2csv(list, map);\n return new Blob([data], {\n type: 'text/csv;charset=utf-8;',\n });\n}\n\nexport function listToCsvFile(\n list: Record<string, string>[],\n fileName = 'list',\n map: Record<string, string> | Map<string, string>,\n): void {\n if (!document.createElement && !navigator.msSaveBlob) {\n throw new Error(`\n Can not export to file without document/navigator msSaveBlob functionality.\n Use listToCsvBlob and handle file creation on your side instead.\n `);\n }\n const blob = listToCsvBlob(list, map);\n const finalFileName = `${fileName}.csv`;\n\n if (navigator.msSaveBlob) {\n // IE 10+\n navigator.msSaveBlob(blob, finalFileName);\n } else {\n const link = document.createElement('a');\n if (link.download !== undefined) {\n // feature detection\n // Browsers that support HTML5 download attribute\n const url = URL.createObjectURL(blob);\n link.setAttribute('href', url);\n link.setAttribute('download', finalFileName);\n link.style.visibility = 'hidden';\n document.body.appendChild(link);\n link.click();\n document.body.removeChild(link);\n }\n }\n}\n"],
5
+ "mappings": "AAAA;ACAA,MAAM,cAAc,CAAC,QAAgD,CAAC,CAAC,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-1,15 +1,18 @@
1
1
  {
2
2
  "name": "@elliemae/ds-csv-converter",
3
- "version": "3.0.0-next.2",
3
+ "version": "3.0.0-next.6",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - CSV converting utilities",
6
- "module": "./esm/index.js",
7
- "main": "./cjs/index.js",
8
- "types": "./types/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "module": "./dist/esm/index.js",
10
+ "main": "./dist/cjs/index.js",
11
+ "types": "./dist/types/index.d.ts",
9
12
  "exports": {
10
13
  ".": {
11
- "import": "./esm/index.js",
12
- "require": "./cjs/index.js"
14
+ "import": "./dist/esm/index.js",
15
+ "require": "./dist/cjs/index.js"
13
16
  }
14
17
  },
15
18
  "sideEffects": [],
@@ -18,19 +21,25 @@
18
21
  "url": "https://git.elliemae.io/platform-ui/dimsum.git"
19
22
  },
20
23
  "engines": {
21
- "npm": ">=7",
22
- "node": ">=14"
24
+ "pnpm": ">=6",
25
+ "node": ">=16"
23
26
  },
24
27
  "author": "ICE MT",
25
- "scripts": {
26
- "prebuild": "exit 0",
27
- "predev": "exit 0",
28
- "build": "node ../../scripts/build/build.js",
29
- "dev": "cross-env NODE_ENV=development && node ../../scripts/build/build.js -w"
28
+ "jestSonar": {
29
+ "sonar56x": true,
30
+ "reportPath": "reports",
31
+ "reportFile": "tests.xml",
32
+ "indent": 4
30
33
  },
31
34
  "publishConfig": {
32
35
  "access": "public",
33
- "directory": "dist",
34
- "generateSubmodules": true
36
+ "typeSafety": false
37
+ },
38
+ "scripts": {
39
+ "test": "node ../../scripts/testing/test.mjs",
40
+ "lint": "node ../../scripts/lint.mjs",
41
+ "dts": "node ../../scripts/dts.mjs",
42
+ "build": "cross-env NODE_ENV=production node ../../scripts/build/build.mjs",
43
+ "dev": "cross-env NODE_ENV=development node ../../scripts/build/build.mjs --watch"
35
44
  }
36
45
  }
package/cjs/index.js DELETED
@@ -1,88 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- require('core-js/modules/esnext.map.delete-all.js');
6
- require('core-js/modules/esnext.map.emplace.js');
7
- require('core-js/modules/esnext.map.every.js');
8
- require('core-js/modules/esnext.map.filter.js');
9
- require('core-js/modules/esnext.map.find.js');
10
- require('core-js/modules/esnext.map.find-key.js');
11
- require('core-js/modules/esnext.map.includes.js');
12
- require('core-js/modules/esnext.map.key-of.js');
13
- require('core-js/modules/esnext.map.map-keys.js');
14
- require('core-js/modules/esnext.map.map-values.js');
15
- require('core-js/modules/esnext.map.merge.js');
16
- require('core-js/modules/esnext.map.reduce.js');
17
- require('core-js/modules/esnext.map.some.js');
18
- require('core-js/modules/esnext.map.update.js');
19
- require('core-js/modules/web.dom-collections.iterator.js');
20
- require('core-js/modules/esnext.async-iterator.map.js');
21
- require('core-js/modules/esnext.iterator.map.js');
22
- require('core-js/modules/es.string.replace.js');
23
- require('core-js/modules/web.url.js');
24
- require('core-js/modules/web.url-search-params.js');
25
-
26
- const argIsMap = arg => arg && arg instanceof Map === false; // https://github.com/BubbleBear/list2csv/blob/master/src/index.ts
27
-
28
-
29
- function list2csv(list, map) {
30
- let headerMap;
31
-
32
- if (argIsMap(map)) {
33
- headerMap = map;
34
- } else {
35
- headerMap = new Map(Object.entries(map));
36
- }
37
-
38
- const columns = headerMap && Array.from(headerMap.keys()) || Object.keys(list[0] || {});
39
- const header = columns.map(v => "\"".concat(headerMap ? headerMap.get(v) : v, "\"")).join(',');
40
- const content = list.map(item => columns.map(key => {
41
- let finalCell;
42
- const cell = item[key];
43
- finalCell = cell;
44
- if (typeof cell === 'string') finalCell = cell.replace(/"/g, '""');
45
- return "\"".concat(finalCell, "\"");
46
- }).join(',')).join('\r\n');
47
- return "".concat(header, "\r\n").concat(content);
48
- }
49
- function listToCsvBlob(list, map) {
50
- const data = list2csv(list, map);
51
- return new Blob([data], {
52
- type: 'text/csv;charset=utf-8;'
53
- });
54
- }
55
- function listToCsvFile(list) {
56
- let fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'list';
57
- let map = arguments.length > 2 ? arguments[2] : undefined;
58
-
59
- if (!document.createElement && !navigator.msSaveBlob) {
60
- throw new Error("\n Can not export to file without document/navigator msSaveBlob functionality.\n Use listToCsvBlob and handle file creation on your side instead.\n ");
61
- }
62
-
63
- const blob = listToCsvBlob(list, map);
64
- const finalFileName = "".concat(fileName, ".csv");
65
-
66
- if (navigator.msSaveBlob) {
67
- // IE 10+
68
- navigator.msSaveBlob(blob, finalFileName);
69
- } else {
70
- const link = document.createElement('a');
71
-
72
- if (link.download !== undefined) {
73
- // feature detection
74
- // Browsers that support HTML5 download attribute
75
- const url = URL.createObjectURL(blob);
76
- link.setAttribute('href', url);
77
- link.setAttribute('download', finalFileName);
78
- link.style.visibility = 'hidden';
79
- document.body.appendChild(link);
80
- link.click();
81
- document.body.removeChild(link);
82
- }
83
- }
84
- }
85
-
86
- exports.list2csv = list2csv;
87
- exports.listToCsvBlob = listToCsvBlob;
88
- exports.listToCsvFile = listToCsvFile;
package/esm/index.js DELETED
@@ -1,82 +0,0 @@
1
- import 'core-js/modules/esnext.map.delete-all.js';
2
- import 'core-js/modules/esnext.map.emplace.js';
3
- import 'core-js/modules/esnext.map.every.js';
4
- import 'core-js/modules/esnext.map.filter.js';
5
- import 'core-js/modules/esnext.map.find.js';
6
- import 'core-js/modules/esnext.map.find-key.js';
7
- import 'core-js/modules/esnext.map.includes.js';
8
- import 'core-js/modules/esnext.map.key-of.js';
9
- import 'core-js/modules/esnext.map.map-keys.js';
10
- import 'core-js/modules/esnext.map.map-values.js';
11
- import 'core-js/modules/esnext.map.merge.js';
12
- import 'core-js/modules/esnext.map.reduce.js';
13
- import 'core-js/modules/esnext.map.some.js';
14
- import 'core-js/modules/esnext.map.update.js';
15
- import 'core-js/modules/web.dom-collections.iterator.js';
16
- import 'core-js/modules/esnext.async-iterator.map.js';
17
- import 'core-js/modules/esnext.iterator.map.js';
18
- import 'core-js/modules/es.string.replace.js';
19
- import 'core-js/modules/web.url.js';
20
- import 'core-js/modules/web.url-search-params.js';
21
-
22
- const argIsMap = arg => arg && arg instanceof Map === false; // https://github.com/BubbleBear/list2csv/blob/master/src/index.ts
23
-
24
-
25
- function list2csv(list, map) {
26
- let headerMap;
27
-
28
- if (argIsMap(map)) {
29
- headerMap = map;
30
- } else {
31
- headerMap = new Map(Object.entries(map));
32
- }
33
-
34
- const columns = headerMap && Array.from(headerMap.keys()) || Object.keys(list[0] || {});
35
- const header = columns.map(v => "\"".concat(headerMap ? headerMap.get(v) : v, "\"")).join(',');
36
- const content = list.map(item => columns.map(key => {
37
- let finalCell;
38
- const cell = item[key];
39
- finalCell = cell;
40
- if (typeof cell === 'string') finalCell = cell.replace(/"/g, '""');
41
- return "\"".concat(finalCell, "\"");
42
- }).join(',')).join('\r\n');
43
- return "".concat(header, "\r\n").concat(content);
44
- }
45
- function listToCsvBlob(list, map) {
46
- const data = list2csv(list, map);
47
- return new Blob([data], {
48
- type: 'text/csv;charset=utf-8;'
49
- });
50
- }
51
- function listToCsvFile(list) {
52
- let fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'list';
53
- let map = arguments.length > 2 ? arguments[2] : undefined;
54
-
55
- if (!document.createElement && !navigator.msSaveBlob) {
56
- throw new Error("\n Can not export to file without document/navigator msSaveBlob functionality.\n Use listToCsvBlob and handle file creation on your side instead.\n ");
57
- }
58
-
59
- const blob = listToCsvBlob(list, map);
60
- const finalFileName = "".concat(fileName, ".csv");
61
-
62
- if (navigator.msSaveBlob) {
63
- // IE 10+
64
- navigator.msSaveBlob(blob, finalFileName);
65
- } else {
66
- const link = document.createElement('a');
67
-
68
- if (link.download !== undefined) {
69
- // feature detection
70
- // Browsers that support HTML5 download attribute
71
- const url = URL.createObjectURL(blob);
72
- link.setAttribute('href', url);
73
- link.setAttribute('download', finalFileName);
74
- link.style.visibility = 'hidden';
75
- document.body.appendChild(link);
76
- link.click();
77
- document.body.removeChild(link);
78
- }
79
- }
80
- }
81
-
82
- export { list2csv, listToCsvBlob, listToCsvFile };
package/types/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function list2csv(list: Record<string, string>[], map: Record<string, string> | Map<string, string>): string;
2
- export declare function listToCsvBlob(list: Record<string, string>[], map: Record<string, string> | Map<string, string>): Blob;
3
- export declare function listToCsvFile(list: Record<string, string>[], fileName: string | undefined, map: Record<string, string> | Map<string, string>): void;