@tryghost/mg-fs-utils 0.12.2 → 0.12.4
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/lib/csv.js +21 -1
- package/package.json +4 -4
package/lib/csv.js
CHANGED
|
@@ -97,9 +97,29 @@ const writeCSV = async (data, filePath, fileName) => {
|
|
|
97
97
|
return outputPath;
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Check if a CSV has the required keys
|
|
102
|
+
* @param {object} data
|
|
103
|
+
* @param {string} data.filePath Path to CSV file
|
|
104
|
+
* @param {array} data.required Array of keys the CSV must include
|
|
105
|
+
* @param {array} data.blocked Array of keys the CSV must include
|
|
106
|
+
* @returns {boolean}
|
|
107
|
+
*/
|
|
108
|
+
const hasKeys = async ({filePath, required = [], blocked = []}) => {
|
|
109
|
+
const parsed = await parseCSV(filePath);
|
|
110
|
+
const firstRow = parsed[0];
|
|
111
|
+
const colKeys = Object.keys(firstRow);
|
|
112
|
+
|
|
113
|
+
const hasRequiredKeys = required.every(v => colKeys.includes(v));
|
|
114
|
+
const hasBlockedKeys = colKeys.some(r => blocked.includes(r));
|
|
115
|
+
|
|
116
|
+
return hasRequiredKeys && !hasBlockedKeys;
|
|
117
|
+
};
|
|
118
|
+
|
|
100
119
|
export default {
|
|
101
120
|
parseCSV,
|
|
102
121
|
parseString,
|
|
103
122
|
jsonToCSV,
|
|
104
|
-
writeCSV
|
|
123
|
+
writeCSV,
|
|
124
|
+
hasKeys
|
|
105
125
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-fs-utils",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-fs-utils",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"eslint": "8.35.0",
|
|
24
|
-
"jest": "29.
|
|
24
|
+
"jest": "29.5.0",
|
|
25
25
|
"jest-extended": "3.2.4"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@tryghost/image-transform": "1.2.3",
|
|
30
30
|
"@tryghost/zip": "1.1.32",
|
|
31
31
|
"adm-zip": "0.5.10",
|
|
32
|
-
"csv-parse": "5.3.
|
|
32
|
+
"csv-parse": "5.3.6",
|
|
33
33
|
"date-fns": "2.29.3",
|
|
34
34
|
"fs-extra": "11.1.0",
|
|
35
35
|
"lodash": "4.17.21",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"sharp": "0.31.3",
|
|
38
38
|
"transliteration": "2.3.5"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "9a613a18b22c794c0e3eed734c4b6963e905f68d"
|
|
41
41
|
}
|