diff --git a/jsrender.js b/jsrender.js index a481268..95e8534 100644 --- a/jsrender.js +++ b/jsrender.js @@ -48,7 +48,7 @@ var versionNumber = "v1.0.15", jsvStoreName, rTag, rTmplString, topView, $views, $expando, _ocp = "_ocp", // Observable contextual parameter - $isFunction, $isArray, $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, + $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, delimOpenChar0, delimOpenChar1, delimCloseChar0, delimCloseChar1, linkChar, setting, baseOnError, isRenderCall, @@ -170,6 +170,16 @@ var versionNumber = "v1.0.15", map: dataMap // If jsObservable loaded first, use that definition of dataMap }; +function isFunction(ob) { + return typeof ob === "function"; +} + +if (!Array.isArray) { + Array.isArray = function(obj) { + return ({}.toString).call(obj) === "[object Array]"; + }; +} + function getDerivedMethod(baseMethod, method) { return function() { var ret, @@ -186,7 +196,7 @@ function getDerivedMethod(baseMethod, method) { function getMethod(baseMethod, method) { // For derived methods (or handlers declared declaratively as in {{:foo onChange=~fooChanged}} replace by a derived method, to allow using this.base(...) // or this.baseApply(arguments) to call the base implementation. (Equivalent to this._super(...) and this._superApply(arguments) in jQuery UI) - if ($isFunction(method)) { + if (isFunction(method)) { method = getDerivedMethod( !baseMethod ? noop // no base method implementation, so use noop as base method @@ -273,7 +283,7 @@ function $viewsDelimiters(openChars, closeChars, link) { if (!openChars) { return $subSettings.delimiters; } - if ($isArray(openChars)) { + if (Array.isArray(openChars)) { return $viewsDelimiters.apply($views, openChars); } linkChar = link ? link[0] : linkChar; @@ -431,7 +441,7 @@ function contextParameter(key, value, get) { if (!res || !res._cxp) { // Not a contextual parameter // Set storeView to tag (if this is a tag.ctxPrm() call) or to root view ("data" view of linked template) - storeView = storeView.tagCtx || $isFunction(res) + storeView = storeView.tagCtx || isFunction(res) ? storeView // Is a tag, not a view, or is a computed contextual parameter, so scope to the callView, not the 'scope view' : (storeView = storeView.scope || storeView, !storeView.isTop && storeView.ctx.tag // If this view is in a tag, set storeView to the tag @@ -483,7 +493,7 @@ function contextParameter(key, value, get) { res = newRes; } } - if (res && $isFunction(res)) { + if (res && isFunction(res)) { // If a helper is of type function we will wrap it, so if called with no this pointer it will be called with the // view as 'this' context. If the helper ~foo() was in a data-link expression, the view will have a 'temporary' linkCtx property too. // Note that helper functions on deeper paths will have specific this pointers, from the preceding path. @@ -618,7 +628,7 @@ function convertArgs(tagElse, bound) { // tag.cvtArgs() or tag.cvtArgs(tagElse?, } bindFrom = bindFrom || [0]; l = bindFrom.length; - if (!$isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) { + if (!Array.isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) { converter = [converter]; // Returning converter as first arg, even if converter value is an array bindFrom = [0]; l = 1; @@ -669,7 +679,7 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) { var bindArray = tag[type]; if (bindArray !== undefined) { - bindArray = $isArray(bindArray) ? bindArray : [bindArray]; + bindArray = Array.isArray(bindArray) ? bindArray : [bindArray]; m = bindArray.length; while (m--) { key = bindArray[m]; @@ -819,14 +829,14 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) { bindFromLength = bindFrom.length; if (tag._.bnd && (linkedElement = tag.linkedElement)) { - tag.linkedElement = linkedElement = $isArray(linkedElement) ? linkedElement: [linkedElement]; + tag.linkedElement = linkedElement = Array.isArray(linkedElement) ? linkedElement: [linkedElement]; if (bindToLength !== linkedElement.length) { error("linkedElement not same length as bindTo"); } } if (linkedElement = tag.linkedCtxParam) { - tag.linkedCtxParam = linkedElement = $isArray(linkedElement) ? linkedElement: [linkedElement]; + tag.linkedCtxParam = linkedElement = Array.isArray(linkedElement) ? linkedElement: [linkedElement]; if (bindFromLength !== linkedElement.length) { error("linkedCtxParam not same length as bindFrom/bindTo"); @@ -1047,7 +1057,7 @@ function compileTag(name, tagDef, parentTmpl) { tag.tagName = name; } - if ($isFunction(tagDef)) { + if (isFunction(tagDef)) { // Simple tag declared as function. No presenter instantation. tagDef = { depends: tagDef.depends, @@ -1225,7 +1235,7 @@ function compileTmpl(name, tmpl, parentTmpl, options) { //================= function getDefaultVal(defaultVal, data) { - return $isFunction(defaultVal) + return isFunction(defaultVal) ? defaultVal.call(data) : defaultVal; } @@ -1289,7 +1299,7 @@ function compileViewModel(name, type) { ob = data, arr = []; - if ($isArray(data)) { + if (Array.isArray(data)) { data = data || []; l = data.length; for (; j 0; // Default to #data except for auto-create range scenario {{for start=xxx end=yyy step=zzz}} - props.dataMap = (tagCtx.argDefault !== false && $isArray(tagCtx.args[0]) && + props.dataMap = (tagCtx.argDefault !== false && Array.isArray(tagCtx.args[0]) && (paramsProps.sort || paramsProps.start || paramsProps.end || paramsProps.step || paramsProps.filter || paramsProps.reverse || props.sort || props.start || props.end || props.step || props.filter || props.reverse)) && self.sortDataMap; @@ -3011,7 +3013,6 @@ if (!(jsr || $ && $.render)) { } //========================== Define default delimiters ========================== $subSettings = $sub.settings; -$isArray = ($||jsr).isArray; $viewsSettings.delimiters("{{", "}}", "^"); if (jsrToJq) { // Moving from jsrender namespace to jQuery namepace - copy over the stored items (templates, converters, helpers...) diff --git a/package-lock.json b/package-lock.json index 7accf2f..612c3cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,6 +62,19 @@ "dev": true, "optional": true }, + "node_modules/acorn": { + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/acorn-node": { "version": "1.8.2", "dev": true, @@ -72,17 +85,6 @@ "xtend": "^4.0.2" } }, - "node_modules/acorn-node/node_modules/acorn": { - "version": "7.0.0", - "dev": true, - "license": "MIT", - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/acorn-walk": { "version": "7.0.0", "dev": true, @@ -366,7 +368,9 @@ } }, "node_modules/bn.js": { - "version": "4.11.8", + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.1.tgz", + "integrity": "sha512-k8TVBiPkPJT9uHLdOKfFpqcfprwBFOAAXXozRubr7R7PfIuKvQlzcI4M0pALeqXN09vdaMbUdUj+pass+uULAg==", "dev": true, "license": "MIT" }, @@ -379,6 +383,19 @@ "concat-map": "0.0.1" } }, + "node_modules/braces": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/brorand": { "version": "1.1.0", "dev": true, @@ -517,28 +534,98 @@ } }, "node_modules/browserify-rsa": { - "version": "4.0.1", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.1.1.tgz", + "integrity": "sha512-YBjSAiTqM04ZVei6sXighu679a3SqWORA3qZTEqZImnlkDIFtKc6pNutpjyZ8RJTjQtuYfeetkxM11GwoYXMIQ==", "dev": true, "license": "MIT", "dependencies": { - "bn.js": "^4.1.0", - "randombytes": "^2.0.1" + "bn.js": "^5.2.1", + "randombytes": "^2.1.0", + "safe-buffer": "^5.2.1" + }, + "engines": { + "node": ">= 0.10" } }, + "node_modules/browserify-rsa/node_modules/bn.js": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", + "integrity": "sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/browserify-rsa/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/browserify-sign": { - "version": "4.0.4", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.2.3.tgz", + "integrity": "sha512-JWCZW6SKhfhjJxO8Tyiiy+XYB7cqd2S5/+WeYHsKdNKFlCBhKbblba1A/HN/90YwtxKc8tCErjffZl++UNmGiw==", "dev": true, "license": "ISC", "dependencies": { - "bn.js": "^4.1.1", - "browserify-rsa": "^4.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.2", - "elliptic": "^6.0.0", - "inherits": "^2.0.1", - "parse-asn1": "^5.0.0" + "bn.js": "^5.2.1", + "browserify-rsa": "^4.1.0", + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "elliptic": "^6.5.5", + "hash-base": "~3.0", + "inherits": "^2.0.4", + "parse-asn1": "^5.1.7", + "readable-stream": "^2.3.8", + "safe-buffer": "^5.2.1" + }, + "engines": { + "node": ">= 0.12" } }, + "node_modules/browserify-sign/node_modules/bn.js": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", + "integrity": "sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/browserify-sign/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/browserify-zlib": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/browserify-zlib/-/browserify-zlib-0.2.0.tgz", @@ -671,30 +758,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/chokidar/node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, - "dependencies": { - "fill-range": "^7.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/chokidar/node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, - "dependencies": { - "to-regex-range": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/chokidar/node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -1086,17 +1149,19 @@ } }, "node_modules/elliptic": { - "version": "6.5.1", + "version": "6.6.1", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.6.1.tgz", + "integrity": "sha512-RaddvvMatK2LJHqFJ+YA4WysVN5Ita9E35botqIYspQ4TkRAlCicdzKOjlyv/1Za5RyTNn7di//eEV0uTAfe3g==", "dev": true, "license": "MIT", "dependencies": { - "bn.js": "^4.4.0", - "brorand": "^1.0.1", + "bn.js": "^4.11.9", + "brorand": "^1.1.0", "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.0" + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" } }, "node_modules/emoji-regex": { @@ -1288,6 +1353,19 @@ "reusify": "^1.0.4" } }, + "node_modules/fill-range": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/findup-sync": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-5.0.0.tgz", @@ -1303,43 +1381,6 @@ "node": ">= 10.13.0" } }, - "node_modules/findup-sync/node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, - "dependencies": { - "fill-range": "^7.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/findup-sync/node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, - "dependencies": { - "to-regex-range": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/findup-sync/node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", - "dev": true, - "dependencies": { - "braces": "^3.0.2", - "picomatch": "^2.3.1" - }, - "engines": { - "node": ">=8.6" - } - }, "node_modules/fined": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fined/-/fined-2.0.0.tgz", @@ -2048,6 +2089,16 @@ "node": ">=0.10.0" } }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/is-plain-object": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", @@ -2177,7 +2228,9 @@ "optional": true }, "node_modules/jquery": { - "version": "3.4.1", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz", + "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==", "dev": true, "license": "MIT" }, @@ -2319,6 +2372,20 @@ "safe-buffer": "^5.1.2" } }, + "node_modules/micromatch": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "dev": true, + "license": "MIT", + "dependencies": { + "braces": "^3.0.3", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, "node_modules/miller-rabin": { "version": "4.0.1", "dev": true, @@ -2653,18 +2720,44 @@ } }, "node_modules/parse-asn1": { - "version": "5.1.5", + "version": "5.1.7", + "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.7.tgz", + "integrity": "sha512-CTM5kuWR3sx9IFamcl5ErfPl6ea/N8IYwiJ+vpeB2g+1iknv7zBl5uPwbMbRVznRVbrNY6lGuDoE5b30grmbqg==", "dev": true, "license": "ISC", "dependencies": { - "asn1.js": "^4.0.0", - "browserify-aes": "^1.0.0", - "create-hash": "^1.1.0", - "evp_bytestokey": "^1.0.0", - "pbkdf2": "^3.0.3", - "safe-buffer": "^5.1.1" + "asn1.js": "^4.10.1", + "browserify-aes": "^1.2.0", + "evp_bytestokey": "^1.0.3", + "hash-base": "~3.0", + "pbkdf2": "^3.1.2", + "safe-buffer": "^5.2.1" + }, + "engines": { + "node": ">= 0.10" } }, + "node_modules/parse-asn1/node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/parse-filepath": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/parse-filepath/-/parse-filepath-1.0.2.tgz", @@ -2739,7 +2832,9 @@ } }, "node_modules/pbkdf2": { - "version": "3.0.17", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz", + "integrity": "sha512-iuh7L6jA7JEGu2WxDwtQP1ddOpaJNC4KlDEFfdQajSGgGPNi4OyDc2R7QnbY2bR9QjBVGwgvTdNJZoE7RaxUMA==", "dev": true, "license": "MIT", "dependencies": { @@ -2886,7 +2981,9 @@ } }, "node_modules/readable-stream": { - "version": "2.3.6", + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", "license": "MIT", "dependencies": { "core-util-is": "~1.0.0", @@ -3386,6 +3483,7 @@ "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, + "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, @@ -3393,15 +3491,6 @@ "node": ">=8.0" } }, - "node_modules/to-regex-range/node_modules/is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, - "engines": { - "node": ">=0.12.0" - } - }, "node_modules/to-through": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/to-through/-/to-through-3.0.0.tgz", diff --git a/package.json b/package.json index 4a65a39..3aea0d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "jsrender", - "version": "v1.0.15", + "name": "@labware/jsrender", + "version": "1.0.16", "description": "Best-of-breed templating in browser or on Node.js (with Express 4, Hapi and Browserify integration)", "main": "./jsrender-node.js", "browser": "./jsrender.js", @@ -11,12 +11,15 @@ "homepage": "http://www.jsviews.com/#jsrender", "repository": { "type": "git", - "url": "https://github.com/borismoore/jsrender.git" + "url": "https://github.com/LabWare/jsrender.git" }, "license": "MIT", "bugs": { - "url": "https://github.com/borismoore/jsrender/issues" + "url": "https://github.com/LabWare/jsrender/issues" }, + "publishConfig": { + "@labware:registry": "https://npm.pkg.github.com" + }, "scripts": { "test": "node ./test/unit-tests-node-runner.js" }, diff --git a/test/browserify/bundles/htm-jsrender-tmpl-bundle.js b/test/browserify/bundles/htm-jsrender-tmpl-bundle.js index 81a9d05..ac0f74e 100644 --- a/test/browserify/bundles/htm-jsrender-tmpl-bundle.js +++ b/test/browserify/bundles/htm-jsrender-tmpl-bundle.js @@ -49,7 +49,7 @@ var versionNumber = "v1.0.15", jsvStoreName, rTag, rTmplString, topView, $views, $expando, _ocp = "_ocp", // Observable contextual parameter - $isFunction, $isArray, $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, + $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, delimOpenChar0, delimOpenChar1, delimCloseChar0, delimCloseChar1, linkChar, setting, baseOnError, isRenderCall, @@ -171,6 +171,16 @@ var versionNumber = "v1.0.15", map: dataMap // If jsObservable loaded first, use that definition of dataMap }; +function isFunction(ob) { + return typeof ob === "function"; +} + +if (!Array.isArray) { + Array.isArray = function(obj) { + return ({}.toString).call(obj) === "[object Array]"; + }; +} + function getDerivedMethod(baseMethod, method) { return function() { var ret, @@ -187,7 +197,7 @@ function getDerivedMethod(baseMethod, method) { function getMethod(baseMethod, method) { // For derived methods (or handlers declared declaratively as in {{:foo onChange=~fooChanged}} replace by a derived method, to allow using this.base(...) // or this.baseApply(arguments) to call the base implementation. (Equivalent to this._super(...) and this._superApply(arguments) in jQuery UI) - if ($isFunction(method)) { + if (isFunction(method)) { method = getDerivedMethod( !baseMethod ? noop // no base method implementation, so use noop as base method @@ -274,7 +284,7 @@ function $viewsDelimiters(openChars, closeChars, link) { if (!openChars) { return $subSettings.delimiters; } - if ($isArray(openChars)) { + if (Array.isArray(openChars)) { return $viewsDelimiters.apply($views, openChars); } linkChar = link ? link[0] : linkChar; @@ -432,7 +442,7 @@ function contextParameter(key, value, get) { if (!res || !res._cxp) { // Not a contextual parameter // Set storeView to tag (if this is a tag.ctxPrm() call) or to root view ("data" view of linked template) - storeView = storeView.tagCtx || $isFunction(res) + storeView = storeView.tagCtx || isFunction(res) ? storeView // Is a tag, not a view, or is a computed contextual parameter, so scope to the callView, not the 'scope view' : (storeView = storeView.scope || storeView, !storeView.isTop && storeView.ctx.tag // If this view is in a tag, set storeView to the tag @@ -484,7 +494,7 @@ function contextParameter(key, value, get) { res = newRes; } } - if (res && $isFunction(res)) { + if (res && isFunction(res)) { // If a helper is of type function we will wrap it, so if called with no this pointer it will be called with the // view as 'this' context. If the helper ~foo() was in a data-link expression, the view will have a 'temporary' linkCtx property too. // Note that helper functions on deeper paths will have specific this pointers, from the preceding path. @@ -619,7 +629,7 @@ function convertArgs(tagElse, bound) { // tag.cvtArgs() or tag.cvtArgs(tagElse?, } bindFrom = bindFrom || [0]; l = bindFrom.length; - if (!$isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) { + if (!Array.isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) { converter = [converter]; // Returning converter as first arg, even if converter value is an array bindFrom = [0]; l = 1; @@ -670,7 +680,7 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) { var bindArray = tag[type]; if (bindArray !== undefined) { - bindArray = $isArray(bindArray) ? bindArray : [bindArray]; + bindArray = Array.isArray(bindArray) ? bindArray : [bindArray]; m = bindArray.length; while (m--) { key = bindArray[m]; @@ -820,14 +830,14 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) { bindFromLength = bindFrom.length; if (tag._.bnd && (linkedElement = tag.linkedElement)) { - tag.linkedElement = linkedElement = $isArray(linkedElement) ? linkedElement: [linkedElement]; + tag.linkedElement = linkedElement = Array.isArray(linkedElement) ? linkedElement: [linkedElement]; if (bindToLength !== linkedElement.length) { error("linkedElement not same length as bindTo"); } } if (linkedElement = tag.linkedCtxParam) { - tag.linkedCtxParam = linkedElement = $isArray(linkedElement) ? linkedElement: [linkedElement]; + tag.linkedCtxParam = linkedElement = Array.isArray(linkedElement) ? linkedElement: [linkedElement]; if (bindFromLength !== linkedElement.length) { error("linkedCtxParam not same length as bindFrom/bindTo"); @@ -1048,7 +1058,7 @@ function compileTag(name, tagDef, parentTmpl) { tag.tagName = name; } - if ($isFunction(tagDef)) { + if (isFunction(tagDef)) { // Simple tag declared as function. No presenter instantation. tagDef = { depends: tagDef.depends, @@ -1226,7 +1236,7 @@ function compileTmpl(name, tmpl, parentTmpl, options) { //================= function getDefaultVal(defaultVal, data) { - return $isFunction(defaultVal) + return isFunction(defaultVal) ? defaultVal.call(data) : defaultVal; } @@ -1290,7 +1300,7 @@ function compileViewModel(name, type) { ob = data, arr = []; - if ($isArray(data)) { + if (Array.isArray(data)) { data = data || []; l = data.length; for (; j 0; // Default to #data except for auto-create range scenario {{for start=xxx end=yyy step=zzz}} - props.dataMap = (tagCtx.argDefault !== false && $isArray(tagCtx.args[0]) && + props.dataMap = (tagCtx.argDefault !== false && Array.isArray(tagCtx.args[0]) && (paramsProps.sort || paramsProps.start || paramsProps.end || paramsProps.step || paramsProps.filter || paramsProps.reverse || props.sort || props.start || props.end || props.step || props.filter || props.reverse)) && self.sortDataMap; @@ -3012,7 +3014,6 @@ if (!(jsr || $ && $.render)) { } //========================== Define default delimiters ========================== $subSettings = $sub.settings; -$isArray = ($||jsr).isArray; $viewsSettings.delimiters("{{", "}}", "^"); if (jsrToJq) { // Moving from jsrender namespace to jQuery namepace - copy over the stored items (templates, converters, helpers...) diff --git a/test/browserify/bundles/html-jsr-tmpl-bundle.js b/test/browserify/bundles/html-jsr-tmpl-bundle.js index 29caa95..6a4eae9 100644 --- a/test/browserify/bundles/html-jsr-tmpl-bundle.js +++ b/test/browserify/bundles/html-jsr-tmpl-bundle.js @@ -49,7 +49,7 @@ var versionNumber = "v1.0.15", jsvStoreName, rTag, rTmplString, topView, $views, $expando, _ocp = "_ocp", // Observable contextual parameter - $isFunction, $isArray, $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, + $templates, $converters, $helpers, $tags, $sub, $subSettings, $subSettingsAdvanced, $viewsSettings, delimOpenChar0, delimOpenChar1, delimCloseChar0, delimCloseChar1, linkChar, setting, baseOnError, isRenderCall, @@ -171,6 +171,16 @@ var versionNumber = "v1.0.15", map: dataMap // If jsObservable loaded first, use that definition of dataMap }; +function isFunction(ob) { + return typeof ob === "function"; +} + +if (!Array.isArray) { + Array.isArray = function(obj) { + return ({}.toString).call(obj) === "[object Array]"; + }; +} + function getDerivedMethod(baseMethod, method) { return function() { var ret, @@ -187,7 +197,7 @@ function getDerivedMethod(baseMethod, method) { function getMethod(baseMethod, method) { // For derived methods (or handlers declared declaratively as in {{:foo onChange=~fooChanged}} replace by a derived method, to allow using this.base(...) // or this.baseApply(arguments) to call the base implementation. (Equivalent to this._super(...) and this._superApply(arguments) in jQuery UI) - if ($isFunction(method)) { + if (isFunction(method)) { method = getDerivedMethod( !baseMethod ? noop // no base method implementation, so use noop as base method @@ -274,7 +284,7 @@ function $viewsDelimiters(openChars, closeChars, link) { if (!openChars) { return $subSettings.delimiters; } - if ($isArray(openChars)) { + if (Array.isArray(openChars)) { return $viewsDelimiters.apply($views, openChars); } linkChar = link ? link[0] : linkChar; @@ -432,7 +442,7 @@ function contextParameter(key, value, get) { if (!res || !res._cxp) { // Not a contextual parameter // Set storeView to tag (if this is a tag.ctxPrm() call) or to root view ("data" view of linked template) - storeView = storeView.tagCtx || $isFunction(res) + storeView = storeView.tagCtx || isFunction(res) ? storeView // Is a tag, not a view, or is a computed contextual parameter, so scope to the callView, not the 'scope view' : (storeView = storeView.scope || storeView, !storeView.isTop && storeView.ctx.tag // If this view is in a tag, set storeView to the tag @@ -484,7 +494,7 @@ function contextParameter(key, value, get) { res = newRes; } } - if (res && $isFunction(res)) { + if (res && isFunction(res)) { // If a helper is of type function we will wrap it, so if called with no this pointer it will be called with the // view as 'this' context. If the helper ~foo() was in a data-link expression, the view will have a 'temporary' linkCtx property too. // Note that helper functions on deeper paths will have specific this pointers, from the preceding path. @@ -619,7 +629,7 @@ function convertArgs(tagElse, bound) { // tag.cvtArgs() or tag.cvtArgs(tagElse?, } bindFrom = bindFrom || [0]; l = bindFrom.length; - if (!$isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) { + if (!Array.isArray(converter) || (converter.arg0 !== false && (l === 1 || converter.length !== l || converter.arg0))) { converter = [converter]; // Returning converter as first arg, even if converter value is an array bindFrom = [0]; l = 1; @@ -670,7 +680,7 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) { var bindArray = tag[type]; if (bindArray !== undefined) { - bindArray = $isArray(bindArray) ? bindArray : [bindArray]; + bindArray = Array.isArray(bindArray) ? bindArray : [bindArray]; m = bindArray.length; while (m--) { key = bindArray[m]; @@ -820,14 +830,14 @@ function renderTag(tagName, parentView, tmpl, tagCtxs, isUpdate, onError) { bindFromLength = bindFrom.length; if (tag._.bnd && (linkedElement = tag.linkedElement)) { - tag.linkedElement = linkedElement = $isArray(linkedElement) ? linkedElement: [linkedElement]; + tag.linkedElement = linkedElement = Array.isArray(linkedElement) ? linkedElement: [linkedElement]; if (bindToLength !== linkedElement.length) { error("linkedElement not same length as bindTo"); } } if (linkedElement = tag.linkedCtxParam) { - tag.linkedCtxParam = linkedElement = $isArray(linkedElement) ? linkedElement: [linkedElement]; + tag.linkedCtxParam = linkedElement = Array.isArray(linkedElement) ? linkedElement: [linkedElement]; if (bindFromLength !== linkedElement.length) { error("linkedCtxParam not same length as bindFrom/bindTo"); @@ -1048,7 +1058,7 @@ function compileTag(name, tagDef, parentTmpl) { tag.tagName = name; } - if ($isFunction(tagDef)) { + if (isFunction(tagDef)) { // Simple tag declared as function. No presenter instantation. tagDef = { depends: tagDef.depends, @@ -1226,7 +1236,7 @@ function compileTmpl(name, tmpl, parentTmpl, options) { //================= function getDefaultVal(defaultVal, data) { - return $isFunction(defaultVal) + return isFunction(defaultVal) ? defaultVal.call(data) : defaultVal; } @@ -1290,7 +1300,7 @@ function compileViewModel(name, type) { ob = data, arr = []; - if ($isArray(data)) { + if (Array.isArray(data)) { data = data || []; l = data.length; for (; j 0; // Default to #data except for auto-create range scenario {{for start=xxx end=yyy step=zzz}} - props.dataMap = (tagCtx.argDefault !== false && $isArray(tagCtx.args[0]) && + props.dataMap = (tagCtx.argDefault !== false && Array.isArray(tagCtx.args[0]) && (paramsProps.sort || paramsProps.start || paramsProps.end || paramsProps.step || paramsProps.filter || paramsProps.reverse || props.sort || props.start || props.end || props.step || props.filter || props.reverse)) && self.sortDataMap; @@ -3012,7 +3014,6 @@ if (!(jsr || $ && $.render)) { } //========================== Define default delimiters ========================== $subSettings = $sub.settings; -$isArray = ($||jsr).isArray; $viewsSettings.delimiters("{{", "}}", "^"); if (jsrToJq) { // Moving from jsrender namespace to jQuery namepace - copy over the stored items (templates, converters, helpers...)