@tryghost/mg-fs-utils 0.12.2 → 0.12.3

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.
Files changed (2) hide show
  1. package/lib/csv.js +18 -1
  2. package/package.json +4 -4
package/lib/csv.js CHANGED
@@ -97,9 +97,26 @@ 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 {string} filePath Path to CSV file
103
+ * @param {array} theKeys Array of keys the CSV must include
104
+ * @returns {boolean}
105
+ */
106
+ const hasKeys = async (filePath, theKeys = []) => {
107
+ let parsed = await parseCSV(filePath);
108
+ let firstRow = parsed[0];
109
+ let colKeys = Object.keys(firstRow);
110
+
111
+ let hasRequiredKeys = theKeys.every(v => colKeys.includes(v));
112
+
113
+ return hasRequiredKeys;
114
+ };
115
+
100
116
  export default {
101
117
  parseCSV,
102
118
  parseString,
103
119
  jsonToCSV,
104
- writeCSV
120
+ writeCSV,
121
+ hasKeys
105
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-fs-utils",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
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.4.3",
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.5",
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": "5425b18d5b6ffb6f0f7dc9d13a5c0341c6937945"
40
+ "gitHead": "3dcab8e838ec029cdf46a8df53e1067f3b2fb0b7"
41
41
  }