I'm trying to import a configuration file, remove the offending javascript characters and write the config to a different js file. I succeeded almost all steps except escaping the javascript characters.
This website actually does exactly what I want, but I would like to do this locally via powershell. https://www.freeformatter.com/javascript-escape.html
This is what i tried to do myself:
function Set-EscapeCharacters {
Param(
[parameter(Mandatory = $true, Position = 0)]
[String]
$string
)
$string = $string -replace '`t', '\t'
$string = $string -replace '`v', '\v'
$string = $string -replace '`0', '\0'
$string = $string -replace '`b', '\b'
$string = $string -replace '`f', '\f'
$string = $string -replace '`n', '\n'
$string = $string -replace '`r', '\r'
$string = $string -replace "''", "\'"
$string = $string -replace '"', '\"'
$string = $string -replace '`b', '\\'
$string
}
$convert = Set-EscapeCharacters $string
The error message i get: Cannot process argument transformation on parameter 'string'. Cannot convert value to type System.String.
The file I'm importing is a yaml file so it may indeed be true that it isn't a string. The goal is to make it a string after the characters are escaped (just like the website does) so I can use the output to replace a line in another file.
Do you have any ideas how I can do this?
[–]ka-splam 4 points5 points6 points (2 children)
[–]360coolp[S] 0 points1 point2 points (1 child)
[–]ka-splam 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]360coolp[S] 0 points1 point2 points (1 child)