josenanodev-react-components-library 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,48 +27,49 @@ exports.downloadExcel = void 0;
27
27
  //Librerias de terceros
28
28
  const XLSX = __importStar(require("xlsx-js-style"));
29
29
  function styleObjectParser(styleObject) {
30
- let objetoResultante = {
30
+ let restultantStyleObject = {
31
31
  v: styleObject.value,
32
32
  s: {},
33
33
  };
34
34
  if (styleObject.allign)
35
- objetoResultante.s.alignment = Object.assign({}, styleObject.allign);
35
+ restultantStyleObject.s.alignment = Object.assign({}, styleObject.allign);
36
36
  if (styleObject.fontSize)
37
- objetoResultante.s.font = Object.assign(Object.assign({}, objetoResultante.s.font), { sz: styleObject.fontSize });
37
+ restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { sz: styleObject.fontSize });
38
38
  if (styleObject.fontColor)
39
- objetoResultante.s.font = Object.assign(Object.assign({}, objetoResultante.s.font), { color: { rgb: styleObject.fontColor } });
39
+ restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { color: { rgb: styleObject.fontColor } });
40
40
  if (styleObject.bold)
41
- objetoResultante.s.font = Object.assign(Object.assign({}, objetoResultante.s.font), { bold: styleObject.bold });
41
+ restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { bold: styleObject.bold });
42
42
  if (styleObject.backgroundColor)
43
- objetoResultante.s.fill = Object.assign(Object.assign({}, objetoResultante.s.fill), { fgColor: { rgb: styleObject.backgroundColor } });
43
+ restultantStyleObject.s.fill = Object.assign(Object.assign({}, restultantStyleObject.s.fill), { fgColor: { rgb: styleObject.backgroundColor } });
44
44
  if (styleObject.borders)
45
- objetoResultante.s.border = {
45
+ restultantStyleObject.s.border = {
46
46
  bgColor: styleObject.borders,
47
47
  };
48
- return objetoResultante;
48
+ return restultantStyleObject;
49
49
  }
50
50
  function downloadExcel(fileName, data, headers) {
51
51
  if (data !== undefined) {
52
- const wb = XLSX.utils.book_new();
53
- for (const hoja in data) {
54
- if (Object.prototype.hasOwnProperty.call(data, hoja)) {
52
+ const workbook = XLSX.utils.book_new();
53
+ for (const sheetName in data) {
54
+ if (Object.prototype.hasOwnProperty.call(data, sheetName)) {
55
55
  let dataXlsxJs = [];
56
- if (headers !== undefined) {
56
+ if (headers !== undefined &&
57
+ Object.prototype.hasOwnProperty.call(headers, sheetName)) {
57
58
  dataXlsxJs = [
58
- headers[hoja].map((encabezado) => styleObjectParser(encabezado)),
59
- ...data[hoja].map((fila) => fila.map((celda) => styleObjectParser(celda))),
59
+ headers[sheetName].map((header) => styleObjectParser(header)),
60
+ ...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
60
61
  ];
61
62
  }
62
63
  else {
63
64
  dataXlsxJs = [
64
- ...data[hoja].map((fila) => fila.map((celda) => styleObjectParser(celda))),
65
+ ...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
65
66
  ];
66
67
  }
67
- const ws = XLSX.utils.aoa_to_sheet(dataXlsxJs);
68
- XLSX.utils.book_append_sheet(wb, ws, "hoja");
68
+ const worksheet = XLSX.utils.aoa_to_sheet(dataXlsxJs);
69
+ XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
69
70
  }
70
71
  }
71
- XLSX.writeFile(wb, `${fileName}.xlsx`);
72
+ XLSX.writeFile(workbook, `${fileName}.xlsx`);
72
73
  }
73
74
  }
74
75
  exports.downloadExcel = downloadExcel;
@@ -1,47 +1,48 @@
1
1
  //Librerias de terceros
2
2
  import * as XLSX from "xlsx-js-style";
3
3
  function styleObjectParser(styleObject) {
4
- let objetoResultante = {
4
+ let restultantStyleObject = {
5
5
  v: styleObject.value,
6
6
  s: {},
7
7
  };
8
8
  if (styleObject.allign)
9
- objetoResultante.s.alignment = Object.assign({}, styleObject.allign);
9
+ restultantStyleObject.s.alignment = Object.assign({}, styleObject.allign);
10
10
  if (styleObject.fontSize)
11
- objetoResultante.s.font = Object.assign(Object.assign({}, objetoResultante.s.font), { sz: styleObject.fontSize });
11
+ restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { sz: styleObject.fontSize });
12
12
  if (styleObject.fontColor)
13
- objetoResultante.s.font = Object.assign(Object.assign({}, objetoResultante.s.font), { color: { rgb: styleObject.fontColor } });
13
+ restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { color: { rgb: styleObject.fontColor } });
14
14
  if (styleObject.bold)
15
- objetoResultante.s.font = Object.assign(Object.assign({}, objetoResultante.s.font), { bold: styleObject.bold });
15
+ restultantStyleObject.s.font = Object.assign(Object.assign({}, restultantStyleObject.s.font), { bold: styleObject.bold });
16
16
  if (styleObject.backgroundColor)
17
- objetoResultante.s.fill = Object.assign(Object.assign({}, objetoResultante.s.fill), { fgColor: { rgb: styleObject.backgroundColor } });
17
+ restultantStyleObject.s.fill = Object.assign(Object.assign({}, restultantStyleObject.s.fill), { fgColor: { rgb: styleObject.backgroundColor } });
18
18
  if (styleObject.borders)
19
- objetoResultante.s.border = {
19
+ restultantStyleObject.s.border = {
20
20
  bgColor: styleObject.borders,
21
21
  };
22
- return objetoResultante;
22
+ return restultantStyleObject;
23
23
  }
24
24
  export function downloadExcel(fileName, data, headers) {
25
25
  if (data !== undefined) {
26
- const wb = XLSX.utils.book_new();
27
- for (const hoja in data) {
28
- if (Object.prototype.hasOwnProperty.call(data, hoja)) {
26
+ const workbook = XLSX.utils.book_new();
27
+ for (const sheetName in data) {
28
+ if (Object.prototype.hasOwnProperty.call(data, sheetName)) {
29
29
  let dataXlsxJs = [];
30
- if (headers !== undefined) {
30
+ if (headers !== undefined &&
31
+ Object.prototype.hasOwnProperty.call(headers, sheetName)) {
31
32
  dataXlsxJs = [
32
- headers[hoja].map((encabezado) => styleObjectParser(encabezado)),
33
- ...data[hoja].map((fila) => fila.map((celda) => styleObjectParser(celda))),
33
+ headers[sheetName].map((header) => styleObjectParser(header)),
34
+ ...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
34
35
  ];
35
36
  }
36
37
  else {
37
38
  dataXlsxJs = [
38
- ...data[hoja].map((fila) => fila.map((celda) => styleObjectParser(celda))),
39
+ ...data[sheetName].map((row) => row.map((cell) => styleObjectParser(cell))),
39
40
  ];
40
41
  }
41
- const ws = XLSX.utils.aoa_to_sheet(dataXlsxJs);
42
- XLSX.utils.book_append_sheet(wb, ws, "hoja");
42
+ const worksheet = XLSX.utils.aoa_to_sheet(dataXlsxJs);
43
+ XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
43
44
  }
44
45
  }
45
- XLSX.writeFile(wb, `${fileName}.xlsx`);
46
+ XLSX.writeFile(workbook, `${fileName}.xlsx`);
46
47
  }
47
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "josenanodev-react-components-library",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "author": {
5
5
  "name": "Jose Carlos Cardenas Martinez"
6
6
  },