Skip to content

Commit 826da7c

Browse files
committed
v.0.0.3.alpha
1 parent 5b248a3 commit 826da7c

File tree

5 files changed

+88
-81
lines changed

5 files changed

+88
-81
lines changed

expression-utils.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
var ExpressionUtils = (function () {
4+
function ExpressionUtils(_defaultColumnSeparator) {
5+
if (_defaultColumnSeparator === void 0) { _defaultColumnSeparator = "_"; }
6+
this._defaultColumnSeparator = _defaultColumnSeparator;
7+
}
8+
ExpressionUtils.prototype.getValueByExpression = function (instance, expression) {
9+
return expression(instance);
10+
};
11+
ExpressionUtils.prototype.getValueByProperties = function (instance, properties) {
12+
var _this = this;
13+
var result = instance;
14+
properties.forEach(function (property) {
15+
result = _this.getValue(result, property);
16+
});
17+
return result;
18+
};
19+
ExpressionUtils.prototype.getValue = function (instance, property) {
20+
if (instance) {
21+
return instance[property];
22+
}
23+
return void 0;
24+
};
25+
ExpressionUtils.prototype.getColumnByExpression = function (expression) {
26+
return this.getColumnByProperties(this.getPropertiesByExpression(expression));
27+
};
28+
ExpressionUtils.prototype.getColumnByProperties = function (properties) {
29+
return properties.join(this._defaultColumnSeparator);
30+
};
31+
ExpressionUtils.prototype.getPropertiesByExpression = function (expression) {
32+
var strAfterReturn = expression.toString().split("return")[1].trim();
33+
if (!strAfterReturn) {
34+
strAfterReturn = expression.toString().split("{")[1].trim();
35+
}
36+
var strBeforeSemicon = strAfterReturn.split(" ")[0].split(";")[0];
37+
return this.getPropertiesByExpressionString(strBeforeSemicon);
38+
};
39+
ExpressionUtils.prototype.getPropertiesByExpressionString = function (expression) {
40+
var propertiesReferences = expression.split(".");
41+
if (propertiesReferences.length)
42+
propertiesReferences.shift(); // remove alias
43+
return propertiesReferences;
44+
};
45+
ExpressionUtils.prototype.getColumnByLambdaExpression = function (expression) {
46+
var propertiesMetadada = this.getPropertiesByLambdaExpression(expression);
47+
return {
48+
columnLeft: this.getColumnByProperties(propertiesMetadada.propertiesLeft),
49+
operator: propertiesMetadada.operator,
50+
columnRight: this.getColumnByProperties(propertiesMetadada.propertiesRight)
51+
};
52+
};
53+
ExpressionUtils.prototype.getPropertiesByLambdaExpression = function (expression) {
54+
var expressionMetadada = this.getExpressionByLambdaExpression(expression);
55+
return {
56+
propertiesLeft: this.getPropertiesByExpressionString(expressionMetadada.expressionLeft),
57+
operator: expressionMetadada.operator,
58+
propertiesRight: this.getPropertiesByExpressionString(expressionMetadada.expressionRight)
59+
};
60+
};
61+
ExpressionUtils.prototype.getExpressionByLambdaExpression = function (expression) {
62+
var strAfterReturn = expression.toString().split("return")[1].trim();
63+
if (!strAfterReturn) {
64+
strAfterReturn = expression.toString().split("{")[1].trim();
65+
}
66+
var strExpression = strAfterReturn.split(";")[0].split(" ");
67+
if (strExpression.length != 3) {
68+
throw "Lambda expression '" + expression.toString() + "' not supported! Use simple expression with '{expressionLeft} {operador} {expressionRight}'";
69+
}
70+
return {
71+
expressionLeft: strExpression[0],
72+
operator: strExpression[1],
73+
expressionRight: strExpression[2]
74+
};
75+
};
76+
return ExpressionUtils;
77+
}());
78+
exports.ExpressionUtils = ExpressionUtils;

index.js

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,6 @@
11
"use strict";
2+
function __export(m) {
3+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4+
}
25
Object.defineProperty(exports, "__esModule", { value: true });
3-
var ExpressionUtils = (function () {
4-
function ExpressionUtils(_defaultColumnSeparator) {
5-
if (_defaultColumnSeparator === void 0) { _defaultColumnSeparator = "_"; }
6-
this._defaultColumnSeparator = _defaultColumnSeparator;
7-
}
8-
ExpressionUtils.prototype.getValueByExpression = function (instance, expression) {
9-
return expression(instance);
10-
};
11-
ExpressionUtils.prototype.getValueByProperties = function (instance, properties) {
12-
var _this = this;
13-
var result = instance;
14-
properties.forEach(function (property) {
15-
result = _this.getValue(result, property);
16-
});
17-
return result;
18-
};
19-
ExpressionUtils.prototype.getValue = function (instance, property) {
20-
if (instance) {
21-
return instance[property];
22-
}
23-
return void 0;
24-
};
25-
ExpressionUtils.prototype.getColumnByExpression = function (expression) {
26-
return this.getColumnByProperties(this.getPropertiesByExpression(expression));
27-
};
28-
ExpressionUtils.prototype.getColumnByProperties = function (properties) {
29-
return properties.join(this._defaultColumnSeparator);
30-
};
31-
ExpressionUtils.prototype.getPropertiesByExpression = function (expression) {
32-
var strAfterReturn = expression.toString().split("return")[1].trim();
33-
if (!strAfterReturn) {
34-
strAfterReturn = expression.toString().split("{")[1].trim();
35-
}
36-
var strBeforeSemicon = strAfterReturn.split(" ")[0].split(";")[0];
37-
return this.getPropertiesByExpressionString(strBeforeSemicon);
38-
};
39-
ExpressionUtils.prototype.getPropertiesByExpressionString = function (expression) {
40-
var propertiesReferences = expression.split(".");
41-
if (propertiesReferences.length)
42-
propertiesReferences.shift(); // remove alias
43-
return propertiesReferences;
44-
};
45-
ExpressionUtils.prototype.getColumnByLambdaExpression = function (expression) {
46-
var propertiesMetadada = this.getPropertiesByLambdaExpression(expression);
47-
return {
48-
columnLeft: this.getColumnByProperties(propertiesMetadada.propertiesLeft),
49-
operator: propertiesMetadada.operator,
50-
columnRight: this.getColumnByProperties(propertiesMetadada.propertiesRight)
51-
};
52-
};
53-
ExpressionUtils.prototype.getPropertiesByLambdaExpression = function (expression) {
54-
var expressionMetadada = this.getExpressionByLambdaExpression(expression);
55-
return {
56-
propertiesLeft: this.getPropertiesByExpressionString(expressionMetadada.expressionLeft),
57-
operator: expressionMetadada.operator,
58-
propertiesRight: this.getPropertiesByExpressionString(expressionMetadada.expressionRight)
59-
};
60-
};
61-
ExpressionUtils.prototype.getExpressionByLambdaExpression = function (expression) {
62-
var strAfterReturn = expression.toString().split("return")[1].trim();
63-
if (!strAfterReturn) {
64-
strAfterReturn = expression.toString().split("{")[1].trim();
65-
}
66-
var strExpression = strAfterReturn.split(";")[0].split(" ");
67-
if (strExpression.length != 3) {
68-
throw "Lambda expression '" + expression.toString() + "' not supported! Use simple expression with '{expressionLeft} {operador} {expressionRight}'";
69-
}
70-
return {
71-
expressionLeft: strExpression[0],
72-
operator: strExpression[1],
73-
expressionRight: strExpression[2]
74-
};
75-
};
76-
return ExpressionUtils;
77-
}());
78-
exports.ExpressionUtils = ExpressionUtils;
6+
__export(require("./expression-utils"));

metadatas.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
{
22
"name": "lambda-expression",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "Utility to analyze function (js) and arrow functions (ts), and create metadata of expressions, the initial scope is that it seeks to solve simple expressions. And later advance to encompass complex expressions.",
5-
"main": "./dist/index.js",
6-
"types": "./dist/index.d.ts",
5+
"main": "index.js",
76
"scripts": {
8-
"run": "ts-node ./src/index.ts",
9-
"prepublishOnly": "tsc -p ./ --outDir dist/",
107
"test": "echo \"Error: no test specified\" && exit 1"
118
},
129
"keywords": [

types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

0 commit comments

Comments
 (0)