2018-12-15 08:05:52 +01:00
|
|
|
/**
|
2019-02-10 02:27:03 +01:00
|
|
|
* generate file system safe string for a given string
|
2018-12-15 08:05:52 +01:00
|
|
|
* that can be used as a valid file name
|
|
|
|
* in all operating systems
|
|
|
|
* @param {String} string
|
|
|
|
* @param {String} replacer (optional) character to replace invalid characters
|
|
|
|
*/
|
2019-02-10 02:27:03 +01:00
|
|
|
function generateFileSystemSafeName(string, replacer) {
|
2018-12-15 08:05:52 +01:00
|
|
|
// from here https://serverfault.com/a/242134
|
2019-02-20 20:57:26 +01:00
|
|
|
const INVALID_CHARS_REGEX = /[*/?:\\<>|"\u0000-\u001F]/g; // eslint-disable-line
|
2018-12-15 08:05:52 +01:00
|
|
|
const slug = string.replace(INVALID_CHARS_REGEX, replacer || '');
|
|
|
|
|
|
|
|
return slug;
|
|
|
|
}
|
|
|
|
|
2019-02-10 02:27:03 +01:00
|
|
|
export default generateFileSystemSafeName;
|