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

derby-templates

Package Overview
Dependencies
Maintainers
3
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

derby-templates - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

8

lib/contexts.js

@@ -181,3 +181,9 @@ exports.ContextMeta = ContextMeta;

Context.prototype.get = function() {
return (this.expression) ? this.expression.get(this) : this.controller.model.data;
var value = (this.expression) ?
this.expression.get(this) :
this.controller.model.data;
if (this.item != null) {
return value && value[this.item];
}
return value;
};

@@ -184,0 +190,0 @@

83

lib/expressions.js

@@ -11,2 +11,3 @@ var serializeObject = require('serialize-object');

exports.renderValue = renderValue;
exports.renderTemplate = renderTemplate;
exports.ExpressionMeta = ExpressionMeta;

@@ -55,2 +56,8 @@

function renderValue(value, context) {
return (typeof value !== 'object') ? value :
(value instanceof Template) ? renderTemplate(value, context) :
(Array.isArray(value)) ? renderArray(value, context) :
renderObject(value, context);
}
function renderTemplate(value, context) {
var i = 1000;

@@ -63,2 +70,36 @@ while (value instanceof Template) {

}
function renderArray(array, context) {
for (var i = 0; i < array.length; i++) {
if (hasTemplateProperty(array[i])) {
return renderArrayProperties(array, context);
}
}
return array;
}
function renderObject(object, context) {
return (hasTemplateProperty(object)) ?
renderObjectProperties(object, context) : object;
}
function hasTemplateProperty(object) {
if (!object) return false;
if (object.constructor !== Object) return false;
for (var key in object) {
if (object[key] instanceof Template) return true;
}
return false;
}
function renderArrayProperties(array, context) {
var out = new Array(array.length);
for (var i = 0; i < array.length; i++) {
out[i] = renderValue(array[i], context);
}
return out;
}
function renderObjectProperties(object, context) {
var out = {};
for (var key in object) {
out[key] = renderValue(object[key], context);
}
return out;
}

@@ -124,11 +165,2 @@ function ExpressionMeta(source, blockType, isEnd, as, keyAs, unescaped, bindType, valueType) {

};
Expression.prototype._getPatch = function(context, value) {
if (this.meta && this.meta.blockType) {
value = renderValue(value, context);
}
if (context && context.expression === this && context.item != null) {
value = value && value[context.item];
}
return (value instanceof Expression) ? value.get(context) : value;
};
Expression.prototype._resolvePatch = function(context, segments) {

@@ -159,4 +191,4 @@ return (context && context.expression === this && context.item != null) ?

};
LiteralExpression.prototype.get = function(context) {
return this._getPatch(context, this.value);
LiteralExpression.prototype.get = function() {
return this.value;
};

@@ -179,4 +211,3 @@

if (!context.controller) return;
var value = lookup(this.segments, context.controller.model.data);
return this._getPatch(context, value);
return lookup(this.segments, context.controller.model.data);
};

@@ -215,6 +246,6 @@ PathExpression.prototype.resolve = function(context) {

if (this.segments.length) {
value = renderValue(value, relativeContext);
value = renderTemplate(value, relativeContext);
value = lookup(this.segments, value);
}
return this._getPatch(context, value);
return value;
};

@@ -258,6 +289,6 @@ RelativePathExpression.prototype.resolve = function(context) {

if (this.segments.length) {
value = renderValue(value, aliasContext);
value = renderTemplate(value, aliasContext);
value = lookup(this.segments, value);
}
return this._getPatch(context, value);
return value;
};

@@ -308,6 +339,6 @@ AliasPathExpression.prototype.resolve = function(context) {

if (this.segments.length) {
value = renderValue(value, attributeContext);
value = renderTemplate(value, attributeContext);
value = lookup(this.segments, value);
}
return this._getPatch(context, value);
return value;
};

@@ -355,4 +386,3 @@ AttributePathExpression.prototype.resolve = function(context) {

var base = before[inside];
var value = (this.afterSegments) ? lookup(this.afterSegments, base) : base;
return this._getPatch(context, value);
return (this.afterSegments) ? lookup(this.afterSegments, base) : base;
};

@@ -397,4 +427,3 @@ BracketsExpression.prototype.resolve = function(context) {

}
var out = (this.afterSegments) ? lookup(this.afterSegments, items) : items;
return this._getPatch(context, out);
return (this.afterSegments) ? lookup(this.afterSegments, items) : items;
};

@@ -428,4 +457,3 @@ ArrayExpression.prototype.dependencies = function(context, options) {

}
var out = (this.afterSegments) ? lookup(this.afterSegments, object) : object;
return this._getPatch(context, out);
return (this.afterSegments) ? lookup(this.afterSegments, object) : object;
};

@@ -460,6 +488,3 @@ ObjectExpression.prototype.dependencies = function(context, options) {

// Lookup property underneath computed value if needed
if (this.afterSegments) {
value = lookup(this.afterSegments, value);
}
return this._getPatch(context, value);
return (this.afterSegments) ? lookup(this.afterSegments, value) : value;
};

@@ -466,0 +491,0 @@ FnExpression.prototype.apply = function(context, extraInputs) {

{
"name": "derby-templates",
"version": "0.7.0",
"version": "0.7.1",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

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