aboutsummaryrefslogtreecommitdiff
path: root/lua/user/utils.lua
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2023-02-12 16:52:30 +0200
committersrdusr <trevorgray@srdusr.com>2023-02-12 16:52:30 +0200
commit565f74484110409e8bdc1269d4ef1953e61d98be (patch)
tree3d73a55df0548bc166d2177d988547494748365c /lua/user/utils.lua
parentaa2e1e9313a59caa658318719d6181d817055ad9 (diff)
downloaddotfiles-565f74484110409e8bdc1269d4ef1953e61d98be.tar.gz
dotfiles-565f74484110409e8bdc1269d4ef1953e61d98be.zip
Add a function to determine if a value of any type is empty
Diffstat (limited to 'lua/user/utils.lua')
-rw-r--r--lua/user/utils.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/lua/user/utils.lua b/lua/user/utils.lua
index 07867a4..f70fac5 100644
--- a/lua/user/utils.lua
+++ b/lua/user/utils.lua
@@ -28,6 +28,20 @@ end
--------------------------------------------------
+---Determine if a value of any type is empty
+---@param item any
+---@return boolean?
+function M.empty(item)
+ if not item then return true end
+ local item_type = type(item)
+ if item_type == 'string' then return item == '' end
+ if item_type == 'number' then return item <= 0 end
+ if item_type == 'table' then return vim.tbl_isempty(item) end
+ return item ~= nil
+end
+
+--------------------------------------------------
+
--- Create a dir if it does not exist
function M.may_create_dir(dir)
local res = fn.isdirectory(dir)