1 | // eslint-disable-next-line no-control-regex
|
2 | const InvalidFileFolderNameCharsOnlineRegex = /["*:<>?/\\|\x00-\x1f\x7f-\x9f]/g;
|
3 | // eslint-disable-next-line no-control-regex
|
4 | const InvalidFileFolderNameCharsOnPremiseRegex = /["#%*:<>?/\\|\x00-\x1f\x7f-\x9f]/g;
|
5 | /**
|
6 | * Checks if file or folder name contains invalid characters
|
7 | *
|
8 | * @param input File or folder name to check
|
9 | * @param onPremise Set to true for SharePoint On-Premise
|
10 | * @returns True if contains invalid chars, false otherwise
|
11 | */
|
12 | export function containsInvalidFileFolderChars(input, onPremise = false) {
|
13 | if (onPremise) {
|
14 | return InvalidFileFolderNameCharsOnPremiseRegex.test(input);
|
15 | }
|
16 | else {
|
17 | return InvalidFileFolderNameCharsOnlineRegex.test(input);
|
18 | }
|
19 | }
|
20 | /**
|
21 | * Removes invalid characters from file or folder name
|
22 | *
|
23 | * @param input File or folder name
|
24 | * @param replacer Value that will replace invalid characters
|
25 | * @param onPremise Set to true for SharePoint On-Premise
|
26 | * @returns File or folder name with replaced invalid characters
|
27 | */
|
28 | export function stripInvalidFileFolderChars(input, replacer = "", onPremise = false) {
|
29 | if (onPremise) {
|
30 | return input.replace(InvalidFileFolderNameCharsOnPremiseRegex, replacer);
|
31 | }
|
32 | else {
|
33 | return input.replace(InvalidFileFolderNameCharsOnlineRegex, replacer);
|
34 | }
|
35 | }
|
36 | //# sourceMappingURL=file-names.js.map |
\ | No newline at end of file |