Regular expression for matching reserved filename characters
by sindresorhusJavaScript
Last 12 weeks · 0 commits
4 of 6 standards met
According to Microsoft's Naming Conventions: Do not use the following reserved names for the name of a file: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, COM¹, COM², COM³, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9, LPT¹, LPT², and LPT³. Also avoid these names followed immediately by an extension; for example, NUL.txt and NUL.tar.gz are both equivalent to NUL. For more information, see Namespaces. Note Windows recognizes the 8-bit ISO/IEC 8859-1 superscript digits ¹, ², and ³ as digits and treats them as valid parts of COM# and LPT# device names, making them reserved in every directory. For example, echo test > COM¹ fails to create a file. The regex neither checks for superscript digits nor for reserved names immediately followed by an extension: https://github.com/sindresorhus/filename-reserved-regex/blob/1403e86e937f0955fbb0ffad4ce56fbae47e3cc0/index.js#L8 It should probably be something like this (excluding 0 as it should be valid):
From https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions: Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. They should be added the the Windows Regexp.
Hi, I'm getting the following error when importing this package: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /redacted/path/node_modules/filename-reserved-regex/index.js require() of ES modules is not supported. require() of /redacted/path/node_modules/filename-reserved-regex/index.js from /redacted/path/build/server.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /redacted/path/node_modules/filename-reserved-regex/package.json. at new NodeError (node:internal/errors:363:5) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:13) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:816:12) at Module.require (node:internal/modules/cjs/loader:999:19) at require (node:internal/modules/cjs/helpers:93:18) at Object. (/redacted/path/build/server.js:22:46) at Module._compile (node:internal/modules/cjs/loader:1095:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10) at Module.load (node:internal/modules/cjs/loader:975:32) ERROR: "dev:server" exited with 1. It is possible to implement one of the suggestions in the error? Thanks
Repository: sindresorhus/filename-reserved-regex. Description: Regular expression for matching reserved filename characters Stars: 52, Forks: 5. Primary language: JavaScript. Languages: JavaScript (100%). License: MIT. Latest release: v4.0.0 (11mo ago). Open PRs: 1, open issues: 1. Last activity: 11mo ago. Community health: 85%. Top contributors: sindresorhus, silverwind, sonicdoe, Richienb.