Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kandybars

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kandybars - npm Package Compare versions

Comparing version 0.9.1 to 0.9.2

4

CHANGELOG.md
# Changelog
## 0.9.2
- Updates dependencies
- Removes unused devDependencies
## 0.9.1

@@ -4,0 +8,0 @@ - Updates dependencies

30

dist/index.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,19 +6,16 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _extend = require('@jalik/extend');
var _extend = require("@jalik/extend");
var _kandybars = require('./kandybars');
var _kandybars = _interopRequireWildcard(require("./kandybars"));
var _kandybars2 = _interopRequireDefault(_kandybars);
var _template = _interopRequireDefault(require("./template"));
var _template = require('./template');
var _templateInstance = _interopRequireDefault(require("./template-instance"));
var _template2 = _interopRequireDefault(_template);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _templateInstance = require('./template-instance');
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
var _templateInstance2 = _interopRequireDefault(_templateInstance);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*

@@ -47,7 +44,8 @@ * The MIT License (MIT)

*/
var _default = (0, _extend.extend)(_kandybars.default, {
Template: _template.default,
Templates: _kandybars.Templates,
TemplateInstance: _templateInstance.default
});
exports.default = (0, _extend.extend)(_kandybars2.default, {
Template: _template2.default,
Templates: _kandybars.Templates,
TemplateInstance: _templateInstance2.default
});
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,44 +6,23 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _extend = require("@jalik/extend");
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /*
* The MIT License (MIT)
*
* Copyright (c) 2018 Karl STEIN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var _patterns = _interopRequireDefault(require("./patterns"));
var _extend = require('@jalik/extend');
var _reservedWords = _interopRequireDefault(require("./reserved-words"));
var _patterns = require('./patterns');
var _template = _interopRequireDefault(require("./template"));
var _patterns2 = _interopRequireDefault(_patterns);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _reservedWords = require('./reserved-words');
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
var _reservedWords2 = _interopRequireDefault(_reservedWords);
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
var _template = require('./template');
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
var _template2 = _interopRequireDefault(_template);
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -76,3 +55,2 @@ var Kandybars = {

/**

@@ -91,11 +69,9 @@ * Returns the value of the condition

expression = expression.replace(/[\r\n]/g, '');
}
} // eslint-disable-next-line
// eslint-disable-next-line
eval('kbRes = ( ' + expression + ' );');
eval("kbRes = ( ".concat(expression, " );"));
return kbRes;
},
/**

@@ -113,3 +89,2 @@ * Checks if a template exists

/**

@@ -134,3 +109,3 @@ * Returns block arguments from string

if ((firstChar === '"' || firstChar === '\'') && (firstChar !== lastChar || '\\' + lastChar === split[a].slice(-2))) {
if ((firstChar === '"' || firstChar === '\'') && (firstChar !== lastChar || "\\".concat(lastChar) === split[a].slice(-2))) {
var merge = [split[a]];

@@ -140,6 +115,5 @@

lastChar = split[b].slice(-1);
merge.push(split[b]);
merge.push(split[b]); // Check if last char matches first char and is not escaped
// Check if last char matches first char and is not escaped
if (lastChar === firstChar && '\\' + lastChar !== split[b].slice(-2)) {
if (lastChar === firstChar && "\\".concat(lastChar) !== split[b].slice(-2)) {
a = b;

@@ -154,6 +128,6 @@ args.push(merge.join(' '));

}
return args;
},
/**

@@ -177,3 +151,6 @@ * Returns "each" blocks

startIndexes.push(startIndex);
tags.push({ index: startIndex, isStart: true });
tags.push({
index: startIndex,
isStart: true
});
}

@@ -190,6 +167,12 @@ } while (startIndex !== -1);

if (i >= tags.length) {
tags.push({ index: endIndex, isStart: false });
tags.push({
index: endIndex,
isStart: false
});
break;
} else if (endIndex < tags[i].index && i > 0) {
tags.splice(i, 0, { index: endIndex, isStart: false });
tags.splice(i, 0, {
index: endIndex,
isStart: false
});
break;

@@ -199,5 +182,5 @@ }

}
} while (endIndex !== -1);
} while (endIndex !== -1); // Check coherence
// Check coherence
if (startIndexes.length > endIndexes.length) {

@@ -207,5 +190,5 @@ throw new Error('Missing closing {{/each}} somewhere');

throw new Error('Missing opening {{#each ..}} somewhere');
}
} // Extract blocks contents
// Extract blocks contents
for (var _i = 1; _i < tags.length; _i += 1) {

@@ -223,10 +206,10 @@ if (!tags[_i].isStart && tags[_i - 1].isStart) {

source: source
});
// Remove indexes from list
}); // Remove indexes from list
tags.splice(_i - 1, 2);
_i = 0;
}
}
} // Removes child blocks
// Removes child blocks
for (var _i2 = 0; _i2 < blocks.length; _i2 += 1) {

@@ -243,3 +226,2 @@ for (var j = 0; j < blocks.length; j += 1) {

/**

@@ -254,3 +236,2 @@ * Returns the template

/**

@@ -265,3 +246,2 @@ * Checks if helper exists

/**

@@ -273,6 +253,5 @@ * Checks if template exists

isTemplate: function isTemplate(name) {
return typeof this.templates[name] !== 'undefined' && this.templates[name] instanceof _template2.default;
return typeof this.templates[name] !== 'undefined' && this.templates[name] instanceof _template.default;
},
/**

@@ -287,16 +266,14 @@ * Loads a file

// Get file type
var fileType = url.substr(url.lastIndexOf('.') + 1);
var fileType = url.substr(url.lastIndexOf('.') + 1); // Prepare HTTP request
// Prepare HTTP request
var req = new XMLHttpRequest();
// todo return cached version of the URL
var req = new XMLHttpRequest(); // todo return cached version of the URL
// Error callback
// Error callback
req.onerror = function (ev) {
if (typeof callback === 'function') {
callback.call(_this, new Error('Cannot load file : ' + url, ev.target.status));
callback.call(_this, new Error("Cannot load file : ".concat(url), ev.target.status));
}
};
}; // State changed callback
// State changed callback
req.onreadystatechange = function () {

@@ -311,2 +288,3 @@ if (req.readyState === 4) {

break;
case 'html':

@@ -318,6 +296,9 @@ case 'hbml':

_this.parseTemplates(req.responseText);
break;
default:
}
// Execute the callback
} // Execute the callback
if (typeof callback === 'function') {

@@ -328,11 +309,10 @@ callback.call(_this, null);

// Execute the callback
callback.call(_this, new Error('Cannot load file : ' + url));
callback.call(_this, new Error("Cannot load file : ".concat(url)));
}
}
};
}; // Prepare async request
// Prepare async request
req.open('GET', url, true);
// Avoid browser to parse HTML content
req.open('GET', url, true); // Avoid browser to parse HTML content
switch (fileType) {

@@ -345,9 +325,10 @@ case 'html':

break;
default:
}
// Get file
} // Get file
req.send(null);
},
/**

@@ -362,18 +343,17 @@ * Returns block arguments with computed value

parseBlockArguments: function parseBlockArguments(text, data, options) {
var args = this.fetchBlockArguments(text);
var args = this.fetchBlockArguments(text); // Replace arguments
// Replace arguments
for (var i = 0; i < args.length; i += 1) {
var value = this.parseValue(args[i], data, options);
var value = this.parseValue(args[i], data, options); // Unquote string ("test" => test)
// Unquote string ("test" => test)
if (/^(["'])[^\1]+?\1$/.test(value)) {
value = value.substring(1, value.length - 1);
}
args[i] = value;
}
return args;
},
/**

@@ -400,3 +380,3 @@ * Returns block params with computed value

if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null) {
if (_typeof(value) === 'object' && value !== null) {
params = (0, _extend.extendRecursively)({}, value, params);

@@ -409,6 +389,6 @@ }

}
return params;
},
/**

@@ -428,3 +408,2 @@ * Returns block arguments with computed value

/**

@@ -444,3 +423,2 @@ * Returns block params with computed value

/**

@@ -452,4 +430,6 @@ * Search and creates templates found in the HTML code

parseTemplates: function parseTemplates(html) {
var templates = { length: 0 };
var matches = html.match(_patterns2.default.templateRegExp);
var templates = {
length: 0
};
var matches = html.match(_patterns.default.templateRegExp);

@@ -459,23 +439,22 @@ for (var i = 0; i < matches.length; i += 1) {

var nameMatch = template.match(/name=(["'])([^"]+)\1/);
var name = nameMatch && nameMatch[2];
var name = nameMatch && nameMatch[2]; // Check template name
// Check template name
if (typeof name !== 'string' || name.length === 0) {
throw new SyntaxError('Missing "name" attribute for <template>');
}
if (name === 'length') {
throw new SyntaxError('Value of "name" attribute for <template> cannot be "length"');
}
} // Remove template tags
// Remove template tags
var src = template.replace(_patterns2.default.templateTagsRegExp, '');
// Register template
var src = template.replace(_patterns.default.templateTagsRegExp, ''); // Register template
templates[name] = this.registerTemplate(name, src);
templates.length += 1;
}
return templates;
},
/**

@@ -496,39 +475,46 @@ * Returns the parsed value

return newVal.substr(1, newVal.length - 2);
}
// Ignore operator
} // Ignore operator
if (['+', '-', '*', '/'].indexOf(newVal) !== -1) {
return newVal;
}
// Boolean
} // Boolean
if (/^true$/i.test(newVal)) {
return true;
}
if (/^false$/i.test(newVal)) {
return false;
}
// Float
} // Float
if (/^[+-]?[0-9]*[.,][0-9]+$/.test(newVal)) {
return parseFloat(newVal.replace(',', '.'));
}
// Integer
} // Integer
if (/^[+-]?(?:[0-9]+|Infinity)$/.test(newVal)) {
return Number.parseInt(newVal, 10);
}
// Ignore reserved word
if (_reservedWords2.default.indexOf(newVal) !== -1) {
} // Ignore reserved word
if (_reservedWords.default.indexOf(newVal) !== -1) {
return newVal;
}
// Resolve path
if (_patterns2.default.contextPathRegExp.test(newVal)) {
} // Resolve path
if (_patterns.default.contextPathRegExp.test(newVal)) {
newVal = this.resolvePath(newVal, data, options);
if (typeof newVal === 'string') {
newVal = '"' + newVal.replace(/"/g, '\\"') + '"';
newVal = "\"".concat(newVal.replace(/"/g, '\\"'), "\"");
}
}
}
return newVal;
},
/**

@@ -543,16 +529,19 @@ * Registers a helper

}
if (!/^[a-zA-Z_]+[a-zA-Z0-9_]*$/.test(name)) {
throw new Error('Helper name is not valid: ' + name);
throw new Error("Helper name is not valid: ".concat(name));
}
if (typeof callback !== 'function') {
throw new Error('Helper callback must be a function');
}
if (this.isHelper(name)) {
// eslint-disable-next-line no-console
console.warn('Helper "' + name + '" has been defined already');
console.warn("Helper \"".concat(name, "\" has been defined already"));
}
this.helpers[name] = callback;
},
/**

@@ -565,7 +554,6 @@ * Registers a template

registerTemplate: function registerTemplate(name, html) {
this.templates[name] = new _template2.default(name, html);
this.templates[name] = new _template.default(name, html);
return this.templates[name];
},
/**

@@ -580,4 +568,5 @@ * Returns the generated template

if (!this.isTemplate(name)) {
throw new Error('Template "' + name + '" does not exist');
throw new Error("Template \"".concat(name, "\" does not exist"));
}
var template = this.getTemplate(name);

@@ -588,3 +577,2 @@ var tpl = template.createInstance(data, options);

/**

@@ -599,6 +587,5 @@ * Returns the generated template

// Generate a temporary name
var name = 'tpl_' + Date.now();
var name = "tpl_".concat(Date.now()); // Create and render the template
// Create and render the template
var template = new _template2.default(name, html);
var template = new _template.default(name, html);
var tpl = template.createInstance(data, options);

@@ -608,3 +595,2 @@ return tpl.render(options);

/**

@@ -622,3 +608,3 @@ * Replaces all templating elements

if ((typeof ctx === 'undefined' ? 'undefined' : _typeof(ctx)) === 'object') {
if (_typeof(ctx) === 'object') {
var dataKeys = Object.keys(ctx);

@@ -648,3 +634,2 @@ var dataKeysLength = dataKeys.length;

/**

@@ -660,3 +645,2 @@ * Replaces all attributes

/**

@@ -678,12 +662,10 @@ * Replaces all blocks

var object = void 0;
blocks[b].result = '';
if (/^[^ ]+ in [^ ]+$/.test(args)) {
// todo expose context in a variable (ex: each item in items)
} else if (_patterns2.default.contextPathRegExp.test(args)) {
if (/^[^ ]+ in [^ ]+$/.test(args)) {// todo expose context in a variable (ex: each item in items)
} else if (_patterns.default.contextPathRegExp.test(args)) {
object = this.resolvePath(args, data, options);
}
} // Loop on values
// Loop on values
if (object !== null && typeof object !== 'undefined') {

@@ -694,9 +676,12 @@ if (typeof object.length === 'number') {

if ((typeof blockContext === 'undefined' ? 'undefined' : _typeof(blockContext)) === 'object') {
if (_typeof(blockContext) === 'object') {
blockContext['@index'] = i;
}
var blockHtml = html.replace('{{@index}}', i);
blockHtml = blockHtml.replace('@index', String(i));
blocks[b].result += this.replaceAll(blockHtml, blockContext, {
special: { '@index': i },
special: {
'@index': i
},
parent: {

@@ -708,3 +693,3 @@ data: data,

}
} else if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object') {
} else if (_typeof(object) === 'object') {
var objectKeys = Object.keys(object);

@@ -717,9 +702,13 @@ var objectKeysLength = objectKeys.length;

if ((typeof _blockContext === 'undefined' ? 'undefined' : _typeof(_blockContext)) === 'object') {
if (_typeof(_blockContext) === 'object') {
_blockContext['@key'] = key;
}
var _blockHtml = html.replace('{{@key}}', key);
_blockHtml = _blockHtml.replace('@key', key);
blocks[b].result += this.replaceAll(_blockHtml, _blockContext, {
special: { '@key': key },
special: {
'@key': key
},
parent: {

@@ -732,11 +721,11 @@ data: data,

}
}
} // Replace source by compiled code
// Replace source by compiled code
src = src.replace(blocks[b].source, blocks[b].result);
}
return src;
},
/**

@@ -748,6 +737,5 @@ * Replaces all comments

replaceComments: function replaceComments(source) {
return source.replace(_patterns2.default.commentBlockRegExp, '');
return source.replace(_patterns.default.commentBlockRegExp, '');
},
/**

@@ -763,7 +751,6 @@ * Replaces all conditions

var src = source;
var src = source; // Very greedy !!
// Very greedy !!
while (src.indexOf('{{#if') !== -1) {
src = src.replace(_patterns2.default.conditionBlockRegExp, function (match, test, html) {
src = src.replace(_patterns.default.conditionBlockRegExp, function (match, test, html) {
var result = '';

@@ -774,8 +761,6 @@

cond1 = _html$split2[0],
cond2 = _html$split2[1];
cond2 = _html$split2[1]; // Replace variables in condition
// Replace variables in condition
var condition = test.replace(_patterns2.default.blockArgumentRegExp, function (match2, variable) {
var condition = test.replace(_patterns.default.blockArgumentRegExp, function (match2, variable) {
return _this2.parseValue(variable, data, options);

@@ -801,9 +786,10 @@ });

}
return result;
});
}
return src;
},
/**

@@ -819,8 +805,10 @@ * Replaces all evaluations

return source.replace(_patterns2.default.evalBlockRegExp, function (match, expression) {
return source.replace(_patterns.default.evalBlockRegExp, function (match, expression) {
// Replace variables in expression
var expr = expression.replace(_patterns2.default.blockArgumentRegExp, function (match2, variable) {
var expr = expression.replace(_patterns.default.blockArgumentRegExp, function (match2, variable) {
return _this3.parseValue(variable, data, options);
});
var args = _this3.parseBlockArguments(expr, data, options);
return _this3.evalCondition(args.join(' '));

@@ -830,3 +818,2 @@ });

/**

@@ -842,16 +829,16 @@ * Replaces all helpers

return source.replace(_patterns2.default.helperBlockRegExp, function (match, name, argsString) {
return source.replace(_patterns.default.helperBlockRegExp, function (match, name, argsString) {
var args = _this4.parseBlockArguments(argsString, data, options);
if (!_this4.isHelper(name)) {
throw new Error('Helper "' + name + '" does not exist');
}
throw new Error("Helper \"".concat(name, "\" does not exist"));
} // Get the helper value
// Get the helper value
var result = _this4.helpers[name];
// Get the value from a function
var result = _this4.helpers[name]; // Get the value from a function
if (typeof result === 'function') {
result = result.apply(data, args);
}
return typeof result !== 'undefined' && result !== null ? result : '';

@@ -861,3 +848,2 @@ });

/**

@@ -873,11 +859,16 @@ * Replaces partial blocks

return source.replace(_patterns2.default.partialBlockRegExp, function (match, name, paramsString) {
return source.replace(_patterns.default.partialBlockRegExp, function (match, name, paramsString) {
var params = _this5.parseBlockParams(paramsString, data, options);
var context = (0, _extend.extendRecursively)({}, data, params);
var value = _this5.render(name, context, {
html: true,
// fixme "this" should refer to template instance
parent: (0, _extend.extendRecursively)({}, (options || {}).parent, { instance: _this5 }),
parent: (0, _extend.extendRecursively)({}, (options || {}).parent, {
instance: _this5
}),
partial: true
});
return value !== null ? value : '';

@@ -887,3 +878,2 @@ });

/**

@@ -899,14 +889,15 @@ * Replaces variable blocks

return source.replace(_patterns2.default.variableBlockRegExp, function (match, varExpr) {
return source.replace(_patterns.default.variableBlockRegExp, function (match, varExpr) {
var value = _this6.resolvePath(varExpr, data, options);
if (value !== null && typeof value !== 'undefined') {
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
if (_typeof(value) === 'object') {
value = typeof value.toString === 'function' ? value.toString() : value;
} else if (typeof value === 'function') {
var parent = options && options.parent ? options.parent : {};
// todo return parent only as 2nd argument
var parent = options && options.parent ? options.parent : {}; // todo return parent only as 2nd argument
value = value(data, parent.data, parent);
}
}
return value !== null && typeof value !== 'undefined' ? value : '';

@@ -916,3 +907,2 @@ });

/**

@@ -932,3 +922,2 @@ * Replaces variable blocks

/**

@@ -944,4 +933,5 @@ * Replaces with blocks (custom scope)

return source.replace(_patterns2.default.withBlockRegExp, function (match, path, html) {
return source.replace(_patterns.default.withBlockRegExp, function (match, path, html) {
var object = _this7.resolvePath(path, data, options);
var result = '';

@@ -957,2 +947,3 @@

}
return result;

@@ -962,3 +953,2 @@ });

/**

@@ -974,3 +964,3 @@ * Returns the value of a path

var newPath = path;
var value = void 0;
var value;

@@ -981,16 +971,17 @@ if (typeof newPath === 'string' && data !== null && typeof data !== 'undefined') {

return opt.special[newPath];
}
// Check if path is valid
if (!_patterns2.default.contextPathRegExp.test(newPath)) {
} // Check if path is valid
if (!_patterns.default.contextPathRegExp.test(newPath)) {
return null;
}
// Return current context
} // Return current context
if (newPath === 'this') {
return data;
}
} // Find value in context
// Find value in context
var obj = data;
// Access parent data
var obj = data; // Access parent data
if (newPath.indexOf('../') === 0) {

@@ -1010,2 +1001,3 @@ if (opt.parent) {

}
newPath = newPath.substring(3);

@@ -1025,6 +1017,6 @@ } else if (newPath.indexOf('this.') === 0) {

break;
}
} // is Object
// is Object
if (part.length && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
if (part.length && _typeof(obj) === 'object') {
if (part.indexOf('[') !== -1) {

@@ -1050,5 +1042,5 @@ var indexStart = part.indexOf('[');

obj = null;
}
} // Get the result of the function
// Get the result of the function
if (obj !== null && typeof obj === 'function') {

@@ -1062,8 +1054,10 @@ obj = obj.call(data);

}
value = obj;
}
return value;
}
};
exports.default = Kandybars;
var _default = Kandybars;
exports.default = _default;

@@ -6,2 +6,4 @@ "use strict";

});
exports.default = void 0;
/*

@@ -30,5 +32,3 @@ * The MIT License (MIT)

*/
exports.default = {
var _default = {
/**

@@ -39,2 +39,3 @@ * Regexp of a block argument

blockArgumentRegExp: /\b((?:this\.|\.\.\/)?[a-zA-Z_$][a-zA-Z0-9_$]*(?:\.[a-zA-Z0-9_$]+)*)\b(?!["'])/g,
/**

@@ -45,2 +46,3 @@ * Regexp of a comment block

commentBlockRegExp: /{{![^}]+?}}/g,
/**

@@ -51,2 +53,3 @@ * Regexp of an condition block

conditionBlockRegExp: /{{#if ([^}]+)}}((?:(?!{{#if)[\s\S])*?){{\/if}}/g,
/**

@@ -57,2 +60,3 @@ * Regexp of a template context path

contextPathRegExp: /^(?:this\.|\.\.\/)?[a-zA-Z_][a-zA-Z0-9_]*(?:(?:\[[a-zA-Z0-9_]*])?|\.[a-zA-Z_][a-zA-Z0-9_]*)*$/,
/**

@@ -63,2 +67,3 @@ * Regexp of an "each" block

eachBlockRegExp: /{{#each ((?:this\.|\.\.\/)?[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*)}}([\s\S]*?){{\/each}}/g,
/**

@@ -69,2 +74,3 @@ * Regexp of an eval block

evalBlockRegExp: /{{eval ([^}]+)}}/g,
/**

@@ -75,2 +81,3 @@ * Regexp of a helper block

helperBlockRegExp: /{{([a-zA-Z0-9_]+) ([^}]+)}}/g,
/**

@@ -81,2 +88,3 @@ * Regexp of a partial block

partialBlockRegExp: /{{> *([^ }]+)( +[^}]+)*}}/g,
/**

@@ -87,2 +95,3 @@ * Regexp of a template definition

templateRegExp: /<template[^>]*>([\s\S]*?)<\/template>/g,
/**

@@ -93,2 +102,3 @@ * Regexp of a template tag

templateTagsRegExp: /<template[^>]*>|<\/template>/g,
/**

@@ -99,2 +109,3 @@ * Regexp of a variable block

variableBlockRegExp: /{{{?((?:this\.|\.\.\/)?[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*)}}}?/g,
/**

@@ -105,2 +116,3 @@ * Regexp of a "with" block

withBlockRegExp: /{{#with ((?:this\.|\.\.\/)?[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*)}}([\s\S]*?){{\/with}}/g
};
};
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,2 +6,4 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
/*

@@ -30,5 +32,4 @@ * The MIT License (MIT)

*/
var reservedWords = ['abstract', 'arguments', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do', 'double', 'else', 'enum', 'eval', 'export', 'extends', 'false', 'final', 'finally', 'float', 'for', 'function', 'goto', 'if', 'implements', 'import', 'in', 'instanceof', 'int', 'interface', 'let', 'long', 'native', 'new', 'null', 'package', 'private', 'protected', 'public', 'return', 'short', 'static', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'true', 'try', 'typeof', 'let', 'void', 'volatile', 'while', 'with', 'yield'];
exports.default = reservedWords;
var _default = reservedWords;
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,49 +6,26 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /*
* The MIT License (MIT)
*
* Copyright (c) 2018 Karl STEIN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var _extend = require("@jalik/extend");
var _extend = require('@jalik/extend');
var _observer = _interopRequireDefault(require("@jalik/observer"));
var _observer = require('@jalik/observer');
var _kandybars = _interopRequireDefault(require("./kandybars"));
var _observer2 = _interopRequireDefault(_observer);
var _template = _interopRequireDefault(require("./template"));
var _kandybars = require('./kandybars');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _kandybars2 = _interopRequireDefault(_kandybars);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _template = require('./template');
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
var _template2 = _interopRequireDefault(_template);
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var instanceCount = 0;
var partials = {};
var TemplateInstance = function () {
var TemplateInstance =
/*#__PURE__*/
function () {
function TemplateInstance(template, data, options) {

@@ -58,3 +35,2 @@ _classCallCheck(this, TemplateInstance);

instanceCount += 1;
var opt = (0, _extend.extendRecursively)({

@@ -66,6 +42,5 @@ events: {},

rendered: null
}, options);
}, options); // Check template
// Check template
if (!(template instanceof _template2.default)) {
if (!(template instanceof _template.default)) {
throw new TypeError('template is not an instance of Template');

@@ -77,4 +52,4 @@ }

this.data = data;
this.id = 'kbti_' + instanceCount;
this.observer = new _observer2.default(this);
this.id = "kbti_".concat(instanceCount);
this.observer = new _observer.default(this);
this.options = opt;

@@ -86,5 +61,5 @@ this.parent = opt.parent;

partials[this.id] = this;
}
} // Link instance to it's parent
// Link instance to it's parent
if (this.parent && this.parent.instance instanceof TemplateInstance) {

@@ -94,3 +69,2 @@ this.parent.instance.getChildren().push(this);

}
/**

@@ -105,3 +79,3 @@ * Attaches the event to the elements in the template

_createClass(TemplateInstance, [{
key: 'attachEvent',
key: "attachEvent",
value: function attachEvent(event, callback, node) {

@@ -119,5 +93,4 @@ var _this = this;

var target = selector && node.filter(selector);
var htmlNode = void 0;
var htmlNode = void 0; // Check if root node is the target
// Check if root node is the target
if (target && target.length === 1) {

@@ -141,3 +114,2 @@ htmlNode = target;

}
/**

@@ -150,3 +122,3 @@ * Parses all events in the template

}, {
key: 'attachEvents',
key: "attachEvents",
value: function attachEvents(events, node) {

@@ -161,3 +133,2 @@ var keys = Object.keys(events);

}
/**

@@ -169,7 +140,6 @@ * Returns template children

}, {
key: 'getChildren',
key: "getChildren",
value: function getChildren() {
return this.children;
}
/**

@@ -181,7 +151,6 @@ * Returns instance context

}, {
key: 'getContext',
key: "getContext",
value: function getContext() {
return (0, _extend.extendRecursively)({}, this.data, this.template.helpers);
}
/**

@@ -193,7 +162,6 @@ * Returns instance events

}, {
key: 'getEvents',
key: "getEvents",
value: function getEvents() {
return (0, _extend.extendRecursively)({}, this.getTemplate().getEvents(), this.options.events);
}
/**

@@ -205,7 +173,6 @@ * Returns instance helpers

}, {
key: 'getHelpers',
key: "getHelpers",
value: function getHelpers() {
return (0, _extend.extendRecursively)({}, this.getTemplate().getHelpers(), this.options.helpers);
}
/**

@@ -217,7 +184,6 @@ * Returns the template Id

}, {
key: 'getId',
key: "getId",
value: function getId() {
return this.id;
}
/**

@@ -229,7 +195,6 @@ * Returns the template parent

}, {
key: 'getParent',
key: "getParent",
value: function getParent() {
return this.parent && this.parent.instance;
}
/**

@@ -241,7 +206,6 @@ * Returns the template

}, {
key: 'getTemplate',
key: "getTemplate",
value: function getTemplate() {
return this.template;
}
/**

@@ -253,7 +217,6 @@ * Checks if instance has children

}, {
key: 'hasChildren',
key: "hasChildren",
value: function hasChildren() {
return this.children.length > 0;
}
/**

@@ -265,7 +228,6 @@ * Checks if instance is a partial template

}, {
key: 'isPartial',
key: "isPartial",
value: function isPartial() {
return this.options.partial === true;
}
/**

@@ -278,3 +240,3 @@ * Returns a compiled version of the template

}, {
key: 'render',
key: "render",
value: function render(options) {

@@ -288,14 +250,11 @@ var opt = (0, _extend.extendRecursively)({

}, options);
var context = this.getContext();
var template = this.getTemplate();
var source = template.getSource();
var source = template.getSource(); // Generate template
// Generate template
var tpl = _kandybars2.default.replaceAll(source, context, opt);
var tpl = _kandybars.default.replaceAll(source, context, opt);
if (this.isPartial()) {
var partialId = this.getId();
var partialId = this.getId(); // Search first node
// Search first node
var startIndex = tpl.indexOf('<');

@@ -305,5 +264,5 @@ var closeIndex = tpl.indexOf('>', startIndex);

if (startIndex === -1 || closeIndex === -1) {
tpl = '<div data-partial-id="' + partialId + '">' + tpl + '</div>';
tpl = "<div data-partial-id=\"".concat(partialId, "\">").concat(tpl, "</div>");
} else {
tpl = tpl.substr(0, closeIndex) + ' data-partial-id="' + partialId + '"' + tpl.substr(closeIndex);
tpl = "".concat(tpl.substr(0, closeIndex), " data-partial-id=\"").concat(partialId, "\"").concat(tpl.substr(closeIndex));
}

@@ -314,5 +273,4 @@ } else if (!opt.html) {

if (typeof window.jQuery !== 'undefined') {
tpl = window.jQuery(tpl);
tpl = window.jQuery(tpl); // Insert the template in the target
// Insert the template in the target
if (opt.target) {

@@ -325,21 +283,16 @@ window.jQuery(opt.target).html(tpl);

var partialId = node.attr('data-partial-id');
var partial = partials[partialId];
var partial = partials[partialId]; // Overwrite compiled result
// Overwrite compiled result
partial.compiled = window.jQuery(this);
partial.compiled = window.jQuery(this); // Attach events
// Attach events
partial.attachEvents(partial.getEvents(), node);
partial.attachEvents(partial.getEvents(), node); // Execute rendered callback
// Execute rendered callback
partial.rendered();
};
}; // Search partial in root node
// Search partial in root node
tpl.filter('[data-partial-id]').each(processPartial);
// Search partials in child nodes
tpl.find('[data-partial-id]').each(processPartial);
tpl.filter('[data-partial-id]').each(processPartial); // Search partials in child nodes
// Attach events
tpl.find('[data-partial-id]').each(processPartial); // Attach events
this.attachEvents(this.getEvents(), tpl);

@@ -354,5 +307,5 @@ }

}
return tpl;
}
/**

@@ -364,3 +317,3 @@ * Executes rendered callbacks

}, {
key: 'rendered',
key: "rendered",
value: function rendered() {

@@ -371,4 +324,5 @@ if (typeof this.options.rendered === 'function') {

this.getTemplate().rendered.call(this, this.compiled, this.getContext());
}
// Notify listeners
} // Notify listeners
this.observer.notify('rendered', this.compiled, this.getContext());

@@ -381,2 +335,3 @@ }

exports.default = TemplateInstance;
var _default = TemplateInstance;
exports.default = _default;

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,42 +6,21 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _observer = _interopRequireDefault(require("@jalik/observer"));
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /*
* The MIT License (MIT)
*
* Copyright (c) 2018 Karl STEIN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var _templateInstance = _interopRequireDefault(require("./template-instance"));
var _observer = require('@jalik/observer');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _observer2 = _interopRequireDefault(_observer);
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var _templateInstance = require('./template-instance');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _templateInstance2 = _interopRequireDefault(_templateInstance);
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Template = function () {
var Template =
/*#__PURE__*/
function () {
function Template(name, source) {

@@ -53,5 +32,7 @@ _classCallCheck(this, Template);

}
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
throw new Error('Template name "' + name + '" is not valid');
throw new Error("Template name \"".concat(name, "\" is not valid"));
}
if (typeof source !== 'string') {

@@ -64,7 +45,6 @@ throw new Error('Template source must be a string');

this.name = name;
this.observer = new _observer2.default(this);
this.observer = new _observer.default(this);
this.rendered = null;
this.source = source;
}
/**

@@ -79,7 +59,6 @@ * Creates an instance of the template

_createClass(Template, [{
key: 'createInstance',
key: "createInstance",
value: function createInstance(data, options) {
return new _templateInstance2.default(this, data, options);
return new _templateInstance.default(this, data, options);
}
/**

@@ -91,5 +70,5 @@ * Defines events of the template

}, {
key: 'events',
key: "events",
value: function events(_events) {
if (_events !== null && (typeof _events === 'undefined' ? 'undefined' : _typeof(_events)) === 'object') {
if (_events !== null && _typeof(_events) === 'object') {
var keys = Object.keys(_events);

@@ -104,3 +83,2 @@ var keysLength = keys.length;

}
/**

@@ -112,7 +90,6 @@ * Returns template events

}, {
key: 'getEvents',
key: "getEvents",
value: function getEvents() {
return this.events;
}
/**

@@ -124,7 +101,6 @@ * Returns template helpers

}, {
key: 'getHelpers',
key: "getHelpers",
value: function getHelpers() {
return this.helpers;
}
/**

@@ -136,7 +112,6 @@ * Returns template name

}, {
key: 'getName',
key: "getName",
value: function getName() {
return this.name;
}
/**

@@ -148,7 +123,6 @@ * Returns template source

}, {
key: 'getSource',
key: "getSource",
value: function getSource() {
return this.source;
}
/**

@@ -160,5 +134,5 @@ * Defines helpers of the template

}, {
key: 'helpers',
key: "helpers",
value: function helpers(_helpers) {
if (_helpers !== null && (typeof _helpers === 'undefined' ? 'undefined' : _typeof(_helpers)) === 'object') {
if (_helpers !== null && _typeof(_helpers) === 'object') {
var keys = Object.keys(_helpers);

@@ -174,3 +148,3 @@ var keysLength = keys.length;

}, {
key: 'onRendered',
key: "onRendered",
value: function onRendered(listener) {

@@ -184,2 +158,3 @@ this.observer.attach('rendered', listener);

exports.default = Template;
var _default = Template;
exports.default = _default;
{
"name": "kandybars",
"version": "0.9.1",
"version": "0.9.2",
"description": "A template engine for all purposes.",

@@ -26,36 +26,31 @@ "license": "MIT",

"scripts": {
"build": "./node_modules/.bin/gulp build",
"bundle": "npm test && ./node_modules/.bin/webpack -p",
"lint": "./node_modules/.bin/eslint .",
"lint-fix": "./node_modules/.bin/eslint --fix .",
"prepare": "./node_modules/.bin/gulp prepare",
"build": "npx gulp build",
"lint": "npx eslint .",
"lint-fix": "npx eslint --fix .",
"prepare": "npx gulp prepare",
"prepublishOnly": "npm test",
"test": "./node_modules/.bin/jest",
"watch": "./node_modules/.bin/gulp watch"
"test": "npx jest",
"watch": "npx gulp watch"
},
"dependencies": {
"@jalik/extend": "^1.0.2",
"@jalik/observer": "^1.0.3"
"@jalik/extend": "^1.0.3",
"@jalik/observer": "^1.0.5"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"ajv": "^6.5.4",
"babel-core": "^7.0.0-bridge.0",
"del": "^3.0.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jest": "^21.17.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.9.1",
"eslint": "^5.6.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.24.1",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"gulp": "^4.0.0",
"gulp-babel": "^7.0.1",
"gulp-eslint": "^4.0.2",
"gulp-strip-comments": "^2.5.2",
"gulp-watch": "^5.0.0",
"jest": "^23.1.0",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.3"
"gulp-babel": "^8.0.0",
"gulp-eslint": "^5.0.0",
"jest": "^23.6.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc