1.3.0 • Published 2 months ago

als-filename-validator v1.3.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

als-filename-validator

als-filename-validator is a Node.js module for validating file and directory names across different operating systems including Windows, Linux, and MacOS.

Change log for v1.3

  • string validation for filename parameter (return false)
  • validation for empty string (return false)

Installation

Use npm to install the package:

npm install als-filename-validator

Usage

The module exports a function that checks if a given file name is valid for a specified operating system.

const isValidFileName = require('als-filename-validator');

const fileName = "test.txt";
const os = "windows"; // can be 'windows', 'linux', 'mac', 'darwin', 'win32', or 'all'

if (isValidFileName(fileName, os)) {
  console.log("The file name is valid.");
} else {
  console.log("The file name is not valid.");
}

The second argument os is optional. If not provided, the function will perform validation checks for all operating systems ('all').

You can also explicitly check for all operating systems by passing 'all' as the second argument.

Browser Compatibility

In addition to Node.js environments, the als-filename-validator function is designed to be compatible with browser environments. This makes it suitable for a wide range of JavaScript applications, including those running on the client-side in web browsers.

To use it in a browser, simply include the script in your HTML and access the isValidFileName function globally.

Example of including the script in HTML:

<script src="node_modules/als-filename-validator/index.js"></script>

Examples

The following table provides some examples of file names and the function's output:

File NameOSIs Valid?
test.txtallYes
.testallNo
test:.txtwindowsNo
my*file.txtlinuxNo
prn.txtwindowsNo
valid_file_namemacYes
space_in_end.txtallNo
CONwindowsNo
normal_file_name.jpegallYes
:invalid:file:name.txtmacNo