Updated Version

There’s an updated version of this article here:

Scenario

We have a number and a string and we want to format both to 2 decimal places:

var num1: any = 213.73145;
var num2: any = '213.73145';

Approach

/**
* Round the number.
* @param num The number
* @param precision The precision…

Image by Domingo Trejo from Pixabay

Scenario

We have a PurchaseOrder class that has been annotated with Firefly Semantics Validator decorators.

Now we want to learn how to use the Firefly Semantics ValidatorAPI

To validate:

  • A single property
  • A single PurchaseOrder instance.
  • Multiple PurchaseOder instances.

Approach

Create a new PurchaseOrder instance:

const po: PurchaseOrder = new PurchaseOrder(
{…

Image by Eelffica from Pixabay

Scenario

We have PurchaseOrderDTO decorated with Firefly Semantics Validator decorators.

The instances are coming in over the wire as described here.

We wish to construct PurchaseOrder instances using the PurchaseOrderDTO instances and then validate the following:

  • The quantity is an integer
  • Both the purchaseDate and the receiptDate are Date instances.
  • The…

Image by Gerhard G. from Pixabay

Updated Version

There’s an updated version of this article here:

Scenario

We are receiving data transfer object instances with a PurchaseOrderDTO type and we need to validate them using Firefly Semantics Validator:

Approach

The PurchaseOrderDTO has been annotated with Firefly Semantics Validator validation annotations as follows:

We will create an instance an validate…

Scenario

For our prototyping work we want a Typescript starter project preconfigured with Jest, Typedoc, and NPM Workflow Scripts.

Cloning it like this creates the project <project_name>:

git clone git@github.com:fireflysemantics/typescript-starter.git <project_name>

This is the final repository in case you want to get right to it:

Approach

First create a new Node project:

Image by Jimmy Lau from Pixabay

Scenario

We have an array of elements [1,2,'a'] , and we want to see whether all of the elements in the array are numbers.

Approach

This approach uses:

@fireflysemantics/validatorts to check whether the array element is a number:

let arr: any[] = [1, 2, 'a'];function allNumbersPredicate(v: any, index: number, array: any[]):boolean…

Ole Ersoy

Founder of Firefly Semantics Corporation

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store