Modules@robinpath/validate
validate

@robinpath/validate

0.1.1Node.jsPublic

Validate strings, numbers, and data formats (email, URL, IP, UUID, JSON, etc.)

Validate

Validate strings, numbers, and data formats (email, URL, IP, UUID, JSON, etc.)

Package: @robinpath/validate | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the validate module when you need to:

  • Validate email format -- Use validate.isEmail to perform this operation
  • Validate URL format -- Use validate.isUrl to perform this operation
  • Validate IPv4 address format -- Use validate.isIP to perform this operation
  • Validate UUID format -- Use validate.isUUID to perform this operation
  • Check if a string is a valid date -- Use validate.isDate to perform this operation

Quick Reference

FunctionDescriptionReturns
isEmailValidate email formatTrue if the string is a valid email format
isUrlValidate URL formatTrue if the string is a valid URL
isIPValidate IPv4 address formatTrue if the string is a valid IPv4 address
isUUIDValidate UUID formatTrue if the string is a valid UUID
isDateCheck if a string is a valid dateTrue if the string can be parsed as a valid date
isNumericCheck if a string is numericTrue if the string represents a valid number
isAlphaCheck if a string contains only lettersTrue if the string contains only alphabetic characters
isAlphanumericCheck if a string contains only letters and digitsTrue if the string contains only alphanumeric characters
matchesTest a string against a regular expression patternTrue if the string matches the pattern
minLengthCheck if a string meets a minimum lengthTrue if the string length is >= min
maxLengthCheck if a string does not exceed a maximum lengthTrue if the string length is <= max
inRangeCheck if a number is within a range (inclusive)True if value >= min and value <= max
isJSONCheck if a string is valid JSONTrue if the string can be parsed as valid JSON
isEmptyCheck if a value is empty (null, undefined, empty string, empty array, or empty object)True if the value is considered empty

Functions

isEmail

Validate email format

Module: validate | Returns: boolean -- True if the string is a valid email format

validate.isEmail "user@example.com"
ParameterTypeRequiredDescription
valuestringYesThe string to validate as an email address

isUrl

Validate URL format

Module: validate | Returns: boolean -- True if the string is a valid URL

validate.isUrl "https://example.com"
ParameterTypeRequiredDescription
valuestringYesThe string to validate as a URL

isIP

Validate IPv4 address format

Module: validate | Returns: boolean -- True if the string is a valid IPv4 address

validate.isIP "192.168.1.1"
ParameterTypeRequiredDescription
valuestringYesThe string to validate as an IPv4 address

isUUID

Validate UUID format

Module: validate | Returns: boolean -- True if the string is a valid UUID

validate.isUUID "550e8400-e29b-41d4-a716-446655440000"
ParameterTypeRequiredDescription
valuestringYesThe string to validate as a UUID

isDate

Check if a string is a valid date

Module: validate | Returns: boolean -- True if the string can be parsed as a valid date

validate.isDate "2024-01-15"
ParameterTypeRequiredDescription
valuestringYesThe string to validate as a date

isNumeric

Check if a string is numeric

Module: validate | Returns: boolean -- True if the string represents a valid number

validate.isNumeric "123.45"
ParameterTypeRequiredDescription
valuestringYesThe string to check

isAlpha

Check if a string contains only letters

Module: validate | Returns: boolean -- True if the string contains only alphabetic characters

validate.isAlpha "hello"
ParameterTypeRequiredDescription
valuestringYesThe string to check

isAlphanumeric

Check if a string contains only letters and digits

Module: validate | Returns: boolean -- True if the string contains only alphanumeric characters

validate.isAlphanumeric "hello123"
ParameterTypeRequiredDescription
valuestringYesThe string to check

matches

Test a string against a regular expression pattern

Module: validate | Returns: boolean -- True if the string matches the pattern

validate.matches $str "^\\d{3}$"
ParameterTypeRequiredDescription
valuestringYesThe string to test
patternstringYesThe regular expression pattern
flagsstringNoOptional regex flags (e.g. "i" for case-insensitive)

minLength

Check if a string meets a minimum length

Module: validate | Returns: boolean -- True if the string length is >= min

validate.minLength "hello" 3
ParameterTypeRequiredDescription
valuestringYesThe string to check
minnumberYesThe minimum required length

maxLength

Check if a string does not exceed a maximum length

Module: validate | Returns: boolean -- True if the string length is <= max

validate.maxLength "hi" 5
ParameterTypeRequiredDescription
valuestringYesThe string to check
maxnumberYesThe maximum allowed length

inRange

Check if a number is within a range (inclusive)

Module: validate | Returns: boolean -- True if value >= min and value <= max

validate.inRange 5 1 10
ParameterTypeRequiredDescription
valuenumberYesThe number to check
minnumberYesThe minimum value (inclusive)
maxnumberYesThe maximum value (inclusive)

isJSON

Check if a string is valid JSON

Module: validate | Returns: boolean -- True if the string can be parsed as valid JSON

validate.isJSON '{"a":1}'
ParameterTypeRequiredDescription
valuestringYesThe string to check

isEmpty

Check if a value is empty (null, undefined, empty string, empty array, or empty object)

Module: validate | Returns: boolean -- True if the value is considered empty

validate.isEmpty ""
ParameterTypeRequiredDescription
valueanyYesThe value to check

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Is email and validate result"
do
  set $result as validate.isEmail "user@example.com"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Validate workflow

Chain multiple validate operations together.

@desc "Is email, is url, and more"
do
  set $r_isEmail as validate.isEmail "user@example.com"
  set $r_isUrl as validate.isUrl "https://example.com"
  set $r_isIP as validate.isIP "192.168.1.1"
  print "All operations complete"
enddo

2. Safe isEmail with validation

Check results before proceeding.

@desc "Is email and validate result"
do
  set $result as validate.isEmail "user@example.com"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/validate

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size6.5 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

utilities