mirror of
https://github.com/chenasraf/text-transform.nvim.git
synced 2026-05-18 01:48:57 +00:00
chore: formatting
This commit is contained in:
@@ -3,32 +3,32 @@ local utils = require("text-transform.util")
|
||||
|
||||
local fn = {}
|
||||
|
||||
fn.WORD_BOUNDRY = '[%_%-%s%.]'
|
||||
fn.WORD_BOUNDRY = "[%_%-%s%.]"
|
||||
|
||||
--- Splits a string into words.
|
||||
--- @param string string
|
||||
--- @return table
|
||||
function fn.to_words(string)
|
||||
local words = {}
|
||||
local word = ''
|
||||
local word = ""
|
||||
for i = 1, #string do
|
||||
local char = string:sub(i, i)
|
||||
if char:match(fn.WORD_BOUNDRY) then
|
||||
if word ~= '' then
|
||||
if word ~= "" then
|
||||
table.insert(words, word:lower())
|
||||
end
|
||||
word = ''
|
||||
word = ""
|
||||
else
|
||||
word = word .. char
|
||||
-- word = word .. string:sub(i)
|
||||
-- break
|
||||
end
|
||||
D.log('transformers', 'i %d char %s word %s words %s', i, char, word, utils.dump(words))
|
||||
D.log("transformers", "i %d char %s word %s words %s", i, char, word, utils.dump(words))
|
||||
end
|
||||
if word ~= '' then
|
||||
if word ~= "" then
|
||||
table.insert(words, word:lower())
|
||||
end
|
||||
D.log('transformers', 'words %s', vim.inspect(words))
|
||||
D.log("transformers", "words %s", vim.inspect(words))
|
||||
return words
|
||||
end
|
||||
|
||||
@@ -41,14 +41,14 @@ end
|
||||
--- @param separator string|nil (optional)
|
||||
--- @return string
|
||||
function fn.transform_words(words, with_word_cb, separator)
|
||||
local out = ''
|
||||
local out = ""
|
||||
for i, word in ipairs(words) do
|
||||
local new_word = with_word_cb(word, i, word)
|
||||
out = out .. new_word
|
||||
if separator and i > 1 then
|
||||
out = out .. separator
|
||||
end
|
||||
D.log('transformers', 'word %s new_word %s out %s', word, new_word, out)
|
||||
D.log("transformers", "word %s new_word %s out %s", word, new_word, out)
|
||||
end
|
||||
return out
|
||||
end
|
||||
@@ -74,7 +74,7 @@ function fn.to_snake_case(string)
|
||||
return word:lower()
|
||||
end
|
||||
return word:lower()
|
||||
end, '_')
|
||||
end, "_")
|
||||
end
|
||||
|
||||
--- Transforms a string into PascalCase.
|
||||
@@ -91,7 +91,7 @@ end
|
||||
function fn.to_title_case(string)
|
||||
return fn.transform_words(fn.to_words(string), function(word)
|
||||
return word:sub(1, 1):upper() .. word:sub(2):lower()
|
||||
end, ' ')
|
||||
end, " ")
|
||||
end
|
||||
|
||||
--- Transforms a string into kebab-case.
|
||||
@@ -100,7 +100,7 @@ end
|
||||
function fn.to_kebab_case(string)
|
||||
return fn.transform_words(fn.to_words(string), function(word)
|
||||
return word:lower()
|
||||
end, '-')
|
||||
end, "-")
|
||||
end
|
||||
|
||||
--- Transforms a string into dot.case.
|
||||
@@ -109,7 +109,7 @@ end
|
||||
function fn.to_dot_case(string)
|
||||
return fn.transform_words(fn.to_words(string), function(word)
|
||||
return word:lower()
|
||||
end, '.')
|
||||
end, ".")
|
||||
end
|
||||
|
||||
--- Transforms a string into CONSTANT_CASE.
|
||||
@@ -118,7 +118,7 @@ end
|
||||
function fn.to_const_case(string)
|
||||
return fn.transform_words(fn.to_words(string), function(word)
|
||||
return word:upper()
|
||||
end, '_')
|
||||
end, "_")
|
||||
end
|
||||
|
||||
return fn
|
||||
|
||||
Reference in New Issue
Block a user