CaseConvert - Easy case type conversion

Case Convert

CaseConvertFinal

A plugin by @LuaBearyGood


DISCLAIMERS:

  • This plugin modifies the source of your script and any changes made cannot be undone (at least conveniently). This may change if I can finally figure out the craziness which is Roblox’s undo system.
  • As the person who wrote this plugin and tested it I myself do not have complete faith in the reliability of this plugin. By using this plugin you accept the risk that your code may become damaged and malformed during use.
  • This plugin will not convert a script if it detects the presence of typed Luau.

What is CaseConvert?

CaseConvert is a plugin that allows you to work with other programmers code at ease and can even be used to tidy up your variable names meaning you can… wait for it… read your old code!!!. It does this by using a lexer to collect local variables in a script which are then converted to your desired programming case and inserted into the script.

Here is an example in the plugin to show me making code written by a lunatic more readable:

How do I get this?

You can install this plugin from the Roblox website here:
https://www.roblox.com/library/8478933793/Case-Convert

Credits:

While I would love to take all the credit for this truly life changing plugin, I am merely a man standing on the shoulder of the giants which are:

@boatbomber - Who made the lexer and module that that collects and gives types to all the variables gathered by the lexer.

@jaschutte - Who created the logic for gathering a list of words from a variable name in addition to the code for identifying luau generics.

Without either of them this project simply would not have been possible so a huge thank you to them.


Final notes:

As I alluded to in the disclaimers section of this post, I do not have complete confidence in this module so if you do come across any bugs, firstly I apologise, but please do let me know and I will try to fix it as soon as I can.

I do want people to understand though that any bugs are not from my lack of trying to quash them, out of the 3 day development cycle of this plugin, I spent 2 days and at least 10 hours working with Jaschutte to try and refine the module to the point where at the time of releasing there are no bugs, big or small, that I am actively aware of.

In regards to the future of the plugin I want to add a way to modify your automatic preferences so you can e.g. set constants to UPPER_SNAKE and variables to pascal. I also want to apply the changes to function arguments and improve performance.

25 Likes

I don’t really see me ever using it but still a nice looking and could possibly be a usefull plugin for some people.

I was literally working on this lol

Could you release just the case conversion module for use in code?

1 Like
local CaseFunctions = {}

local function CapitalFirst(String)
	return String:sub(1,1):upper().. String:sub(2):lower()
end

function GetWords(VariableName)
	VariableName = VariableName:upper() == VariableName and VariableName:lower() or VariableName
	VariableName = VariableName:sub(1, 1):upper() .. VariableName:sub(2)

	VariableName = VariableName:gsub("_(.)", function(String) return String:upper() end)

	local Words = {}

	for Word in VariableName:gmatch("[A-Z][^A-Z]*") do
		Words[#Words+1] = Word
	end

	return Words
end

function CaseFunctions.ConvertToCamel(VariableName)
	local Words = GetWords(VariableName)
	local NewVariableName = string.lower(Words[1])

	for Index = 2, #Words do 
		NewVariableName = NewVariableName.. CapitalFirst(Words[Index])
	end

	return NewVariableName
end

function CaseFunctions.ConvertToPascal(VariableName)
	local Words = GetWords(VariableName)
	local NewVariableName = ''

	for Index = 1, #Words do 
		NewVariableName =  NewVariableName.. CapitalFirst(Words[Index])
	end

	return NewVariableName
end

function CaseFunctions.ConvertToSnake(VariableName)
	local Words = GetWords(VariableName)
	local NewVariableName = string.lower(Words[1])

	for Index = 2, #Words do 
		NewVariableName = NewVariableName.. '_'.. string.lower(Words[Index])
	end

	return NewVariableName
end

function CaseFunctions.ConvertToUpperSnake(VariableName)
	local Words = GetWords(VariableName)
	local NewVariableName = Words[1]

	for Index = 2, #Words do 
		NewVariableName = NewVariableName.. '_'.. Words[Index]
	end

	return string.upper(NewVariableName)
end

return CaseFunctions

Here is my case conversion module :slight_smile:

1 Like

Looks good but I don’t know why you would use it

It’s called ChangeHistoryService

Im aware of what change history service is, I recently filed a bug report about why it is buggy and barely works so that’s what I was referring to working around.

The main use of this module apart from me making jokes about camelCase users is making collaborating on projects with multiple programmers easier, since personally I can’t stand working in anything other then pascal case and I know many programmers are the same.

3 Likes

Update 1:

Just launched a small patch where the plugin was producing an undesired result wen encountering string concatenation using .. when there was a space after ... Sorry if this effected anyone, I didn’t encounter it during testing for some reason. I recommend you update the plugin ASAP.

1 Like

Cool, but not very necessary because casing usually doesn’t break the script.

You should maybe add a feature where it only cases what you’re selecting. Also maybe even the names of Instances! When I’m lazy I usually lowercase part names and have to go back and fix it because it looks better when cased a certain way. I’d definitely use this plugin if it does it on instances too.

I use lowercase :sunglasses:

How does it know what words/where to separate? Does it know English? :scream:

It doesn’t touch instances, anything inside tables simply because then it effects stuff outside the script too which can then just break your entire codebase.

For example if one script is referring to a part named ‘BluePart’ and the converted script is referring to it as ‘BLUE_PART’ then one of those scripts is going to break.

This would be avoided if you were converting your entire codebase to use the same casing but I wanted this plug-in to be for individual scripts.


Also your casing should never break code, the point of this plug-in is mainly to make working with other programmers code less stressful (since I know it can be annoying for say a PascalCase user to have to work with camelCase code)

2 Likes