UNPKG

@deephaven/golden-layout

Version:

A multi-screen javascript Layout manager

66 lines (64 loc) 1.83 kB
import $ from 'jquery'; import { nanoid } from 'nanoid'; export function getHashValue(key) { var matches = location.hash.match(new RegExp(key + '=([^&]*)')); return matches ? matches[1] : null; } export function getQueryStringParam(param) { if (window.location.hash) { return getHashValue(param); } else if (!window.location.search) { return null; } var keyValuePairs = window.location.search.substr(1).split('&'), params = {}, pair, i; for (i = 0; i < keyValuePairs.length; i++) { pair = keyValuePairs[i].split('='); params[pair[0]] = pair[1]; } return params[param] || null; } export function animFrame(fn) { return window.requestAnimationFrame(fn); } export function removeFromArray(item, array) { var index = array.indexOf(item); if (index === -1) { throw new Error("Can't remove item from array. Item is not in the array"); } array.splice(index, 1); } export function getUniqueId() { return nanoid(); } /** * A basic XSS filter. It is ultimately up to the * implementing developer to make sure their particular * applications and usecases are save from cross site scripting attacks * * @param input * @param keepTags * * @returns filtered input */ export function filterXss(input, keepTags) { var output = input.replace(/javascript/gi, 'j&#97;vascript').replace(/expression/gi, 'expr&#101;ssion').replace(/onload/gi, 'onlo&#97;d').replace(/script/gi, '&#115;cript').replace(/onerror/gi, 'on&#101;rror'); if (keepTags === true) { return output; } else { return output.replace(/>/g, '&gt;').replace(/</g, '&lt;'); } } /** * Removes html tags from a string * * @param input * * @returns input without tags */ export function stripTags(input) { return $.trim(input.replace(/(<([^>]+)>)/gi, '')); } //# sourceMappingURL=utils.js.map