@nkhang1902/strapi-plugin-export-import-clsx 1.9.4 → 1.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkhang1902/strapi-plugin-export-import-clsx",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
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 = {}) {
@@ -349,6 +356,7 @@ module.exports = ({ strapi }) => ({
349
356
  hasData = true;
350
357
 
351
358
  const attr = strapi.contentTypes[contentType].attributes;
359
+ console.log(attr)
352
360
  const customFields = Object.entries(attr)
353
361
  .filter(([key, definition]) => definition.customField)
354
362
  .map(([key]) => key);
@@ -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,8 +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)) {
63
- console.log(key, value)
84
+ for (let [k, value] of Object.entries(row)) {
85
+ key = headerToKey(k);
64
86
  if (value === null || value === undefined || value === '') {
65
87
  rowData[key] = null
66
88
  } else if (attr[key] && attr[key].customField && attr[key].type === 'json' && attr[key].default === '[]') {