filename-reserved-regex
Regular expression for matching reserved filename characters
Last updated 2 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install filename-reserved-regex 
SYNC missed versions from official npm registry.

filename-reserved-regex

Regular expression for matching reserved filename characters

On Unix-like systems / is reserved and <>:"/\|?* as well as non-printable characters \u0000-\u001F on Windows. Windows also doesn't allow names ending in space or period.

Install

npm install filename-reserved-regex

Usage

import filenameReservedRegex, {windowsReservedNameRegex} from 'filename-reserved-regex';

filenameReservedRegex().test('foo/bar');
//=> true

filenameReservedRegex().test('foo-bar');
//=> false

'foo/bar'.replace(filenameReservedRegex(), '!');
//=> 'foo!bar'

windowsReservedNameRegex().test('aux');
//=> true

API

filenameReservedRegex()

Returns a regex that matches all invalid characters.

windowsReservedNameRegex()

Returns an exact-match case-insensitive regex that matches reserved Windows device names.

These include CON, PRN, AUX, NUL, CONIN$, CONOUT$, COM1 through COM9, COM¹, COM², COM³, LPT1 through LPT9, LPT¹, LPT², and LPT³. COM0 and LPT0 are conservatively matched for compatibility with previous versions.

Names followed by an extension are also matched because, for example, NUL.txt and NUL.tar.gz are both equivalent to NUL. ASCII spaces before the extension or at the end of the name are ignored in the same way as on Windows.

Current Tags

  • 4.1.0                                ...           latest (2 months ago)

6 Versions

  • 4.1.0                                ...           2 months ago
  • 4.0.1                                ...           3 months ago
  • 4.0.0                                ...           a year ago
  • 3.0.0                                ...           5 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 17
Today 0
This Week 9
This Month 9
Last Day 3
Last Week 0
Last Month 6
Dependencies (0)
None
Dev Dependencies (1)
  • xo ^5.0.1
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE