Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / handlebars / lib / handlebars / utils.js
1 const escape = {
2   '&': '&',
3   '<': '&lt;',
4   '>': '&gt;',
5   '"': '&quot;',
6   "'": '&#x27;',
7   '`': '&#x60;',
8   '=': '&#x3D;'
9 };
10
11 const badChars = /[&<>"'`=]/g,
12       possible = /[&<>"'`=]/;
13
14 function escapeChar(chr) {
15   return escape[chr];
16 }
17
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];
23       }
24     }
25   }
26
27   return obj;
28 }
29
30 export let toString = Object.prototype.toString;
31
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';
37 };
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]';
43   };
44 }
45 export {isFunction};
46 /* eslint-enable func-style */
47
48 /* istanbul ignore next */
49 export const isArray = Array.isArray || function(value) {
50   return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
51 };
52
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) {
57       return i;
58     }
59   }
60   return -1;
61 }
62
63
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) {
70       return '';
71     } else if (!string) {
72       return string + '';
73     }
74
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.
78     string = '' + string;
79   }
80
81   if (!possible.test(string)) { return string; }
82   return string.replace(badChars, escapeChar);
83 }
84
85 export function isEmpty(value) {
86   if (!value && value !== 0) {
87     return true;
88   } else if (isArray(value) && value.length === 0) {
89     return true;
90   } else {
91     return false;
92   }
93 }
94
95 export function createFrame(object) {
96   let frame = extend({}, object);
97   frame._parent = object;
98   return frame;
99 }
100
101 export function blockParams(params, ids) {
102   params.path = ids;
103   return params;
104 }
105
106 export function appendContextPath(contextPath, id) {
107   return (contextPath ? contextPath + '.' : '') + id;
108 }