Skip to content

Commit

Permalink
Merge pull request #332 from Fdawgs/chore/tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Oct 23, 2023
2 parents c8de140 + eb46c0c commit ef0a402
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"bierner.github-markdown-preview",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"esbenp.prettier-vscode",
Expand Down
2 changes: 1 addition & 1 deletion scripts/license-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function checkLicenses() {

/**
* List of deprecated copyleft license identifiers
* @see {@link https://spdx.org/licenses/ | SPDX License List}
* @see {@link https://spdx.org/licenses/#deprecated | SPDX Deprecated License Identifiers}
*/
const deprecatedLicenseList = [
"AGPL-1.0",
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const errorMessages = {
3221225477: "Segmentation fault",
};

const unrtfPathRegex = /(.+)unrtf/u;
const unrtfVersionRegex = /^(\d{1,2}\.\d{1,2}\.\d{1,2})/u;
const rtfMagicNumberRegex = /^\{\\rtf/u;

/**
* @author Frazer Smith
* @description Checks each option provided is valid, of the correct type, and can be used by specified
Expand Down Expand Up @@ -93,7 +97,7 @@ class UnRTF {
const which = spawnSync(platform === "win32" ? "where" : "which", [
"unrtf",
]).stdout.toString();
const unrtfPath = /(.+)unrtf/u.exec(which)?.[1];
const unrtfPath = unrtfPathRegex.exec(which)?.[1];

if (unrtfPath) {
this.unrtfPath = unrtfPath;
Expand Down Expand Up @@ -126,7 +130,7 @@ class UnRTF {
"--version",
]).stderr.toString();
/** @type {string|undefined} */
this.unrtfVersion = /^(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(version)?.[1];
this.unrtfVersion = unrtfVersionRegex.exec(version)?.[1];

/** @type {object} */
this.unrtfAcceptedOptions = {
Expand Down Expand Up @@ -209,7 +213,7 @@ class UnRTF {
throw new Error("File missing");
}
// Check for RTF specific magic number
if (!/^\{\\rtf/u.test(buff.toString())) {
if (!rtfMagicNumberRegex.test(buff.toString())) {
throw new Error(
"File is not the correct media type, expected 'application/rtf'"
);
Expand Down

0 comments on commit ef0a402

Please sign in to comment.