diff --git a/code/typescript/normalAndCensorStrings.ts b/code/typescript/normalAndCensorStrings.ts new file mode 100644 index 0000000..9b39f46 --- /dev/null +++ b/code/typescript/normalAndCensorStrings.ts @@ -0,0 +1,30 @@ +function placeholder(index: number) { + return `_____${index}_____` +} + +function normalAndCensor(strings: string[], ...values: string[]): [string,string] { + + const normal = strings.reduce((result, s, i) => `${result}${s}${values[i] || ""}`, ""); + const censored = strings.reduce((result, s, i) => `${result}${s}${values[i] ? placeholder(i) : ""}`, ""); + return [normal, censored] +} + +function uncensor(s: string, values: string[]) { + return values.reduce((previous, current, index) => { + return previous.replace(placeholder(index), values[index]); + }, s) +} + +const rootFolder = "Secret Content A"; +const fileName = "Secret Content B"; + +const [normal, censor] = normalAndCensor`/me/drive/${rootFolder}/${fileName}:/content?@microsoft.graph.conflictBehavior=rename`; +const display = uncensor(censor, ["rootFolder", "fileName"]); + +console.log(normal); +console.log(censor); +console.log(display); + +// [LOG]: "/me/drive/Secret Content A/Secret Content B:/content?@microsoft.graph.conflictBehavior=rename" +// [LOG]: "/me/drive/_____0_____/_____1_____:/content?@microsoft.graph.conflictBehavior=rename" +// [LOG]: "/me/drive/rootFolder/fileName:/content?@microsoft.graph.conflictBehavior=rename" \ No newline at end of file