-
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] add some common functional utils
- Loading branch information
Showing
7 changed files
with
80 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
# Lua | ||
/luarocks | ||
/lua | ||
/lua_modules | ||
/.luarocks | ||
|
||
# OS | ||
.DS_Store | ||
.DS_Store |
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,9 @@ | ||
local table_utils = require("utils.table") | ||
local static = require("plugin-name.static") | ||
local main = {} | ||
|
||
function main.setup(config) | ||
static.config = table_utils.merge(static.config, config) | ||
end | ||
|
||
return main |
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,3 @@ | ||
return { | ||
config = {}, | ||
} |
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,12 @@ | ||
local command_util = {} | ||
|
||
function command_util.exec_command(command, mode) | ||
local handle = assert(io.popen(command, mode)) | ||
local origin = assert(handle:read("*a")) | ||
|
||
handle:close() | ||
|
||
return origin | ||
end | ||
|
||
return command_util |
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,23 @@ | ||
local list_utils = {} | ||
|
||
function list_utils.find(list, predicate) | ||
for _, value in ipairs(list) do | ||
if predicate(value) then | ||
return value | ||
end | ||
end | ||
|
||
return nil | ||
end | ||
|
||
function list_utils.some(list, predicate) | ||
return list_utils.find(list, predicate) ~= nil | ||
end | ||
|
||
function list_utils.includes(list, value) | ||
return list_utils.find(list, function(item) | ||
return item == value | ||
end) ~= nil | ||
end | ||
|
||
return list_utils |
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,15 @@ | ||
local string_util = {} | ||
|
||
function string_util.trim(str) | ||
return str:gsub("%s+", "") | ||
end | ||
|
||
function string_util.escape(str) | ||
return str:gsub("[%(%)%.%%%+%-%*%?%[%^%$%]]", "%%%1") | ||
end | ||
|
||
function string_util.ends_with(str, suffix) | ||
return str:sub(-#suffix) == suffix | ||
end | ||
|
||
return string_util |
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,17 @@ | ||
local table_utils = {} | ||
|
||
function table_utils.assign(t, props) | ||
for k, v in pairs(props) do | ||
t[k] = v | ||
end | ||
end | ||
|
||
function table_utils.merge(t1, t2) | ||
for k, v in pairs(t2) do | ||
t1[k] = v | ||
end | ||
|
||
return t1 | ||
end | ||
|
||
return table_utils |