Skip to content

Commit

Permalink
Fix/empty key and wrong key (#10)
Browse files Browse the repository at this point in the history
* fix: empty key will not generate lines now

* fix: chinese white space fix
  • Loading branch information
jhonny-me authored Jul 23, 2020
1 parent 0df1e41 commit 96e8e67
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ const getOptions = async (argv) => {
};

const formatKey = (key) => {
const removespace = key.replace(/[_ ]/g, "&&&");
const words = removespace.split("&&&").map((s) => s.toLowerCase());
return words.join("_");
const removespace = key.trim().toLowerCase().replace(/[!@#$%^&*() , .?'":{}|<>]+/g, "_");
return removespace;
};

const readFromCsv = (filepath) => {
Expand All @@ -97,10 +96,12 @@ const readFromCsv = (filepath) => {
.pipe(csv())
.on("data", (data) => {
var { key } = data;
results.push({
...data,
key: formatKey(key),
});
if (key && key.length > 0) {
results.push({
...data,
key: formatKey(key),
});
}
})
.on("end", () => {
results.sort((lhs, rhs) => lhs.key > rhs.key);
Expand Down

0 comments on commit 96e8e67

Please sign in to comment.