guarded`string`
Prevent accidentally introducing XSS holes with the strings in your app
Hold your friends close, and your strings closer
Installation
yarn add guarded-string
Usage
Important! This should be used for things like preventing XSS attacks, not for hiding sensitive information.
; const myString = guardedString`My very important (but not too important) string`; guardedString; // >> booleanguardedString; // >> maybe throwsguardedString; // >> unguarded string (throws on other value types) myString + 'hi'; // Error!JSON; // Error!// etc.
Examples
guardedString`foo`; // Works!guardedString`foo`; // Error!; // Error!
let str = guardedString`foo`; str; // Error!'' + str; // Error!Stringstr; // Error!``; // Error!1 * str; // Error!JSON; // Error!
See test cases for more