react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / handlebars / dist / cjs / handlebars / utils.js
80724 views"use strict";1/*jshint -W004 */2var escape = {3"&": "&",4"<": "<",5">": ">",6'"': """,7"'": "'",8"`": "`"9};1011var badChars = /[&<>"'`]/g;12var possible = /[&<>"'`]/;1314function escapeChar(chr) {15return escape[chr];16}1718function extend(obj /* , ...source */) {19for (var i = 1; i < arguments.length; i++) {20for (var key in arguments[i]) {21if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {22obj[key] = arguments[i][key];23}24}25}2627return obj;28}2930exports.extend = extend;var toString = Object.prototype.toString;31exports.toString = toString;32// Sourced from lodash33// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt34var isFunction = function(value) {35return typeof value === 'function';36};37// fallback for older versions of Chrome and Safari38/* istanbul ignore next */39if (isFunction(/x/)) {40isFunction = function(value) {41return typeof value === 'function' && toString.call(value) === '[object Function]';42};43}44var isFunction;45exports.isFunction = isFunction;46/* istanbul ignore next */47var isArray = Array.isArray || function(value) {48return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;49};50exports.isArray = isArray;51// Older IE versions do not directly support indexOf so we must implement our own, sadly.52function indexOf(array, value) {53for (var i = 0, len = array.length; i < len; i++) {54if (array[i] === value) {55return i;56}57}58return -1;59}6061exports.indexOf = indexOf;62function escapeExpression(string) {63// don't escape SafeStrings, since they're already safe64if (string && string.toHTML) {65return string.toHTML();66} else if (string == null) {67return "";68} else if (!string) {69return string + '';70}7172// Force a string conversion as this will be done by the append regardless and73// the regex test will do this transparently behind the scenes, causing issues if74// an object's to string has escaped characters in it.75string = "" + string;7677if(!possible.test(string)) { return string; }78return string.replace(badChars, escapeChar);79}8081exports.escapeExpression = escapeExpression;function isEmpty(value) {82if (!value && value !== 0) {83return true;84} else if (isArray(value) && value.length === 0) {85return true;86} else {87return false;88}89}9091exports.isEmpty = isEmpty;function blockParams(params, ids) {92params.path = ids;93return params;94}9596exports.blockParams = blockParams;function appendContextPath(contextPath, id) {97return (contextPath ? contextPath + '.' : '') + id;98}99100exports.appendContextPath = appendContextPath;101102