Data Validation and Sanitization
npm install @fireflysemantics/validatortsA typescript library of validators and sanitizers based on validator.js.

The Typedoc contains documentation for all the validators and sanitizers.
```
npm i -S @fireflysemantics/validatorts tslib
``
import { isPort } from '@fireflysemantics/validatorts';
console.log(isPort('4200').value) //Logs true
console.log(isPort('70000').value); //Logs false
console.log(isPort('4200').error); //Logs undefined
In the event of an error the Result.value property will be undefined and both the message and error properties will be set, thus we can handle and error like this:
``
if (isPort(4200).error) {
console.log(isPort(4200).value); //Logs undefined
console.log(isPort(4200).message); //The target argument 4200 is not a string.
}
To see what types of errors can occur see the Typedoc for the API being used.
For more details on the error handling design and approach see Typescript Exception Free Function Error Handling.
Each validator and sanitizer returns a Result instance with this interface:
``
/**
* The result of validation and sanitation calls.
*/
export class Result
public message?:string
constructor(
public value: E | undefined,
public error?: MessageFunctionType,
public parameters?: string[]
) {
if (error) {
this.message = this.error!(parameters)
}
}
}
Running unit tests
Run the Jest Tests for ValidatorTS
npm tValidatorTS Workspace
This project was generated with Angular CLI version 12.1.2.
Generate Typedoc
npm run docTypedoc will be contained in the
doc folder of the root directory.
Supported Package Formats
The library is built with the Angular Package Format. It therefore supports all these package formats (As can be seen in the provided
package.json`) and has integrated typescript definitions:- "main": "bundles/fireflysemantics-validatorts.umd.js",
- "module": "fesm5/fireflysemantics-validatorts.js",
- "es2015": "fesm2015/fireflysemantics-validatorts.js",
- "esm5": "esm5/fireflysemantics-validatorts.js",
- "esm2015": "esm2015/fireflysemantics-validatorts.js",
- "fesm5": "fesm5/fireflysemantics-validatorts.js",
- "fesm2015": "fesm2015/fireflysemantics-validatorts.js",
- "typings": "fireflysemantics-validatorts.d.ts",