-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
131 additions
and
134 deletions.
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
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ let context = { | |
times: 3 | ||
}; | ||
let expression = { | ||
user: '[email protected]' | ||
user: '[email protected]', | ||
}; | ||
run(expression, context); | ||
expression = { | ||
|
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ let context: ExpressionContext = { | |
}; | ||
|
||
let expression: Expression = { | ||
user: '[email protected]' | ||
user: '[email protected]', | ||
}; | ||
|
||
run(expression, 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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const functionsFactory_1 = require("./functionsFactory"); | ||
const index_1 = require("./../../dist/index"); | ||
const dist_1 = require("../../dist"); | ||
exports.evaluate = (expression, context) => { | ||
return index_1.evaluate(expression, context, functionsFactory_1.functionsTable); | ||
return dist_1.evaluate(expression, context, functionsFactory_1.functionsTable); | ||
}; |
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import { FuncFactory } from "../functionsFactory"; | ||
export declare const factory: FuncFactory; | ||
export declare const counterFunc: (maxCount: number, context: { | ||
times: number; | ||
}) => boolean; |
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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const desc = { | ||
name: 'maxCount', | ||
evaluate: (maxCount, context) => { | ||
return context.times < maxCount; | ||
}, | ||
}; | ||
exports.factory = () => { | ||
return desc; | ||
exports.counterFunc = (maxCount, context) => { | ||
return context.times < maxCount; | ||
}; |
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 |
---|---|---|
@@ -1,14 +1,6 @@ | ||
'use strict'; | ||
|
||
import {FuncFactory, FunctionDescription} from "../functionsFactory"; | ||
|
||
const desc = { | ||
name: 'maxCount', | ||
evaluate: (maxCount: number, context: { times: number }): boolean => { | ||
return context.times < maxCount; | ||
}, | ||
export const counterFunc = (maxCount: number, context: { times: number }): boolean => { | ||
return context.times < maxCount; | ||
}; | ||
|
||
export const factory: FuncFactory = (): FunctionDescription => { | ||
return desc; | ||
}; |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import { FuncFactory } from "../functionsFactory"; | ||
export declare const factory: FuncFactory; | ||
export declare const userFunc: (user: string, context: { | ||
userId: string; | ||
}) => boolean; |
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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const desc = { | ||
name: 'user', | ||
evaluate: (user, context) => { | ||
return context.userId === user; | ||
}, | ||
}; | ||
exports.factory = () => { | ||
return desc; | ||
exports.userFunc = (user, context) => { | ||
return context.userId === user; | ||
}; |
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 |
---|---|---|
@@ -1,14 +1,6 @@ | ||
'use strict'; | ||
|
||
import {FuncFactory, FunctionDescription} from "../functionsFactory"; | ||
|
||
const desc = { | ||
name: 'user', | ||
evaluate: (user: string, context: { userId: string }): boolean => { | ||
return context.userId === user; | ||
}, | ||
export const userFunc = (user: string, context: { userId: string }): boolean => { | ||
return context.userId === user; | ||
}; | ||
|
||
export const factory: FuncFactory = (): FunctionDescription => { | ||
return desc; | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,4 @@ | ||
import { Func, FunctionsTable } from "../../dist"; | ||
import { FunctionsTable } from "../../dist"; | ||
import { ExpressionContext } from "./evaluator"; | ||
export interface FunctionDescription { | ||
name: string; | ||
evaluate: Func<ExpressionContext>; | ||
} | ||
export declare type FuncFactory = () => FunctionDescription; | ||
declare const functionsTable: FunctionsTable<ExpressionContext>; | ||
export { functionsTable }; |
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
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 |
---|---|---|
@@ -1,27 +1,14 @@ | ||
'use strict'; | ||
|
||
import {Func, FunctionsTable} from "../../dist"; | ||
import {FunctionsTable} from "../../dist"; | ||
import {ExpressionContext} from "./evaluator"; | ||
import {factory as userFuncFactory} from './functions/userFunc'; | ||
import {factory as counterFuncFactory} from './functions/counterFunc'; | ||
import {userFunc} from './functions/userFunc'; | ||
import {counterFunc} from './functions/counterFunc'; | ||
|
||
export interface FunctionDescription { | ||
name: string; | ||
evaluate: Func<ExpressionContext>; | ||
} | ||
|
||
export type FuncFactory = () => FunctionDescription; | ||
|
||
const functionsTable: FunctionsTable<ExpressionContext> = {}; | ||
|
||
const _addFunction = (description: FunctionDescription) : void => { | ||
if (functionsTable[description.name]) { | ||
throw new Error(`Function with name ${description.name} already exists`); | ||
} | ||
functionsTable[description.name] = description.evaluate; | ||
const functionsTable: FunctionsTable<ExpressionContext> = { | ||
user: userFunc, | ||
maxCount: counterFunc, | ||
}; | ||
|
||
_addFunction(userFuncFactory()); | ||
_addFunction(counterFuncFactory()); | ||
|
||
export { functionsTable }; | ||
export {functionsTable}; |
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
Oops, something went wrong.