You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

filename-reserved-regex

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

filename-reserved-regex

Regular expression for matching reserved filename characters


Version published
Maintainers
1
Created

Package description

What is filename-reserved-regex?

The filename-reserved-regex npm package provides a regular expression that matches characters that are reserved in filenames across different operating systems. This can be particularly useful for validating filenames or sanitizing them to ensure they are compatible across Windows, macOS, and Unix/Linux systems.

What are filename-reserved-regex's main functionalities?

Validation of filenames

This code sample demonstrates how to use the package to check if a string (which is intended to be used as a filename) contains any reserved characters. The `match` method will return an array of matches if any reserved characters are found, or `null` if the filename is safe to use.

"some*filename?.txt".match(filenameReservedRegex())

Sanitization of filenames

This code sample shows how to sanitize a filename by removing any reserved characters. This is done by replacing any characters that match the regex provided by the package with an empty string, effectively removing them.

"some*filename?.txt".replace(filenameReservedRegex(), '')

Other packages similar to filename-reserved-regex

Readme

Source

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.

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 invalid Windows filenames. These include CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8 and LPT9.

Keywords

FAQs

Package last updated on 16 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc