react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / lib / handlebars / utils.js
80698 views/*jshint -W004 */1var escape = {2"&": "&",3"<": "<",4">": ">",5'"': """,6"'": "'",7"`": "`"8};910var badChars = /[&<>"'`]/g;11var possible = /[&<>"'`]/;1213function escapeChar(chr) {14return escape[chr];15}1617export function extend(obj /* , ...source */) {18for (var i = 1; i < arguments.length; i++) {19for (var key in arguments[i]) {20if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {21obj[key] = arguments[i][key];22}23}24}2526return obj;27}2829export var toString = Object.prototype.toString;3031// Sourced from lodash32// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt33var isFunction = function(value) {34return typeof value === 'function';35};36// fallback for older versions of Chrome and Safari37/* istanbul ignore next */38if (isFunction(/x/)) {39isFunction = function(value) {40return typeof value === 'function' && toString.call(value) === '[object Function]';41};42}43export var isFunction;4445/* istanbul ignore next */46export var isArray = Array.isArray || function(value) {47return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;48};4950// Older IE versions do not directly support indexOf so we must implement our own, sadly.51export function indexOf(array, value) {52for (var i = 0, len = array.length; i < len; i++) {53if (array[i] === value) {54return i;55}56}57return -1;58}596061export function escapeExpression(string) {62// don't escape SafeStrings, since they're already safe63if (string && string.toHTML) {64return string.toHTML();65} else if (string == null) {66return "";67} else if (!string) {68return string + '';69}7071// Force a string conversion as this will be done by the append regardless and72// the regex test will do this transparently behind the scenes, causing issues if73// an object's to string has escaped characters in it.74string = "" + string;7576if(!possible.test(string)) { return string; }77return string.replace(badChars, escapeChar);78}7980export function isEmpty(value) {81if (!value && value !== 0) {82return true;83} else if (isArray(value) && value.length === 0) {84return true;85} else {86return false;87}88}8990export function blockParams(params, ids) {91params.path = ids;92return params;93}9495export function appendContextPath(contextPath, id) {96return (contextPath ? contextPath + '.' : '') + id;97}9899100