1.0.0 • Published 1 year ago

som-exp-sdk1 v1.0.0

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
1 year ago

et-nd-exp-sdk

NPM version NPM downloads

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

  1. Getting Started
  2. Installation
  3. Initialization
  4. APIs
    1. Class: EvalSdkCore
    2. Methods
    3. init(host: string, port?: number, basePath?: string): EvalSdkCore
    4. Example
    5. evaluateExpression(expression: string): Promise
    6. Example
  5. Release Notes & Breaking Changes
  6. License
  7. Contributing

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

NameTypeRequiredDefaultDescription
opts.hoststringtrue--The host url of the end point, ex: http://api-gateway/
opts.portnumberfalse80usually 80, must be empty if need to use host URL as it is
opts.basePathstringfalse""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>

NameTypeRequiredDefaultDescription
expressionstringtrue--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.

NameTypeRequiredDefaultDescription
interestRatenumbertrue--interestRate -- value that represents monthly interestRate, e.g. 5/100/12
loanTermnumbertrue--Total number of month. e.g., 60
loanAmountnumbertrue--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.

NameTypeRequiredDefaultDescription
dateExprstringtrue--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

Release Notes & Breaking Changes

License

Contributing