Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 12, 2023
1 parent e1a7949 commit 82de5af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"extends": "@logux/eslint-config",
"rules": {
"n/global-require": "off",
"no-control-regex": "off",
"no-console": "off"
},
"overrides": [
Expand Down
35 changes: 9 additions & 26 deletions packages/esbuild-why/valid-filename.js
@@ -1,28 +1,11 @@
// from https://github.com/sindresorhus/valid-filename/blob/main/index.js
function isValidFilename(string) {
if (!string || string.length > 255) {
return false;
module.exports = {
isValidFilename(string) {
if (!string || string.length > 255 || string === '.' || string === '..') {
return false
}
return (
!/[<>:"/\\|?*\u0000-\u001F]/g.test(string) &&
!/^(con|prn|aux|nul|com\d|lpt\d)$/i.test(string)
)
}

if (filenameReservedRegex().test(string) || windowsReservedNameRegex().test(string)) {
return false;
}

if (string === '.' || string === '..') {
return false;
}

return true;
}

// from https://github.com/sindresorhus/filename-reserved-regex/blob/main/index.js
function filenameReservedRegex() {
// eslint-disable-next-line no-control-regex
return /[<>:"/\\|?*\u0000-\u001F]/g;
}

function windowsReservedNameRegex() {
return /^(con|prn|aux|nul|com\d|lpt\d)$/i;
}

module.exports = { isValidFilename }

0 comments on commit 82de5af

Please sign in to comment.