Skip to content

Commit

Permalink
fix: replace all reserved characters in filename with -
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Jun 6, 2023
1 parent 26f52dd commit 582beb3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { Highlight } from "./api";
export const DATE_FORMAT_W_OUT_SECONDS = "yyyy-MM-dd'T'HH:mm";
export const DATE_FORMAT = `${DATE_FORMAT_W_OUT_SECONDS}:ss`;
export const REPLACEMENT_CHAR = "-";
export const ILLEGAL_CHAR_REGEX = /[/\\?%*:|"<>]/g;
// On Unix-like systems / is reserved and <>:"/\|?* as well as non-printable characters \u0000-\u001F on Windows
// credit: https://github.com/sindresorhus/filename-reserved-regex
// eslint-disable-next-line no-control-regex
export const ILLEGAL_CHAR_REGEX = /[<>:"/\\|?*\u0000-\u001F]/g;

export interface HighlightPoint {
left: number;
Expand Down Expand Up @@ -88,7 +91,7 @@ export const unicodeSlug = (str: string, savedAt: string) => {
};

export const replaceIllegalChars = (str: string): string => {
return str.replace(ILLEGAL_CHAR_REGEX, REPLACEMENT_CHAR);
return str.replaceAll(ILLEGAL_CHAR_REGEX, REPLACEMENT_CHAR);
};

export function formatDate(date: string, format: string): string {
Expand Down

0 comments on commit 582beb3

Please sign in to comment.