The Text protocol:

protocol Text {
  func countLines(_ string: String) -> Int
  func countCharacters(_ string: String) -> Int
  func countWords(_ string: String) -> Int
  func capitalize(_ string: String) -> String
  func lowercase(_ string: String) -> String
  func uppercase(_ string: String) -> String
  func getUUID() -> String
  func isLink(_ string: String) -> Bool
  func findLinks(_ string: String) -> [String]
  func URLEncode(_ string: String) -> String
  func URLDecode(_ string: String) -> String
  func encodeAsBase64(_ string: String) -> String
  func decodeFromBase64(_ string: String) -> String?


const lines = $text.countLines('hello world');
$alert.info('Text Stats', `Lines: ${lines}`); // Lines: 1

Count lines in string.


const chars = $text.countCharacters('hello world');
$alert.info('Text Stats', `Characters: ${chars}`); // Characters: 11

Count characters in string.


const words = $text.countWords('hello world');
$alert.info('Text Stats', `Words: ${words}`); // Words: 2

Count words in string.


const capitalized = $text.capitalize('hello world'); // Hello World

Capitalize string.


const lowercased = $text.lowercase('HELLO WORLD'); // hello world

Convert string to lowercase.


const uppercased = $text.uppercase('hello world'); // HELLO WORLD

Convert string to uppercase.


const uuid = $text.getUUID(); // 21889372-7DCD-41C1-9E21-05B4EA26E25F

Generate a UUID string.


const isLink = $text.isLink('https://okjson.aoo'); // true

Test if string is a link.


const links = $text.findLinks('Visit our website at https://okjson.app'); // ["https://okjson.app"]

Find links in string with Regular Expression.


URL encode string

const encoded = $text.URLEncode('OK JSON is a fine app.'); // OK%20JSON%20is%20a%20fine%20app%2E


URL decode string.

const decoded = $text.URLDecode('OK%20JSON%20is%20a%20fine%20app%2E'); // OK JSON is a fine app.


Encode input as Base64 string.

const encoded = $text.encodeAsBase64('OK JSON'); // T0sgSlNPTg==


Decode input from Base64 string. The output will be undefined if the string cannot be decoded.

const decoded = $text.decodeFromBase64('T0sgSlNPTg=='); // OK JSON