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 {
console.log(`is number ${isNumber(v).value}`);
return isNumber(v).value;
}
console.log(`All numbers:? ${arr.every(allNumbers)}`);

Demo

Image by Pexels from Pixabay

Scenario

We have a RANGE_DEFAULT_OPTIONS object:

const RANGE_DEFAULT_OPTIONS = { min: 0, max: 100 }

And we want to use the defaults, unless the API overrides them:

export function range(value:number, options:any) {
...
}

Approach

options = { ...RANGE_DEFAULT_OPTIONS, ...options }

Demo

Image by vujicivana from Pixabay

Updated Article

There’s an updated version of this article here:

Scenario

In this article:

We implemented the median function per the illustration of the method used to calculate it.

Here we will be adding error handling without using exceptions.

Approach

Error Function Type

Error strings will be created by functions that have the signature:

export type MessageFunctionType…

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