camelcase

function camelcase( strlst ) --> str

Description

Concatenate the assigned words in the array table to a camel case string.

Parameters

strlst

An array table with strings.

Return Values

str

The generated camel case string.

Code

--ZFUNC-camelcase-v1
local function camelcase( strlst ) --> str
   --ZFUNC-cutstr-v1
   local function cutstr( str, n )
      return str:sub( 1, n ), str:sub( n + 1, #str )
   end

   local str = {}
   for i, v in ipairs( strlst ) do
      local left, right = cutstr( v, 1 )
      table.insert( str, string.upper( left ) )
      table.insert( str, string.lower( right ) )
   end
   return table.concat( str )
end

return camelcase

Examples

local t = require( "tapered" )
local camelcase = require( "camelcase" )

-- with table as argument
t.is( "WikiWordBumpyCaps", camelcase{ "Wiki", "Word", "bumpy", "Caps" } )

t.done()

Inspired by

See also