Last active
July 30, 2016 14:15
-
-
Save abiank/db22245c424191fcd6cb219752afef40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// getAudioPlayer()._currentPlaylist._ref._list | |
//// merge this: | |
str.replace(/[^\x00-\x7F]/g, ""); | |
//// | |
var truncate = require("truncate-utf8-bytes"); | |
var illegalRe = /[\/\?<>\\:\*\|":]/g; | |
var controlRe = /[\x00-\x1f\x80-\x9f]/g; | |
var reservedRe = /^\.+$/; | |
var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i; | |
var windowsTrailingRe = /[\. ]+$/; | |
function sanitize(input, replacement) { | |
var sanitized = input | |
.replace(illegalRe, replacement) | |
.replace(controlRe, replacement) | |
.replace(reservedRe, replacement) | |
.replace(windowsReservedRe, replacement) | |
.replace(windowsTrailingRe, replacement); | |
return truncate(sanitized, 255); | |
} | |
module.exports = function (input, options) { | |
var replacement = (options && options.replacement) || ''; | |
var output = sanitize(input, replacement); | |
if (replacement === '') { | |
return output; | |
} | |
return sanitize(output, ''); | |
}; | |
Contact GitHub API Training Shop Blog About |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment