summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/utils.js
diff options
context:
space:
mode:
authorKevin Decker <kpdecker@gmail.com>2013-10-12 14:22:10 -0700
committerKevin Decker <kpdecker@gmail.com>2013-10-12 14:22:10 -0700
commit583141de7cb61eb70eaa6b33c25f475f3048071b (patch)
tree47c419f82f2941fbde5ff5aa33a85b79d6772b4c /lib/handlebars/utils.js
parent782aae95d0b430058e2f65b8eba1621453f9055e (diff)
parent3f96319f103d1e9dc4a6de220d2a9934e00df0b6 (diff)
downloadhandlebars.js-583141de7cb61eb70eaa6b33c25f475f3048071b.zip
handlebars.js-583141de7cb61eb70eaa6b33c25f475f3048071b.tar.gz
handlebars.js-583141de7cb61eb70eaa6b33c25f475f3048071b.tar.bz2
Merge pull request #628 from wycats/es6-modules
Convert code to ES6 modules
Diffstat (limited to 'lib/handlebars/utils.js')
-rw-r--r--lib/handlebars/utils.js102
1 files changed, 35 insertions, 67 deletions
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js
index 59947ca..998c9ca 100644
--- a/lib/handlebars/utils.js
+++ b/lib/handlebars/utils.js
@@ -1,29 +1,6 @@
-exports.attach = function(Handlebars) {
+import SafeString from "./safe-string";
-var toString = Object.prototype.toString,
- isArray = Array.isArray;
-
-// BEGIN(BROWSER)
-
-var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
-
-Handlebars.Exception = function(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.
- for (var idx = 0; idx < errorProps.length; idx++) {
- this[errorProps[idx]] = tmp[errorProps[idx]];
- }
-};
-Handlebars.Exception.prototype = new Error();
-
-// Build out our basic SafeString type
-Handlebars.SafeString = function(string) {
- this.string = string;
-};
-Handlebars.SafeString.prototype.toString = function() {
- return "" + this.string;
-};
+var isArray = Array.isArray;
var escape = {
"&": "&amp;",
@@ -37,50 +14,41 @@ var escape = {
var badChars = /[&<>"'`]/g;
var possible = /[&<>"'`]/;
-var escapeChar = function(chr) {
+function escapeChar(chr) {
return escape[chr] || "&amp;";
-};
-
-Handlebars.Utils = {
- extend: function(obj, value) {
- for(var key in value) {
- if(value.hasOwnProperty(key)) {
- obj[key] = value[key];
- }
- }
- },
-
- escapeExpression: function(string) {
- /*jshint eqnull: true */
-
- // don't escape SafeStrings, since they're already safe
- if (string instanceof Handlebars.SafeString) {
- return string.toString();
- } else if (!string && string !== 0) {
- 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;
-
- if(!possible.test(string)) { return string; }
- return string.replace(badChars, escapeChar);
- },
+}
- isEmpty: function(value) {
- if (!value && value !== 0) {
- return true;
- } else if (isArray(value) && 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 && string !== 0) {
+ 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;
+
+ if(!possible.test(string)) { return string; }
+ return string.replace(badChars, escapeChar);
+}
+
+export function isEmpty(value) {
+ if (!value && value !== 0) {
+ return true;
+ } else if (isArray(value) && value.length === 0) {
+ return true;
+ } else {
+ return false;
+ }
+}