et-exp-sdk
v1.0.5
Published
Evaluate the User Expression
Downloads
1
Readme
et-nd-exp-sdk
This SDK comes bundled with a range of methods that are useful in parsing and evaluating the expressions of the following kind:
- numeric operations
- date validation
- time expressions
- financial expressions
- loop and logical expression
- sentence expression
Table of Contents
Getting Started
Installation
$ npm install et-nd-exp-sdk
Initialization
Initialize the module before accessing its methods. (Note: host and port values must be valid.)
// @ts-ignore
const sdk = require("et-nd-epr-sdk");
const opts = {
host: "localhost",
port: 9999,
basePath: ""
}
const etExprSDK = sdk.init(opts);
APIs
Class: EvalSdkCore
Methods
init(host: string, port: number, basePath: string): Promise<EvalSdkCore>
init()
method initializes and returns an instance of the class EvalSdkCore
| Name | Type | Required | Default | Description | |:-----------|:----------|:---------|:--------|:-----------------------------------------------------| | opts.host | string | true | -- | The host url of the end point, ex: http://api-gateway/| | opts.port | number | false | 80 | usually 80, must be empty if need to use host URL as it is| | opts.basePath | string | false | "" | could be empty as well |
Example
// @ts-ignore
const sdk = require("et-nd-epr-sdk");
const etExprSDK = sdk.init("localhost", 9999, "");
evaluateExpression(expression: string): Promise<string>
|Name|Type|Required|Default|Description| |:---|:---|:---|:---|:---| |expression|string|true|--|Expression to be evaluated.|
Example
etExprSDK.evaluateExpression("4==2") // returns false
pmt(interestRate: number, loanTerm: number, loanAmount: number): Promise<string>
This method calculates the repayment amount based on the given loan amount, interest rate, and loan term.
|Name|Type|Required|Default|Description| |:---|:---|:---|:---|:---| |interestRate|number|true|--|interestRate -- value that represents monthly interestRate, e.g. 5/100/12| |loanTerm|number|true|--|Total number of month. e.g., 60 | |loanAmount|number|true|--|The principal amount offered as loan amount. e.g., 100000|
Example
etExprSDK.pmt(5/100/12, 5 * 12, 100000) // returns 1887
duration(dateExpr: string): Promise<string>
This method calculates the duration lapsed between the start date and end date in years months days pattern.
|Name|Type|Required|Default|Description| |:---|:---|:---|:---|:---| |dateExpr|string|true|--|A string with date expression in DDMMYYYY, e.g., "21-11-2022 - 21-11-1960", "21/11/2022 - 21/11/1960", "21.11.2022 - 21.11.1960" |
Example
etExprSDK.duration("21-11-2022 - 21-11-1960") // returns 62 years, 0 month, 0 day