Skip to content

Commit

Permalink
fix(api): check and its submodules' annotations fixed.
Browse files Browse the repository at this point in the history
Signed-off-by: Guennadi Maximov C <[email protected]>
  • Loading branch information
DrKJeff16 committed Sep 2, 2024
1 parent 0bb1b47 commit 3410f9f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 57 deletions.
13 changes: 6 additions & 7 deletions lua/user_api/check/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ local M = {}
---
--- ## Description
--- Pretty much reserved for data checking, type checking and conditional operations
---@see User.Check.Value
---@type User.Check.Value
M.value = require('user_api.check.value')

Expand All @@ -18,26 +17,26 @@ M.value = require('user_api.check.value')
--- ## Description
--- This contains many environment, module, namespace, etc. checkers.
--- Also, simplified Vim functions can be found here
---@see User.Check.Existance
---@type User.Check.Existance
M.exists = require('user_api.check.exists')

--- Check whether Nvim is running in a Linux Console rather than a `pty`
---
--- ---
--- ## Description
--- This function can be useful for (un)loading certain elements that conflict with the Linux console, for example
---
--- This function can be useful for (un)loading certain elements that conflict with the Linux console, for example
--- ---
--- ## Return
---
--- A boolean that confirms whether the environment is a Linux Console
--- ---
---@return boolean
function M.in_console()
---@type table<string, any>
local env = vim.fn.environ()

--- TODO: This is not a good enough check. Must find a better solution
return vim.tbl_contains({ 'linux' }, env['TERM'])
and not require('user_api.check.value').fields('DISPLAY', env)
--- FIXME: This is not a good enough check. Must find a better solution
return vim.tbl_contains({ 'linux' }, env['TERM']) and not M.value.fields('DISPLAY', env)
end

---@return boolean
Expand Down
117 changes: 67 additions & 50 deletions lua/user_api/check/value.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ local M = {}

-- NOTE: We define `is_nil` first as it's used by the other checkers.
--- Checks whether a value is `nil`, i.e. non existant or explicitly set as nil
--- ---
--- ## Parameters
---
--- * `var`: Any data type to be checked if it's nil.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as non-existant and the function will return `true`
---
--- * `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element doesn't exist or is `nil`, the function automatically returns false
--- - `var`: Any data type to be checked if it's nil.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as non-existant and the function will return `true`
---
--- - `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element doesn't exist or is `nil`, the function automatically returns false
--- ---
--- ## Return
---
--- A boolean value indicating whether the data is `nil` or doesn't exist
--- ---
---@param var any
Expand Down Expand Up @@ -81,95 +83,109 @@ local function type_fun(t)
end

--- Checks whether a value is a string.
--- ---
--- ## Parameters
---
--- * `var`: Any data type to be checked if it's a string.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-string and the function will return `false`.
---
--- * `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a string, the function automatically returns false.
--- - `var`: Any data type to be checked if it's a string.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-string and the function will return `false`.
---
--- - `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a string, the function automatically returns false.
--- ---
--- ## Return
---
--- A boolean value indicating whether the data is a string or not.
--- ---
M.is_str = type_fun('string')

--- Checks whether a value is a boolean.
--- ---
--- ## Parameters
---
--- * `var`: Any data type to be checked if it's a boolean.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-boolean and the function will return `false`.
---
--- * `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a boolean, the function automatically returns false.
--- - `var`: Any data type to be checked if it's a boolean.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-boolean and the function will return `false`.
---
--- - `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a boolean, the function automatically returns false.
--- ---
--- ## Return
---
--- A boolean value indicating whether the data is a boolean or not.
--- ---

M.is_bool = type_fun('boolean')
--- Checks whether a value is a function.
--- ---
--- ## Parameters
---
--- * `var`: Any data type to be checked if it's a function.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-function and the function will return `false`.
---
--- * `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a function, the function automatically returns false.
--- - `var`: Any data type to be checked if it's a function.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-function and the function will return `false`.
---
--- - `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a function, the function automatically returns false.
--- ---
--- ## Return
---
--- A boolean value indicating whether the data is a function or not.
--- ---
M.is_fun = type_fun('function')

--- Checks whether a value is a number.
--- ---
--- ## Parameters
---
--- * `var`: Any data type to be checked if it's a number.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-number and the function will return `false`.
---
--- * `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a number, the function automatically returns false.
--- - `var`: Any data type to be checked if it's a number.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-number and the function will return `false`.
---
--- - `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a number, the function automatically returns false.
--- ---
--- ## Return
---
--- A boolean value indicating whether the data is a number or not.
--- ---
M.is_num = type_fun('number')

--- Checks whether a value is a table.
--- ---
--- ## Parameters
---
--- * `var`: Any data type to be checked if it's a table.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-table and the function will return `false`.
---
--- * `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a table, the function automatically returns false.
--- - `var`: Any data type to be checked if it's a table.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-table and the function will return `false`.
---
--- - `multiple`: Tell the function you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not a table, the function automatically returns false.
--- ---
--- ## Return
---
--- A boolean value indicating whether the data is a table or not.
--- ---
M.is_tbl = type_fun('table')

--- Create the rest of `is_*` functions, save for `is_int`

--- Checks whether a value is an integer i.e. _greater than or equal to `0` and a **whole number**_.
--- ---
--- ## Parameters
---
--- * `var`: Any data type to be checked if it's an integer.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-integer and the function will return `false`.
---
--- * `multiple`: Tell the integer you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not an integer, the function automatically returns false.
--- **Keep in mind that if `multiple` is set to `true`, this _MUST_ be a _non-empty_ table**.
--- Otherwise it will be flagged as a non-integer and the function will return `false`.
---
--- - `multiple`: Tell the integer you're checking for multiple values. (Default: `false`).
--- If set to `true`, every element of the table will be checked.
--- If **any** element is not an integer, the function automatically returns false.
--- ---
--- ## Return
---
--- A boolean value indicating whether the data is an integer or not.
--- ---
function M.is_int(var, multiple)
Expand Down Expand Up @@ -328,6 +344,7 @@ end

---@param type_str Types
---@param T table
---@return boolean
function M.single_type_tbl(type_str, T)
local is_str = M.is_str
local is_tbl = M.is_tbl
Expand Down

0 comments on commit 3410f9f

Please sign in to comment.