Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@gabliam/expression): begin expression package
- Loading branch information
Showing
8 changed files
with
511 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[![Build Status][build-image]][build-url] | ||
[![NPM version][npm-image]][npm-url] | ||
|
||
|
||
# Gabliam amqp | ||
|
||
Gabliam plugin for add amqp. | ||
|
||
# License | ||
|
||
MIT | ||
|
||
[build-image]: https://img.shields.io/travis/gabliam/gabliam/master.svg?style=flat-square | ||
[build-url]: https://travis-ci.org/gabliam/gabliam | ||
[npm-image]: https://img.shields.io/npm/v/@gabliam/amqp.svg?style=flat-square | ||
[npm-url]: https://github.com/gabliam/amqp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@gabliam/expression", | ||
"version": "6.1.0", | ||
"description": "expression parser", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"module": "lib/index.js", | ||
"scripts": { | ||
"build": "rimraf lib && tsc -p tsconfig.build.json" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/gabliam/gabliam.git" | ||
}, | ||
"keywords": [ | ||
"amqp", | ||
"gabliam" | ||
], | ||
"author": "David Touzet <dtouzet@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/gabliam/gabliam/issues" | ||
}, | ||
"homepage": "https://github.com/gabliam/gabliam/tree/master/packages/amqp#readme", | ||
"peerDependencies": { | ||
"@gabliam/core": "^6.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/escodegen": "^0.0.6", | ||
"@types/esprima": "^4.0.1", | ||
"@types/node": "^8.0.14" | ||
}, | ||
"dependencies": { | ||
"escodegen": "^1.9.0", | ||
"esprima": "^4.0.0", | ||
"tslib": "^1.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as esprima from 'esprima'; | ||
import { ExpressionStatement } from 'estree'; | ||
import { Expression } from './expression'; | ||
|
||
export class ExpressionParser { | ||
constructor(private context: object = {}) { | ||
} | ||
|
||
parseExpression(input: string) { | ||
const program = esprima.parseScript(input); | ||
const ast = (<ExpressionStatement>program.body[0]).expression; | ||
return new Expression(ast, this.context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Expression as AstExpression } from 'estree'; | ||
import { Parser } from './parser'; | ||
|
||
export class Expression { | ||
private parser: Parser; | ||
|
||
constructor(ast: AstExpression, private context: object = {}) { | ||
this.parser = new Parser(ast); | ||
} | ||
|
||
getValue<T>(vars: object = {}): T | undefined | null { | ||
return this.parser.parse({ | ||
...this.context, | ||
...vars | ||
}); | ||
} | ||
} |
Oops, something went wrong.