spws
Version:
SharePoint Web Services Wrapper
28 lines (25 loc) • 809 B
text/typescript
/**
* @name escapeHtml
* @description Escaping HTML is required when sending data to a SharePoint via a web request.
* @param {String} string The string to be escaped.
* @return {String} Returns a string with escaped HTML
* @example
* import escapeHtml from "objectpoint-ui/lib/utils/escapeHtml";
*
* // Escape the & (ampersand) in the string
* escapeHtml("Operations & Development")
*
* // Returns
* "Operations & Development"
*/
const escapeXml = (xml: string | number): string => {
// If not a string, cast to string
if (typeof xml === "number") xml = xml.toString();
return xml
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
};
export default escapeXml;