11 const badChars = /[&<>"'`=]/g,
12 possible = /[&<>"'`=]/;
14 function escapeChar(chr) {
18 export function extend(obj/* , ...source */) {
19 for (let i = 1; i < arguments.length; i++) {
20 for (let key in arguments[i]) {
21 if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
22 obj[key] = arguments[i][key];
30 export let toString = Object.prototype.toString;
32 // Sourced from lodash
33 // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
34 /* eslint-disable func-style */
35 let isFunction = function(value) {
36 return typeof value === 'function';
38 // fallback for older versions of Chrome and Safari
39 /* istanbul ignore next */
40 if (isFunction(/x/)) {
41 isFunction = function(value) {
42 return typeof value === 'function' && toString.call(value) === '[object Function]';
46 /* eslint-enable func-style */
48 /* istanbul ignore next */
49 export const isArray = Array.isArray || function(value) {
50 return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
53 // Older IE versions do not directly support indexOf so we must implement our own, sadly.
54 export function indexOf(array, value) {
55 for (let i = 0, len = array.length; i < len; i++) {
56 if (array[i] === value) {
64 export function escapeExpression(string) {
65 if (typeof string !== 'string') {
66 // don't escape SafeStrings, since they're already safe
67 if (string && string.toHTML) {
68 return string.toHTML();
69 } else if (string == null) {
75 // Force a string conversion as this will be done by the append regardless and
76 // the regex test will do this transparently behind the scenes, causing issues if
77 // an object's to string has escaped characters in it.
81 if (!possible.test(string)) { return string; }
82 return string.replace(badChars, escapeChar);
85 export function isEmpty(value) {
86 if (!value && value !== 0) {
88 } else if (isArray(value) && value.length === 0) {
95 export function createFrame(object) {
96 let frame = extend({}, object);
97 frame._parent = object;
101 export function blockParams(params, ids) {
106 export function appendContextPath(contextPath, id) {
107 return (contextPath ? contextPath + '.' : '') + id;