CSML Reference
  • Introduction
  • Installing CSML
  • Sending and Receiving Messages
    • Message Payloads
    • Custom Components
  • The Event
  • Memory
    • Using Variables in Messages
    • Temporary and Long-Term variables
    • Global variables
  • Navigating in a CSML Bot
  • Conditional Logic
  • External Code Execution
  • Native CSML Functions
  • Value Types
  • Automatic Type Inference
  • 📑CSML Studio Documentation
  • Standard Library
    • Keywords
    • Built-in Functions
    • HTTP Client
    • SMTP Client
    • Crypto Utilities
      • JWT
      • Hash, HMAC
      • Base64, Hex
    • String methods
    • Array methods
    • Object methods
    • Number methods
    • Generic methods
Powered by GitBook
On this page
  • .type_of()
  • .to_string()
  • .is_number()
  • .is_int()
  • .is_float()
  • .is_error(), .get_info()

Was this helpful?

Edit on Git
Export as PDF
  1. Standard Library

Generic methods

The following methods are common to all CSML primitive types.

.type_of()

Return the type of the target value (string, array, object, float, boolean, int, null)

any_value.type_of() => String

.to_string()

Return the target value formatted as a string.

any_value.to_string() => String

.is_number()

Check if a variable can be interpreted as a number (float or int)

string.is_number() => boolean

// example
do var_int = "42"
say var_int.is_number() // true

do var_float = "42.42"
say var_int.is_number() // true

do obj = {"toto": "tutu"}
say obj.is_number() // false

.is_int()

Check if the variable can be interpreted as an int

string.is_int() => boolean

// example
do var_int = "42"
say var_int.is_number() // true

do var_float = 42.42
say var_int.is_number() // false

.is_float()

Check if the variable can be interpreted as an float

string.is_float() => boolean

// example
do var_int = 42
say var_int.is_number() // false

do var_float = 42.42
say var_int.is_number() // true

.is_error(), .get_info()

Some functions may resolve to an error due to a faulty user input, an unreachable API, or some other bug in the code. You can check the result of such functions call (like HTTP() or App()) with .is_error(), and get more information with .get_info().

  do x = HTTP("https://somewhere.com/does-not-exist").send()

  if (x.is_error()) {
    // get info a description of the error
    debug "{{x.get_info()}}"

    // try something else or ask again the user for input!
  }

PreviousNumber methods

Last updated 3 years ago

Was this helpful?