Como podemos ajudar?

02. Referências técnicas (Biblioteca) para DEVs
11 min
Criado por Humanz em 03/06/2022 12:34
Atualizado por MLMC em 10/08/2022 15:44

 

 
Lembrando que as Expressions da biblioteca podem ser realizadas de diferentes formas e em diferentes momentos: como valor de variável, após uma chamada de API, após Webhook, como primeira validação, como segunda, em branchs, entre outros!

Expressions + Referências

Básico

Problema Expression
Comparar valores de uma variável (resposta igual a sim)
resposta == 'sim'
Validar variável maior que (resposta maior que 3)
resposta > 3
Validar variável maior ou igual que (resposta maior ou igual a 3)
resposta >= 3
Validar variável em intervalo de valores (resposta entre 1 e 3)
resposta >= 1 and resposta <= 3
Comparar variável diferente de valor (resposta diferente de sim)
resposta != 'sim'
Validar variável menor ou igual (resposta menor que 5)
resposta < 5

String

Problema
Expression
Verificar se duas strings são exatamente iguais
#string.equals(msg, 'sim')
Verificar se duas strings são exatamente iguais, ignorando diferenças entre maiúsculas e minúsculas
#string.equalsIgnoreCase(msg, 'sim')
Verificar se uma string é vazia ou só contém espaços
#string.isBlank(msg)
Verificar se uma string começa por um prefixo
#string.startsWith(msg,'1.')
Verificar se uma string termina por um sufixo
#string.endsWith(msg,'menu')
Verificar se uma string está dentro de outra
#string.contains(msg,'menu')
Substituir uma parte de uma string por outra
#string.replace(msg,'menu','1')
Remover espaços em branco do começo e do final de uma string
#string.trim(msg)
Remover espaços em branco que estão 'sobrando'
#string.normalizeSpace(msg)
Padronizar o tamanho de uma string, inserindo espaços à esquerda
#string.leftPad(msg,40)
Padronizar o tamanho de uma string, inserindo espaços à direita
#string.rightPad(msg,40)
Abreviar uma string para caber em um tamanho máximo
#string.abbreviate(msg, 20)
Operations on string that are null safe.
 
  • IsEmpty/IsBlank - checks if a String contains text
  • Trim/Strip - removes leading and trailing whitespace
  • Equals/Compare - compares two strings null-safe
  • startsWith - check if a String starts with a prefix null-safe
  • endsWith - check if a String ends with a suffix null-safe
  • IndexOf/LastIndexOf/Contains - null-safe index-of checks
  • IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
  • ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these characters
  • Substring/Left/Right/Mid - null-safe substring extractions
  • SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
  • Split/Join - splits a String into an array of substrings and vice versa
  • Remove/Delete - removes part of a String
  • Replace/Overlay - Searches a String and replaces one String with another
  • Chomp/Chop - removes the last part of a String
  • AppendIfMissing - appends a suffix to the end of the String if not present
  • PrependIfMissing - prepends a prefix to the start of the String if not present
  • LeftPad/RightPad/Center/Repeat - pads a String
  • UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
  • CountMatches - counts the number of occurrences of one String in another
  • IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
  • DefaultString - protects against a null input String
  • Rotate - rotate (circular shift) a String
  • Reverse/ReverseDelimited - reverses a String
  • Abbreviate - abbreviates a string using ellipsis or another given String
  • Difference - compares Strings and reports on their differences
  • LevenshteinDistance - the number of changes needed to change one String into another
    
Veja também:
 

Text

Problema
Expression
Formatar uma texto usando variáveis
#text.format('Total: %03d', var1)
Encontrar uma palavra-chave em um texto
#text.keyword(msg,'sim','s')

Random

Problema
Expression
Gerar uma string aleatória
#random.random(20)
Gerar uma string aleatória contendo apenas letras e números
#random.randomAlphanumeric(20)
Gerar uma string aleatória contendo apenas letras
#random.randomAlphabetic(20)
Gerar uma string aleatória contendo apenas números
#random.randomAlphanumeric(20)

Date

Problema
Expression
Criar um objeto do tipo 'data' a partir de uma string
#time.parseDate('2018-01-01')
Criar um objeto do tipo 'data' a partir da data atual
#time.now().toLocalDate()
Verificar se uma data cai entre outras duas
#time.isBetween(date,startDt,endDt)
Avançar uma data em alguns dias
date.plusDays(7)
Verificar se uma data é anterior a outra
date.isBefore(otherDate)
Voltar uma data em alguns dias
date.minusDays(7)
Descobrir o dia da semana de uma data
date.getDayOfWeek()
Verificar se uma data cai em dia útil
#time.isBusinessDay(date)
Avançar uma data em alguns meses
date.plusMonths(3)
Voltar uma data em alguns meses
date.minusMonths(3)
Verificar se uma data cai entre outras duas
#time.isBetween(date,startDt,endDt)
Formatar uma data como string
#time.format(date,'dd/MM/yyyy')
parseDate(text)
 
Parses a string and returns a LocalDate object. Supported date formats are:
 
Format: Sample
 
ISO: 2011-12-03+01:00
ISO_LOCAL: 2011-12-03
SHORT (pt_BR): 30/11/14
MEDIUM (pt_BR): 30/11/2014
LONG (pt_BR): 30 de Novembro de 2014
dd-MM-yy: 30-11-14
dd-MM-yyyy: 30-11-2014
 
parseDate(text, format)
 
Parses a string using the specified format and returns a LocalDate object. 
 
Veja também: 
 
parseDate(text, format, locale)  
 
Parses a string using the specified format and locale and returns a LocalDate object. 
 
Veja também: 
 
The 'locale' param is a locale specifier string, usually a language code followed by '-' and a country code. 
 
Ex.: "pt-BR" for Brazilian Portuguese.
 
parseTime(text)
 
Parses a string and returns a LocalDate object. Supported time formats are:    
 
ISO: 23:45:00, 23:45
ISO_LOCAL: 23:45:00, 23:45
HH:mm: 23:45
HH'h'mm: 23h45
HH'h'mm'm': 23h45m
HH'h'mm'min': 23h45min
 
parseTime(text, format)
 
Parses a string using the specified format and returns a LocalTime object.
 
 
parseTime(text, format, locale)
 
Parses a string using the specified format and locale and returns a LocalTime object.
 
 
The 'locale' param is a locale specifier string, usually a language code followed by '-' and a country code. Ex.: "pt-BR" for Brazilian Portuguese.
 
format(date, format)
 
Formats a date using the specified format and returns a string.
 
Veja também: 
 
format(date, format, locale)
 
Formats a date using the specified format and returns a string.
 
Veja também: 
 
The 'locale' param is a locale specifier string, usually a language code followed by '-' and a country code.
Ex.: "pt-BR" for Brazilian Portuguese.
 
now
    
Returns a LocalDatetime object containing the current date and time. To convert it to LocalDate or 
LocalTime objects, use the methods toLocalDate() and toLocalTime, respectively.
 
isBusinessDay(date)
 
Checks if a LocalDate or LocalDateTime object's day of week is a business day (Monday - Friday)
 
isBetween(date, start, end)
 
Checks if a LocalDate, LocalTime or LocalDateTime lies between a period denoted by start and end params.

Time

Problema
Expression
Criar um objeto do tipo 'hora' a partir de uma string
Formatar uma hora como string
Criar um objeto do tipo 'hora' a partir da hora atual
#time.now().toLocalTime()
Avançar um horário em algumas horas
hour.plusHours(12)
Voltar um horário em algumas horas
hour.minushours(12)
Verificar se uma hora é posterior a outra
hour.isAfter(anotherHour)
Verificar se uma hora é anterior a outra
hour.isBefore(anotherHour)
Verificar se uma data cai entre outras duas
#time.isBetween(hour,start,end)
Formatar uma hora como string
#time.format(hour,'HH:mm')

Base64

Problema
Expression
Codificar uma string em base64
#base64.encodeBase64String(str.getBytes())
Decodificar uma string em base64
#base64.decodeBase64(str)
Provides Base64 encoding and decoding as defined by RFC 2045.
 
Veja também:

Hash

Problema
Expression
Gerar o hash MD5 de uma string
#hash.md5(str)
Gerar o hash SHA-256 de uma string
#hash.sha256(str)
Gerar o hash SHA-512 de uma string
#hash.sha512(str)
md5(string)
 
Calculates the MD5 digest and returns the value as a 32 character hex string.
 
sha256(string)
 
Calculates the SHA-256 digest and returns the value as a hex string. 
 
sha512(string)
 
 Calculates the SHA-512 digest and returns the value as a hex string.

Phone

parse(text)
 
Parses a string and returns a PhoneNumber object if the specified string contains a valid phone number.
 
Supported formats are: 
 
+5551981234567
5551981234567
+55 51 981234567
+55 51 98123 4567
55 51 98123 4567
+55 (51) 98123 4567
(51) 98123 4567
(51) 98123-4567
(51) 981 234 567
51 98123 4567
+55-51-98123-4567
(51) 981.234.567
 
format(phone, format)
 
Formats a PhoneNumber object as a string using the specified format.
 
INTERNATIONAL: +55 51 98123 4567
NATIONAL: 51 98123 4567
E164: +5551981234567
RFC3966: tel:+55-51-98123-4567
 
find(text)
 
Finds a phone number in a string and returns it as a formatted number using the E164 format specifier.
 
Este artigo resolveu sua dúvida?
Últimos artigos visitados