From d504d7a44d328838c2f0680fb797d9e64db006c8 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Tue, 20 Aug 2024 23:56:13 +0300 Subject: [PATCH] Update functions.md --- docs/docs/guide/functions.md | 320 +++++++++++++++++------------------ 1 file changed, 160 insertions(+), 160 deletions(-) diff --git a/docs/docs/guide/functions.md b/docs/docs/guide/functions.md index 1268fe7..396ca94 100644 --- a/docs/docs/guide/functions.md +++ b/docs/docs/guide/functions.md @@ -2,342 +2,342 @@ ## String -### Lower Words +### Split ```php -lowerWords(string) +split(string, [separator]) ``` -Convert all words in a string to lowercase. +Split a string into a list of substrings. #### Example ```php -lowerWords("Hello, World!") +split("a, b, c", ", ") => ["a", "b", "c"] -// output: "hello, world!" +// output: ["a", "b", "c"] ``` -### Char +### Type ```php -char(string) +type(value) ``` -Convert an ASCII code to a character. +Get the type of a value as a string. #### Example ```php -char(65) => "A" +type(42) => "int" -// output: "A" +// output: "int" ``` -### Length +### Lower First ```php -len(value) +lowerFirst(string) ``` -Get the length of a string, list, or map. +Convert the first character of a string to lowercase. #### Example ```php -len("hello") => 5 +lowerFirst("Hello") -// output: 5 +// output: "hello" ``` -### Join +### Char ```php -join(list, separator) +char(string) ``` -Join a list of strings into a single string with a separator. +Convert an ASCII code to a character. #### Example ```php -join(["a", "b", "c"], ", ") => "a, b, c" +char(65) => "A" -// output: "a, b, c" +// output: "A" ``` -### Split +### Rune ```php -split(string, [separator]) +rune(str) ``` -Split a string into a list of substrings. +Convert a 1-character string to an ASCII code. #### Example ```php -split("a, b, c", ", ") => ["a", "b", "c"] +rune("A") => 65 -// output: ["a", "b", "c"] +// output: 65 ``` -### Type +### Explode ```php -type(value) +explode([separator], string) ``` -Get the type of a value as a string. +Explode a string into a list of substrings. It's the same as split() with the arguments reversed. #### Example ```php -type(42) => "int" +explode(", ", "a, b, c") => ["a", "b", "c"] -// output: "int" +// output: ["a", "b", "c"] ``` -### Rune +### Lower Words ```php -rune(str) +lowerWords(string) ``` -Convert a 1-character string to an ASCII code. +Convert all words in a string to lowercase. #### Example ```php -rune("A") => 65 +lowerWords("Hello, World!") -// output: 65 +// output: "hello, world!" ``` -### Pascal Case +### Dot Case ```php -pascalCase(string) +dotCase(string) ``` -Convert a string to PascalCase. +Convert a string to dot.case. #### Example ```php -pascalCase("Hello, World!") +dotCase("Hello, World!") -// output: "HelloWorld" +// output: "hello.world" ``` -### Lower First +### Lower ```php -lowerFirst(string) +lower(string) ``` -Convert the first character of a string to lowercase. +Convert a string to lowercase. #### Example ```php -lowerFirst("Hello") +lower("HELLO") => "hello" // output: "hello" ``` -### Kebab Case +### Up Words ```php -kebabCase(string) +upWords(string) ``` -Convert a string to kebab-case. +Convert all words in a string to uppercase. #### Example ```php -kebabCase("Hello, World!") +upWords("hello, world!") -// output: "hello-world" +// output: "Hello, World!" ``` -### Dot Case +### Camel Case ```php -dotCase(string) +camelCase(string) ``` -Convert a string to dot.case. +Convert a string to camelCase. #### Example ```php -dotCase("Hello, World!") +camelCase("Hello, World!") -// output: "hello.world" +// output: "helloWorld" ``` -### Explode +### Find ```php -explode([separator], string) +find(haystack, needle) ``` -Explode a string into a list of substrings. It's the same as split() with the arguments reversed. +Find the first occurrence of a substring in a string or a value in a list. #### Example ```php -explode(", ", "a, b, c") => ["a", "b", "c"] +find("hello", "e") => 1 -// output: ["a", "b", "c"] +// output: 1 ``` -### Upper +### Kebab Case ```php -upper(string) +kebabCase(string) ``` -Convert a string to uppercase. +Convert a string to kebab-case. #### Example ```php -upper("hello") => "HELLO" +kebabCase("Hello, World!") -// output: "HELLO" +// output: "hello-world" ``` -### Lower +### Join ```php -lower(string) +join(list, separator) ``` -Convert a string to lowercase. +Join a list of strings into a single string with a separator. #### Example ```php -lower("HELLO") => "hello" +join(["a", "b", "c"], ", ") => "a, b, c" -// output: "hello" +// output: "a, b, c" ``` -### Up Words +### Snake Case ```php -upWords(string) +snakeCase(string) ``` -Convert all words in a string to uppercase. +Convert a string to snake_case. #### Example ```php -upWords("hello, world!") +snakeCase("Hello, World!") -// output: "Hello, World!" +// output: "hello_world" ``` -### Find +### Pascal Case ```php -find(haystack, needle) +pascalCase(string) ``` -Find the first occurrence of a substring in a string or a value in a list. +Convert a string to PascalCase. #### Example ```php -find("hello", "e") => 1 +pascalCase("Hello, World!") -// output: 1 +// output: "HelloWorld" ``` -### Up First +### Length ```php -upFirst(string) +len(value) ``` -Convert the first character of a string to uppercase. +Get the length of a string, list, or map. #### Example ```php -upFirst("hello") => "Hello" +len("hello") => 5 -// output: "Hello" +// output: 5 ``` -### Snake Case +### Upper ```php -snakeCase(string) +upper(string) ``` -Convert a string to snake_case. +Convert a string to uppercase. #### Example ```php -snakeCase("Hello, World!") +upper("hello") => "HELLO" -// output: "hello_world" +// output: "HELLO" ``` -### Camel Case +### Up First ```php -camelCase(string) +upFirst(string) ``` -Convert a string to camelCase. +Convert the first character of a string to uppercase. #### Example ```php -camelCase("Hello, World!") +upFirst("hello") => "Hello" -// output: "helloWorld" +// output: "Hello" ``` -## HTTP +## Conversion -### HTTP Register +### Int ```php -httpRegister(pattern, handler) +int(value) ``` -Register a handler function for a URL pattern. +Convert a value to an integer. #### Example ```php -httpRegister("/", func() { return "Hello, World!" }) +int("42") => 42 -// output: "Hello, World!" +// output: 42 ``` -### HTTP Listen +### Str ```php -httpListen(portOrAddress) +str(value) ``` -Start the HTTP server. +Convert a value to a string. #### Example ```php -httpListen(" +str([1, 2, 3]) => "[1, 2, 3]" -// output: Server is starting on http +// output: "[1, 2, 3]" ``` ## Array @@ -358,6 +358,22 @@ append([1, 2], 3, 4) => [1, 2, 3, 4] // output: [1, 2, 3, 4] ``` +### Sort + +```php +sort(list, [key]) +``` + +Sort a list of values. + +#### Example + +```php +sort([3, 1, 2]) => [1, 2, 3] + +// output: [1, 2, 3] +``` + ### Range ```php @@ -390,23 +406,39 @@ slice("hello", 1, 3) => "el" // output: "el" ``` -### Sort +## System + +### Exit ```php -sort(list, [key]) +exit([code]) ``` -Sort a list of values. +Exit the script with an optional exit code. #### Example ```php -sort([3, 1, 2]) => [1, 2, 3] +exit(1) -// output: [1, 2, 3] +// output: exit status 1 ``` -## System +### Echo + +```php +echo(value1, value2, ...) +``` + +Print values to the standard output. + +#### Example + +```php +echo("hello", 42) => hello 42 + +// output: hello 42 +``` ### Read @@ -456,87 +488,55 @@ args() => ["arg1", "arg2"] // output: ["arg1", "arg2"] ``` -### Exit - -```php -exit([code]) -``` - -Exit the script with an optional exit code. - -#### Example - -```php -exit(1) - -// output: exit status 1 -``` +## File System -### Echo +### File Get Contents ```php -echo(value1, value2, ...) +fileGetContents(url) ``` -Print values to the standard output. +Get the contents of a file or URL. #### Example ```php -echo("hello", 42) => hello 42 - -// output: hello 42 -``` - -## Conversion - -### Int +fileGetContents("http -```php -int(value) +// output: "..." ``` -Convert a value to an integer. - -#### Example - -```php -int("42") => 42 - -// output: 42 -``` +## HTTP -### Str +### HTTP Register ```php -str(value) +httpRegister(pattern, handler) ``` -Convert a value to a string. +Register a handler function for a URL pattern. #### Example ```php -str([1, 2, 3]) => "[1, 2, 3]" +httpRegister("/", func() { return "Hello, World!" }) -// output: "[1, 2, 3]" +// output: "Hello, World!" ``` -## File System - -### File Get Contents +### HTTP Listen ```php -fileGetContents(url) +httpListen(portOrAddress) ``` -Get the contents of a file or URL. +Start the HTTP server. #### Example ```php -fileGetContents("http +httpListen(" -// output: "..." +// output: Server is starting on http ```