@nkhang1902/strapi-plugin-export-import-clsx 1.9.3 → 1.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkhang1902/strapi-plugin-export-import-clsx",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "description": "A powerful Strapi plugin for exporting and importing data with Excel support and advanced filtering",
5
5
  "main": "./strapi-server.js",
6
6
  "scripts": {
@@ -2,8 +2,15 @@ const ExcelJS = require('exceljs');
2
2
 
3
3
  function camelToTitle(str) {
4
4
  return str
5
- .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
6
- .replace(/^./, s => s.toUpperCase());
5
+ // split snake_case but keep underscores as tokens
6
+ .split('_')
7
+ .map(part =>
8
+ part
9
+ // split camelCase inside each segment
10
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
11
+ .replace(/^./, c => c.toUpperCase())
12
+ )
13
+ .join(' _ ');
7
14
  }
8
15
 
9
16
  function styleWorksheetUniform(worksheet, data, uncamelized = false, options = {}) {
@@ -469,7 +476,7 @@ module.exports = ({ strapi }) => ({
469
476
  flattenForXLSX(entry)
470
477
  );
471
478
  const worksheet = workbook.addWorksheet(sheetName);
472
- styleWorksheetUniform(worksheet, cleanedFlat, false, {
479
+ styleWorksheetUniform(worksheet, cleanedFlat, true, {
473
480
  colWidth: 30,
474
481
  });
475
482
  } else {
@@ -502,7 +509,7 @@ module.exports = ({ strapi }) => ({
502
509
  ...tag(experienceData?.investors, 'investor'),
503
510
  ...tag(experienceData?.vipGuests, 'vipGuest'),
504
511
  ];
505
- console.log(JSON.stringify(participants, null, 2));
512
+
506
513
  const data = participants.map((p) => ({
507
514
  type: p.type,
508
515
  fullName:
@@ -1,6 +1,28 @@
1
1
  const XLSX = require("xlsx");
2
2
  const fs = require("fs");
3
3
 
4
+ function headerToKey(header) {
5
+ return header
6
+ // split by " _ " to restore snake segments
7
+ .split(' _ ')
8
+ .map((segment, index) => {
9
+ const words = segment.trim().split(/\s+/);
10
+
11
+ return words
12
+ .map((word, i) => {
13
+ const lower = word.toLowerCase();
14
+
15
+ // first word of each segment → lowercase
16
+ if (i === 0) return lower;
17
+
18
+ // following words → Capitalized (camelCase)
19
+ return lower.charAt(0).toUpperCase() + lower.slice(1);
20
+ })
21
+ .join('');
22
+ })
23
+ .join('_');
24
+ }
25
+
4
26
  function toCamel(str) {
5
27
  return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
6
28
  }
@@ -59,7 +81,8 @@ module.exports = ({ strapi }) => ({
59
81
  for (const row of rows) {
60
82
  const rowData = {};
61
83
 
62
- for (const [key, value] of Object.entries(row)) {
84
+ for (let [k, value] of Object.entries(row)) {
85
+ key = headerToKey(k);
63
86
  if (value === null || value === undefined || value === '') {
64
87
  rowData[key] = null
65
88
  } else if (attr[key] && attr[key].customField && attr[key].type === 'json' && attr[key].default === '[]') {