Skip to content

Standard Library

MattiDragon edited this page Jun 28, 2024 · 2 revisions

Standard Library

The standard libraries of JsonPatcher are a set of functions that are always available to use in your programs. They are imported automatically and can be used without any extra setup. These docs are automatically generated from doc comment files included with jsonpatcher.

Module arrays

Available at "arrays"

The arrays library contains functions for manipulating arrays. All of them can be used as methods on arrays.

Function arrays.insert

Definition: (array: array, index: number, value: any) -> array

Inserts the specified value at the specified index. The inserted value will be found that the index after the insertion.

Function arrays.push

Definition: (array: array, value: any) -> array

Appends the specified value to the end of the array. Returns the array.

Function arrays.pop

Definition: (array: array) -> any

Removes the last element from the array and returns it.

Function arrays.remove

Definition: (array: array, value: any) -> array

Removes the first occurrence of the specified value from the array. Returns the array.

Function arrays.removeAt

Definition: (array: array, index: number) -> array

Removes the value at the specified index from the array. Returns the array.

Function arrays.map

Definition: (array: array, function: function) -> array

Applies the specified function to each element in the array, creating a new array and returns the result.

Function arrays.replace

Definition: (array: array, function: function) -> array

Applies the specified function to each element in the array modifying them in place

Function arrays.filter

Definition: (array: array, function: function) -> array

Applies the specified function to each element in the array, creating a new array with only the elements that returned true.

Function arrays.removeIf

Definition: (array: array, function: function) -> array

Applies the specified function to each element in the array, removing the elements that returned false.

Function arrays.reduce

Definition: (array: array, function: function, initial: any) -> any

Iterates through the array applying the specified function to each element and the current state, beginning with the initial value and being replaced by the returned value from the function. Returns the last state.

Function arrays.slice

Definition: (array: array, from: number, to?: number) -> array

Returns a slice of the array from the specified start index (inclusive) to the specified end index (exclusive)

Function arrays.indexOf

Definition: (array: array, value: any) -> number

Returns the index of the index of the value in the array, or -1 if it isn't present

Module debug

Available at "debug"

Provides various functions for debugging code.

Function debug.assert

Definition: (value: any, message?: string) -> null

Checks if the value is truthy. If it is nothing happens. If it isn't, then an error is thrown.

Function debug.throw

Definition: (message: any) -> null

Throws an error. Use this if your code gets in situations it shouldn't.

Module functions

Available at "functions"

Provides utilities for working with functions. Some of the can be used as methods on function objects.

Function functions.bind

Definition: (function: function, arg: any, index?: number) -> function

Binds the specified argument to the function at the specified index or 0 if none is provided. Can be used as a method

Function functions.then

Definition: (function: function, then: function) -> function

Creates a new function that calls the first function and then calls the second function on it's return value. Can be used as a method

Function functions.identity

Definition: () -> (value: any) -> any

Returns a function that returns its single argument.

Function functions.constant

Definition: (value: any) -> () -> any

Returns a function that always returns the specified value.

Module math

Available at "math"

The math library contains many functions for performing mathematical operations.

Property math.PI

Definition: number

Property math.E

Definition: number

Property math.NaN

Definition: number

Property math.POSITIVE_INFINITY

Definition: number

Property math.NEGATIVE_INFINITY

Definition: number

Function math.asin

Definition: (input: number) -> number

Function math.sin

Definition: (input: number) -> number

Function math.sinh

Definition: (input: number) -> number

Function math.acos

Definition: (input: number) -> number

Function math.cos

Definition: (input: number) -> number

Function math.cosh

Definition: (input: number) -> number

Function math.atan

Definition: (input: number) -> number

Function math.tan

Definition: (input: number) -> number

Function math.tanh

Definition: (input: number) -> number

Function math.exp

Definition: (input: number) -> number

Function math.log

Definition: (input: number) -> number

Function math.log10

Definition: (input: number) -> number

Function math.sqrt

Definition: (input: number) -> number

Function math.cbrt

Definition: (input: number) -> number

Function math.ceil

Definition: (input: number) -> number

Function math.floor

Definition: (input: number) -> number

Function math.abs

Definition: (input: number) -> number

Function math.signum

Definition: (input: number) -> number

Function math.max

Definition: (first: number, second: number) -> number

Function math.min

Definition: (first: number, second: number) -> number

Module objects

Available at "objects"

Provides utilities for working with objects.

Function objects.keys

Definition: (object: object) -> [string]

Returns the list of keys in a object.

Module strings

Available at "strings"

Provides utilities for manipulating strings. Many of the methods in this module can be used as methods.

Function strings.matches

Definition: (string: string, regex: string) -> boolean

Checks if the whole string matches a specific regular expression.

Function strings.replace

Definition: (string: string, pattern: string, replacement: string) -> string

Replaces all instances of pattern in string with replacement.

Function strings.replaceRegex

Definition: (string: string, pattern: string, replacement: string) -> string

Replaces all matches of the regular expression pattern in string with replacement.

Function strings.split

Definition: (string: string, delimiter: string) -> array

Splits the string into into an array with the specified delimiter

Function strings.toLowerCase

Definition: (string: string) -> string

Converts the string to lowercase with the root locale

Function strings.toUpperCase

Definition: (string: string) -> string

Converts the string to uppercase with the root locale

Function strings.trim

Definition: (string: string) -> string

Trim the string by removing leading and trailing whitespace

Function strings.trimStart

Definition: (string: string) -> string

Trim the string by removing leading whitespace

Function strings.trimEnd

Definition: (string: string) -> string

Trim the string by removing trailing whitespace

Function strings.startsWith

Definition: (string: string, prefix: string) -> boolean

Returns true if the string starts with the specified prefix

Function strings.endsWith

Definition: (string: string, suffix: string) -> boolean

Returns true if the string ends with the specified suffix

Function strings.contains

Definition: (string: string, substring: string) -> boolean

Returns true if the string contains the specified substring

Function strings.length

Definition: (string: string) -> number

Returns the length of the string in unicode code units

Function strings.isEmpty

Definition: (string: string) -> boolean

Returns true if the string is empty (length == 0)

Function strings.isBlank

Definition: (string: string) -> boolean

Returns true if the string only contains whitespace characters

Function strings.charAt

Definition: (string: string, index: number) -> string

Returns a string consisting of only the character at the specified index

Function strings.chars

Definition: (string: string) -> array

Returns an array of strings with each character from this string

Function strings.substring

Definition: (string: string, from: number, to?: number) -> string

Returns a substring from the specified start index (inclusive) to the specified end index, if specified (exclusive)

Function strings.asString

Definition: (value: any) -> string

Converts any value to a string

Function strings.join

Definition: (array: array, string: delimiter) -> string

Converts all values in the array to a string and concatenates them with the delimiter in between

Clone this wiki locally