Validator

The @liskhq/lisk-validator package is a wrapper of validation packages. It includes custom validations utilities related to the Lisk Protocol.

Installation

npm install @liskhq/lisk-validator

Update

To perform an upgrade, execute the following command:

npm update @liskhq/lisk-validator

Usage

const validator = require('@liskhq/lisk-validator');

console.log(validator.MAX_SINT64) //9223372036854775807n

Constants

MAX_SINT32: 2147483647,
MIN_SINT32: -2147483647,
MAX_UINT32: 4294967295,
MAX_UINT64: 18446744073709551615n,
MAX_SINT64: 9223372036854775807n,
MIN_SINT64: -9223372036854775808n

Validation methods

isBoolean

Checks if a given input is of type boolean.

Syntax

isBoolean(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is of type boolean, false otherwise.

isBytes

Checks if a given input is a Buffer.

Syntax

isBytes(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is of type Buffer, false otherwise.

isCsv

Checks, if a given input is data in CSV format.

Syntax

isCsv(data)

Parameters

data(string): String to be checked.

Return value

boolean: true if the provided input is in CSV format, false otherwise.

isEncryptedPassphrase

Checks if a given input is an encrypted passphrase.

Syntax

isEncryptedPassphrase(data)

Parameters

data(string): String to be checked.

Return value

boolean: true if the provided data is an encrypted passphrase, false otherwise.

isHexString

Checks if a given input is a hex string.

Syntax

isHexString(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is a hex string, false otherwise.

isIP

Checks if a given string is an IP.

Syntax

isIP(data)

Parameters

data(string): String to be checked.

Return value

boolean: true if the provided data is an IP, false otherwise.

isIPV4

Checks if a given string is an IPv4.

Syntax

isIPV4(data)

Parameters

data(string): String to be checked.

Return value

boolean: true if the provided data is an IPv4, false otherwise.

isIPV6

Checks if a given string is an IPv6.

Syntax

isIPV6(data)

Parameters

data(string): String to be checked.

Return value

boolean: true if the provided data is an IPv6, false otherwise.

isNumberString

Checks if a given input is a number string.

Syntax

isNumberString(num)

Parameters

num: Data to be checked.

Return value

boolean: true if the provided data is a number string, false otherwise.

isPort

Checks if a given string is a port.

Syntax

isPort(port)

Parameters

port(string): String to be checked.

Return value

boolean: true if the provided data is a port, false otherwise.

isProtocolString

Checks if a given string is a protocol.

Syntax

isProtocolString(data)

Parameters

data(string): String to be checked.

Return value

boolean: true if the provided data is a protocol string, false otherwise.

isRangedSemVer

Checks if a given input is a ranged SemVer version.

Syntax

isRangedSemVer(version)

Parameters

version(string): String to be checked.

Return value

boolean: true if the provided data is a valid SemVer version string, false otherwise.

isSInt32

Checks if a given input is of type SInt32.

Syntax

isSInt32(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is of type sint32, false otherwise.

isSInt64

Checks if a given input is of type SInt64.

Syntax

isSInt64(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is of type sint64, false otherwise.

isSemVer

Checks if a given input is a SemVer version.

Syntax

isSemVer(version)

Parameters

version(string): String to be checked.

Return value

boolean: true if the provided data is a SemVer version, false otherwise.

isString

Checks if a given input is of type string.

Syntax

isString(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is of type string, false otherwise.

isStringEndsWith

Checks if a string ends with a given list of suffixes.

Syntax

isStringEndsWith(target,suffixes)

Parameters

  1. target(string): String to be checked.

  2. suffixes(string[]): Suffixes to be checked.

Return value

boolean: true if the provided string ends with one of the suffixes, false otherwise.

isUInt32

Checks if a given input is of type UInt32.

Syntax

isUInt32(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is of type uint32, false otherwise.

isUInt64

Checks if a given input is of type UInt64.

Syntax

isUInt64(data)

Parameters

data: Data to be checked.

Return value

boolean: true if the provided data is of type uint64, false otherwise.

isValidInteger

Checks if a given input is a valid integer.

Syntax

isValidInteger(num)

Parameters

num: Data to be checked.

Return value

boolean: true if the provided data is of type integer, false otherwise.

isLessThanRangedVersion

isGreaterThanRangedVersion

isVersionMatch