diff --git a/docs/stdlib/doc/date.md b/docs/stdlib/doc/date.md index b428756..627f5c4 100644 --- a/docs/stdlib/doc/date.md +++ b/docs/stdlib/doc/date.md @@ -1,3 +1,43 @@ +## `date_add` +```ab +pub fun date_add(add: Text, date: Text = "", utc: Bool = false): Text ? +``` + +### EXPERIMENTAL + +Adds a value to a date. + +If no date is specified, the current date is used. + +Example : `date_add("+3 days")` + +You can use (+/-): + +- years +- months +- days +- hours +- minutes +- seconds + + +## `date_compare` +```ab +pub fun date_compare(date_a: Text, date_b: Text = "", utc: Bool = false): Num ? +``` + +### EXPERIMENTAL +Compares two dates. + +Returns 1 if date_a is after date_b. + +Returns 0 if date_a and date_b is the same. + +Returns -1 if date_b is after date_a. + +If date_b is not provided, current date will be used. + + ## `date_posix` ```ab pub fun date_posix(format: Text = "", date: Text = "", utc: Bool = false): Text ? @@ -83,43 +123,3 @@ pub fun now(): Num Returns the current timestamp (seconds since the Epoch (1970-01-01 00:00 UTC)). -## `date_add` -```ab -pub fun date_add(add: Text, date: Text = "", utc: Bool = false): Text ? -``` - -### EXPERIMENTAL - -Adds a value to a date. - -If no date is specified, the current date is used. - -Example : `date_add("+3 days")` - -You can use (+/-): - -- years -- months -- days -- hours -- minutes -- seconds - - -## `date_compare` -```ab -pub fun date_compare(date_a: Text, date_b: Text = "", utc: Bool = false): Num ? -``` - -### EXPERIMENTAL -Compares two dates. - -Returns 1 if date_a is after date_b. - -Returns 0 if date_a and date_b is the same. - -Returns -1 if date_b is after date_a. - -If date_b is not provided, current date will be used. - - diff --git a/docs/stdlib/doc/env.md b/docs/stdlib/doc/env.md index c98bb0c..b392f04 100644 --- a/docs/stdlib/doc/env.md +++ b/docs/stdlib/doc/env.md @@ -1,73 +1,75 @@ -## `get_env_var` +## `color_echo` ```ab -pub fun get_env_var(var: Text, file: Text = ".env"): Text +pub fun color_echo(message: Text, color: Num): Null ``` -Retrieves the value of an environment variable, optionally sourcing it from a file if not already set. +Prints a text with a specified color. -## `load_env_file` +## `confirm` ```ab -pub fun load_env_file(file: Text = ".env"): Null +pub fun confirm(prompt: Text, default_yes: Bool = false): Bool ``` -Loads the env file in the environment, using `xargs`. +Creates a confirm prompt (Yes/No), and returns true if the choice is Yes. +"No" is the default choice, set default_yes to true for "Yes" as default choice. -## `shell_isset` + +## `echo_info` ```ab -pub fun shell_isset(name: Text): Bool +pub fun echo_info(message: Text): Null ``` -Checks if a variable inside the shell session exists. +Prints a text as a info message. -## `shell_constant_set` +## `echo_success` ```ab -pub fun shell_constant_set(name: Text, val: Text): Null ? +pub fun echo_success(message: Text): Null ``` -Sets a constant inside the shell session. +Prints a text as a success message. -## `shell_constant_get` +## `echo_warning` ```ab -pub fun shell_constant_get(name: Text): Text ? +pub fun echo_warning(message: Text): Null ``` -Gets a constant inside the shell session. +Prints a text as a warning message. -## `shell_var_set` +## `error` ```ab -pub fun shell_var_set(name: Text, val: Text): Null ? +pub fun error(message: Text, exit_code: Num = 1): Null ``` -Sets a constant inside the shell session. +Prints a text as a error and exits if the status code is greater than 0. -## `shell_var_get` +## `exit` ```ab -pub fun shell_var_get(name: Text): Text ? +pub fun exit(code: Num): Null ``` -Gets a constant inside the shell session. +Closes the script. -## `shell_unset` +## `get_env_var` ```ab -pub fun shell_unset(name: Text): Null ? +pub fun get_env_var(var: Text, file: Text = ".env"): Text ``` -Removes a variable inside the shell session. +Retrieves the value of an environment variable, optionally sourcing it from a file if not already set. -## `is_command` +## `has_failed` ```ab -pub fun is_command(command: Text): Bool +pub fun has_failed(command: Text): Bool ``` -Checks if a command exists. +Checks if the command has failed. ## `input` @@ -78,38 +80,28 @@ pub fun input(prompt: Text): Text Creates a prompt and returns the value. -## `confirm` -```ab -pub fun confirm(prompt: Text, default_yes: Bool = false): Bool -``` - -Creates a confirm prompt (Yes/No), and returns true if the choice is Yes. - -"No" is the default choice, set default_yes to true for "Yes" as default choice. - - -## `has_failed` +## `is_command` ```ab -pub fun has_failed(command: Text): Bool +pub fun is_command(command: Text): Bool ``` -Checks if the command has failed. +Checks if a command exists. -## `exit` +## `is_root` ```ab -pub fun exit(code: Num): Null +pub fun is_root(): Bool ``` -Closes the script. +Checks if the script is running with a user with root permission. -## `is_root` +## `load_env_file` ```ab -pub fun is_root(): Bool +pub fun load_env_file(file: Text = ".env"): Null ``` -Checks if the script is running with a user with root permission. +Loads the env file in the environment, using `xargs`. ## `printf` @@ -128,75 +120,83 @@ pub fun printf_escape(text: Text): Text Escapes the text to be used with `printf`. -## `text_shell` +## `shell_constant_get` ```ab -pub fun text_shell(message: Text, style: Num, fg: Num, bg: Num): Text +pub fun shell_constant_get(name: Text): Text ? ``` -Prepares a text with formatting options for `printf`. +Gets a constant inside the shell session. -## `text_bold` +## `shell_constant_set` ```ab -pub fun text_bold(message: Text): Text +pub fun shell_constant_set(name: Text, val: Text): Null ? ``` -Returns a text as bold. +Sets a constant inside the shell session. -## `text_italic` +## `shell_isset` ```ab -pub fun text_italic(message: Text): Text +pub fun shell_isset(name: Text): Bool ``` -Returns a text as italic. +Checks if a variable inside the shell session exists. -## `text_underlined` +## `shell_unset` ```ab -pub fun text_underlined(message: Text): Text +pub fun shell_unset(name: Text): Null ? ``` -Returns a text as underlined. +Removes a variable inside the shell session. -## `color_echo` +## `shell_var_get` ```ab -pub fun color_echo(message: Text, color: Num): Null +pub fun shell_var_get(name: Text): Text ? ``` -Prints a text with a specified color. +Gets a constant inside the shell session. -## `echo_info` +## `shell_var_set` ```ab -pub fun echo_info(message: Text): Null +pub fun shell_var_set(name: Text, val: Text): Null ? ``` -Prints a text as a info message. +Sets a constant inside the shell session. -## `echo_success` +## `text_bold` ```ab -pub fun echo_success(message: Text): Null +pub fun text_bold(message: Text): Text ``` -Prints a text as a success message. +Returns a text as bold. -## `echo_warning` +## `text_italic` ```ab -pub fun echo_warning(message: Text): Null +pub fun text_italic(message: Text): Text ``` -Prints a text as a warning message. +Returns a text as italic. -## `error` +## `text_shell` ```ab -pub fun error(message: Text, exit_code: Num = 1): Null +pub fun text_shell(message: Text, style: Num, fg: Num, bg: Num): Text ``` -Prints a text as a error and exits if the status code is greater than 0. +Prepares a text with formatting options for `printf`. + + +## `text_underlined` +```ab +pub fun text_underlined(message: Text): Text +``` + +Returns a text as underlined. diff --git a/docs/stdlib/doc/fs.md b/docs/stdlib/doc/fs.md index 451d496..a605d90 100644 --- a/docs/stdlib/doc/fs.md +++ b/docs/stdlib/doc/fs.md @@ -1,34 +1,37 @@ -## `dir_exist` +## `change_owner` ```ab -pub fun dir_exist(path) +pub fun change_owner(user: Text, path: Text): Bool ``` -Checks if a directory exists. +Changes the owner of a file. +If the file doesn't exist, it returns `false` -## `file_exist` + +## `create_dir` ```ab -pub fun file_exist(path) +pub fun create_dir(path: Text): Null ``` -Checks if a file exists. +Creates a directory with all parent directories as required. -## `file_read` +## `create_symbolic_link` ```ab -pub fun file_read(path) +pub fun create_symbolic_link(origin: Text, destination: Text): Bool ``` -Gets file contents from a path. +Creates a symbolic link. + +If the file doesn't exist, it returns a boolean and prints a message. -## `file_write` +## `dir_exist` ```ab -pub fun file_write(path, content) +pub fun dir_exist(path) ``` -Writes content to a file. -Doesn't check if the file exist +Checks if a directory exists. ## `file_append` @@ -41,41 +44,38 @@ Appends content to a file. Doesn't check if the file exists. -## `create_symbolic_link` +## `file_exist` ```ab -pub fun create_symbolic_link(origin: Text, destination: Text): Bool +pub fun file_exist(path) ``` -Creates a symbolic link. - -If the file doesn't exist, it returns a boolean and prints a message. +Checks if a file exists. -## `create_dir` +## `file_read` ```ab -pub fun create_dir(path: Text): Null +pub fun file_read(path) ``` -Creates a directory with all parent directories as required. +Gets file contents from a path. -## `make_executable` +## `file_write` ```ab -pub fun make_executable(path: Text): Bool +pub fun file_write(path, content) ``` -Sets a file as executable. - -If the file doesn't exist, it returns a boolean and prints a message. +Writes content to a file. +Doesn't check if the file exist -## `change_owner` +## `make_executable` ```ab -pub fun change_owner(user: Text, path: Text): Bool +pub fun make_executable(path: Text): Bool ``` -Changes the owner of a file. +Sets a file as executable. -If the file doesn't exist, it returns `false` +If the file doesn't exist, it returns a boolean and prints a message. diff --git a/docs/stdlib/doc/math.md b/docs/stdlib/doc/math.md index 5fce147..136ad51 100644 --- a/docs/stdlib/doc/math.md +++ b/docs/stdlib/doc/math.md @@ -1,17 +1,17 @@ -## `sum` +## `abs` ```ab -pub fun sum(list: [Num]): Num +pub fun abs(number: Num): Num ``` -Sums an array's contents +Returns the absolute value of a number -## `round` +## `ceil` ```ab -pub fun round(number: Num): Num +pub fun ceil(number: Num): Num ``` -Returns a number, rounded to the nearest integer +Returns the smallest integer greater than or equal to a number ## `floor` @@ -22,19 +22,19 @@ pub fun floor(number: Num): Num Returns the largest integer less than or equal to a number -## `ceil` +## `round` ```ab -pub fun ceil(number: Num): Num +pub fun round(number: Num): Num ``` -Returns the smallest integer greater than or equal to a number +Returns a number, rounded to the nearest integer -## `abs` +## `sum` ```ab -pub fun abs(number: Num): Num +pub fun sum(list: [Num]): Num ``` -Returns the absolute value of a number +Sums an array's contents diff --git a/docs/stdlib/doc/text.md b/docs/stdlib/doc/text.md index 79116ec..0c9af78 100644 --- a/docs/stdlib/doc/text.md +++ b/docs/stdlib/doc/text.md @@ -1,51 +1,42 @@ -## `replace_once` -```ab -pub fun replace_once(source, pattern, replacement) -``` - -Finds the first occurrence of a pettern in the content and replaces it with the provided replacement text. - - -## `replace` +## `capitalize` ```ab -pub fun replace(source, pattern, replacement) +pub fun capitalize(text: Text): Text ``` -Replaces all occurences of a pattern in the content with the provided replacement text. +Capitalize the first letter of the given `text`. -## `replace_regex` +## `char_at` ```ab -pub fun replace_regex(source: Text, pattern: Text, replacement: Text): Text +pub fun char_at(text: Text, index: Num): Text ``` -Replaces all occurences of a regex pattern in the content with the provided replacement text. - -Function uses `sed` +Returns the character from `text` at the specified `index` (0-based). +If `index` is negative, the substring starts from the end of `text` based on the absolute value of `index`. -## `split` +## `chars` ```ab -pub fun split(text: Text, delimiter: Text): [Text] +pub fun chars(text: Text): [Text] ``` -Splits the input `text` into an array of substrings using the specified `delimiter`. +Splits a text into an array of individual characters. -## `lines` +## `contains` ```ab -pub fun lines(text: Text): [Text] +pub fun contains(text: Text, phrase: Text): Bool ``` -Splits a `text` into an array of substrings based on newline characters. +Checks if some text contains a value/ -## `words` +## `ends_with` ```ab -pub fun words(text: Text): [Text] +pub fun ends_with(text: Text, suffix: Text): Bool ``` -Splits a `text` into an array of substrings based on space character. +Checks if text ends with a value. ## `join` @@ -56,28 +47,20 @@ pub fun join(list: [Text], delimiter: Text): Text Merges text using the delimeter specified. -## `trim_left` -```ab -pub fun trim_left(text: Text): Text -``` - -Trims the spaces at top of the text using `sed`. - - -## `trim_right` +## `len` ```ab -pub fun trim_right(text: Text): Text +pub fun len(value): Num ``` -Trims the spaces at end of the text using `sed`. +Gets the length of provided text or array. -## `trim` +## `lines` ```ab -pub fun trim(text: Text): Text +pub fun lines(text: Text): [Text] ``` -Trims the spaces from the text input. +Splits a `text` into an array of substrings based on newline characters. ## `lower` @@ -88,12 +71,12 @@ pub fun lower(text: Text): Text Makes the text input lowercase using `tr`. -## `upper` +## `lpad` ```ab -pub fun upper(text: Text): Text +pub fun lpad(text: Text, pad: Text, length: Num): Text ``` -Makes the text input uppercase using `tr`. +Pads `text` with the specified `pad` character on left until it reaches the desired `length`. ## `parse` @@ -104,28 +87,30 @@ pub fun parse(text: Text): Num ? Attempts to parse a given text into a number, returning the parsed number or zero if parsing fails. -## `chars` +## `replace` ```ab -pub fun chars(text: Text): [Text] +pub fun replace(source, pattern, replacement) ``` -Splits a text into an array of individual characters. +Replaces all occurences of a pattern in the content with the provided replacement text. -## `len` +## `replace_once` ```ab -pub fun len(value): Num +pub fun replace_once(source, pattern, replacement) ``` -Gets the length of provided text or array. +Finds the first occurrence of a pettern in the content and replaces it with the provided replacement text. -## `contains` +## `replace_regex` ```ab -pub fun contains(text: Text, phrase: Text): Bool +pub fun replace_regex(source: Text, pattern: Text, replacement: Text, extended: Bool = false): Text ``` -Checks if some text contains a value/ +Replaces all occurences of a regex pattern in the content with the provided replacement text. + +Function uses `sed` ## `reverse` @@ -136,20 +121,12 @@ pub fun reverse(text: Text): Text Reverses text using `rev`. -## `starts_with` -```ab -pub fun starts_with(text: Text, prefix: Text): Bool -``` - -Checks if text starts with a value. - - -## `ends_with` +## `rpad` ```ab -pub fun ends_with(text: Text, suffix: Text): Bool +pub fun rpad(text: Text, pad: Text, length: Num): Text ``` -Checks if text ends with a value. +Pads `text` with the specified `pad` character on the right until it reaches the desired `length`. ## `slice` @@ -164,37 +141,60 @@ If `length` is provided, the substring will include `length` characters; otherwi If `length` is negative, an empty string is returned. -## `char_at` +## `split` ```ab -pub fun char_at(text: Text, index: Num): Text +pub fun split(text: Text, delimiter: Text): [Text] ``` -Returns the character from `text` at the specified `index` (0-based). -If `index` is negative, the substring starts from the end of `text` based on the absolute value of `index`. +Splits the input `text` into an array of substrings using the specified `delimiter`. -## `capitalize` +## `starts_with` ```ab -pub fun capitalize(text: Text): Text +pub fun starts_with(text: Text, prefix: Text): Bool ``` -Capitalize the first letter of the given `text`. +Checks if text starts with a value. -## `lpad` +## `trim` ```ab -pub fun lpad(text: Text, pad: Text, length: Num): Text +pub fun trim(text: Text): Text ``` -Pads `text` with the specified `pad` character on left until it reaches the desired `length`. +Trims the spaces from the text input. -## `rpad` +## `trim_left` ```ab -pub fun rpad(text: Text, pad: Text, length: Num): Text +pub fun trim_left(text: Text): Text ``` -Pads `text` with the specified `pad` character on the right until it reaches the desired `length`. +Trims the spaces at top of the text using `sed`. + + +## `trim_right` +```ab +pub fun trim_right(text: Text): Text +``` + +Trims the spaces at end of the text using `sed`. + + +## `upper` +```ab +pub fun upper(text: Text): Text +``` + +Makes the text input uppercase using `tr`. + + +## `words` +```ab +pub fun words(text: Text): [Text] +``` + +Splits a `text` into an array of substrings based on space character. ## `zfill` diff --git a/sync-stdlib-doc.ab b/sync-stdlib-doc.ab index 5baf522..b53fc37 100755 --- a/sync-stdlib-doc.ab +++ b/sync-stdlib-doc.ab @@ -13,7 +13,8 @@ if silent download("https://github.com/amber-lang/amber/archive/refs/heads/maste loop v in stdlib { if (contains(v, ".ab") and file_exist("{std_path}{v}")) { - unsafe $amber --docs "{std_path}{v}" "./docs/stdlib/doc"$ + echo "Parsing {std_path}{v}" + unsafe $amber --docs "{std_path}{v}" "./docs/stdlib/doc/"$ echo "\n" } }