Skip to content

Commit

Permalink
feat: escapeStringRegexp
Browse files Browse the repository at this point in the history
  • Loading branch information
snomiao committed Apr 20, 2022
1 parent 74619f6 commit a1263b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/md-aggregate/cli.mjs
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import arg from "arg";
import escapeStringRegexp from "escape-string-regexp";
import { readFile, writeFile } from "fs/promises";
import { parse, resolve } from "path";

Expand Down Expand Up @@ -47,9 +48,8 @@ export const cli = async (rawArgv) => {
.split("\n")
.map((e) => e.replace(/^#/g, "##"));

// TODO: escape regexp startPattern
// TODO: handle \r\n
const matchStartPattern = `\n${lines[0]}$`;
const matchStartPattern = `\n${escapeStringRegexp(lines[0])}$`;
const eofPattern = "$(?![\\r\\n])";

const sectionStartPattern = `\n##? `;
Expand All @@ -67,7 +67,7 @@ export const cli = async (rawArgv) => {
if (!args["--write"]) return console.log(dstContent);

await writeFile(resolve(dst), dstContent);

console.log(resolve(dst));
};

Expand Down
3 changes: 2 additions & 1 deletion packages/md-aggregate/package.json
Expand Up @@ -9,7 +9,8 @@
"prepack": "prettier -w CHANGELOG.md && md-aggregate CHANGELOG.md README.md -w"
},
"dependencies": {
"arg": "^5.0.1"
"arg": "^5.0.1",
"escape-string-regexp": "^5.0.0"
},
"publishConfig": {
"access": "public"
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1263b3

Please sign in to comment.