-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): New module
util
. Integrated first fun
- Loading branch information
Showing
6 changed files
with
66 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
---@diagnostic disable:unused-local | ||
---@diagnostic disable:unused-function | ||
|
||
---@class UserUtils | ||
---@field strip_fields fun(T: table, fields: string|string[]): table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
---@diagnostic disable:unused-function | ||
---@diagnostic disable:unused-local | ||
|
||
require('user.types.user.util') | ||
|
||
local Value = require('user.check.value') | ||
local is_tbl = Value.is_tbl | ||
local is_str = Value.is_str | ||
local empty = Value.empty | ||
local field = Value.field | ||
|
||
---@type UserUtils | ||
local M = {} | ||
|
||
function M.strip_fields(T, fields) | ||
if not is_tbl(T) then | ||
error('(maps:strip_options): Empty table') | ||
end | ||
|
||
if empty(T) then | ||
return T | ||
end | ||
|
||
if not (is_str(fields) or is_tbl(fields)) or empty(fields) then | ||
return T | ||
end | ||
|
||
---@type UserMaps.Keymap.Opts | ||
local res = {} | ||
|
||
if is_str(fields) then | ||
if not field(fields, T) then | ||
return T | ||
end | ||
|
||
for k, v in next, T do | ||
if k ~= fields then | ||
res[k] = v | ||
end | ||
end | ||
else | ||
for k, v in next, T do | ||
if not vim.tbl_contains(fields, k) then | ||
res[k] = v | ||
end | ||
end | ||
end | ||
|
||
return res | ||
end | ||
|
||
return M |