mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-07-28 11:02:20 +00:00
Changed 'vars' arg in lume.format() to be optional
This commit is contained in:
@@ -211,7 +211,7 @@ instead of whitespace.
|
|||||||
lume.trim(" Hello ") -- Returns "Hello"
|
lume.trim(" Hello ") -- Returns "Hello"
|
||||||
```
|
```
|
||||||
|
|
||||||
### lume.format(str, vars)
|
### lume.format(str [, vars])
|
||||||
Returns a formatted string. The values of keys in the table `vars` can be
|
Returns a formatted string. The values of keys in the table `vars` can be
|
||||||
inserted into the string by using the form `"{key}"` in `str`.
|
inserted into the string by using the form `"{key}"` in `str`.
|
||||||
```lua
|
```lua
|
||||||
|
1
lume.lua
1
lume.lua
@@ -231,6 +231,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.format(str, vars)
|
function lume.format(str, vars)
|
||||||
|
vars = vars or {}
|
||||||
local f = function(x) return tostring(vars[x] or "{" .. x .. "}") end
|
local f = function(x) return tostring(vars[x] or "{" .. x .. "}") end
|
||||||
return (str:gsub("{(.-)}", f))
|
return (str:gsub("{(.-)}", f))
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user