How to use filename-reserved-regex - 3 common examples

To help you get started, we’ve selected a few filename-reserved-regex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / valid-filename / index.js View on Github external
const validFilename = string => {
	if (!string || string.length > 255) {
		return false;
	}

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

	if (/^\.\.?$/.test(string)) {
		return false;
	}

	return true;
};
github sindresorhus / filenamify / index.js View on Github external
const replacement = options.replacement === undefined ? '!' : options.replacement;

	if (filenameReservedRegex().test(replacement) && reControlChars.test(replacement)) {
		throw new Error('Replacement string cannot contain reserved filename characters');
	}

	string = string.replace(filenameReservedRegex(), replacement);
	string = string.replace(reControlChars, replacement);
	string = string.replace(reRelativePath, replacement);

	if (replacement.length > 0) {
		string = trimRepeated(string, replacement);
		string = string.length > 1 ? stripOuter(string, replacement) : string;
	}

	string = filenameReservedRegex.windowsNames().test(string) ? string + replacement : string;
	string = string.slice(0, typeof options.maxLength === 'number' ? options.maxLength : MAX_FILENAME_LENGTH);

	return string;
};
github vuerd / vuerd-electron / src / renderer / js / editor / util.js View on Github external
export const validFileName = name => {
  return name.replace(fileNameRex(), '').replace(fileNameRex.windowsNames(), '')
}

filename-reserved-regex

Regular expression for matching reserved filename characters

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular filename-reserved-regex functions