diff options
Diffstat (limited to 'lib/handlebars/utils.js')
-rw-r--r-- | lib/handlebars/utils.js | 83 |
1 files changed, 37 insertions, 46 deletions
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 1e0e4c9..d14795c 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -1,12 +1,8 @@ -exports.attach = function(Handlebars) { - var toString = Object.prototype.toString; -// BEGIN(BROWSER) - var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack']; -Handlebars.Exception = function(message) { +export function Exception(message) { var tmp = Error.prototype.constructor.apply(this, arguments); // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work. @@ -14,13 +10,15 @@ Handlebars.Exception = function(message) { this[errorProps[idx]] = tmp[errorProps[idx]]; } }; -Handlebars.Exception.prototype = new Error(); + +Exception.prototype = new Error(); // Build out our basic SafeString type -Handlebars.SafeString = function(string) { +export function SafeString(string) { this.string = string; }; -Handlebars.SafeString.prototype.toString = function() { + +SafeString.prototype.toString = function() { return this.string.toString(); }; @@ -40,44 +38,37 @@ var escapeChar = function(chr) { return escape[chr] || "&"; }; -Handlebars.Utils = { - extend: function(obj, value) { - for(var key in value) { - if(value.hasOwnProperty(key)) { - obj[key] = value[key]; - } - } - }, - - escapeExpression: function(string) { - // don't escape SafeStrings, since they're already safe - if (string instanceof Handlebars.SafeString) { - return string.toString(); - } else if (string == null || string === false) { - return ""; - } - - // Force a string conversion as this will be done by the append regardless and - // the regex test will do this transparently behind the scenes, causing issues if - // an object's to string has escaped characters in it. - string = string.toString(); - - if(!possible.test(string)) { return string; } - return string.replace(badChars, escapeChar); - }, - - isEmpty: function(value) { - if (!value && value !== 0) { - return true; - } else if(toString.call(value) === "[object Array]" && value.length === 0) { - return true; - } else { - return false; +export function extend(obj, value) { + for(var key in value) { + if(value.hasOwnProperty(key)) { + obj[key] = value[key]; } } -}; - -// END(BROWSER) +} + +export function escapeExpression(string) { + // don't escape SafeStrings, since they're already safe + if (string instanceof SafeString) { + return string.toString(); + } else if (string == null || string === false) { + return ""; + } -return Handlebars; -}; + // Force a string conversion as this will be done by the append regardless and + // the regex test will do this transparently behind the scenes, causing issues if + // an object's to string has escaped characters in it. + string = string.toString(); + + if(!possible.test(string)) { return string; } + return string.replace(badChars, escapeChar); +} + +export function isEmpty(value) { + if (!value && value !== 0) { + return true; + } else if(toString.call(value) === "[object Array]" && value.length === 0) { + return true; + } else { + return false; + } +} |