NamingConventions.jl is a lightweight and flexible Julia package that facilitates the conversion between various naming conventions commonly used in programming. The package supports the following conventions out-of-the-box:
CamelCase
: youTubeFlatCase
: youtubeKebabCase
: you-tubePascalCase
: YouTubeScreamingSnakeCase
: YOU_TUBESnakeCase
: you_tube
The flexibility of this package lies in its extensibility. By implementing your own encoding and decoding logic, you can create tailored naming conventions that fit your specific needs. All you need to do is define a new type that inherits from AbstractNamingConvention
and implement the encode
and decode
functions.
julia> ] add NamingConventions
Here is how you can easily convert between different naming styles:
using NamingConventions
# convert from snake_case to camelCase
@show NamingConventions.convert(SnakeCase, CamelCase, "snake_case") # output: "snakeCase"
# convert from camelCase to kebab-case
@show NamingConventions.convert(CamelCase, KebabCase, "camelCase") # output: "camel-case"
# convert from kebab-case to PascalCase
@show NamingConventions.convert(KebabCase, PascalCase, "kebab-case") # output: "KebabCase"
You can define your own naming conventions by creating a new type and implementing the required methods:
using NamingConventions
struct ReversePascalCase <: AbstractNamingConvention end
function NamingConventions.encode(::Type{ReversePascalCase}, v::AbstractString)
return join([lowercase(first(s)) * uppercase(s[2:end]) for s in v], "")
end
function NamingConventions.decode(::Type{ReversePascalCase}, s::AbstractString)
return lowercase.(split(s, r"(?<=[A-Z])(?=[a-z])|(?<=[a-z])(?=[a-z][A-Z])"))
end
# convert from camelCase to ReversePascalCase
@show NamingConventions.convert(CamelCase, ReversePascalCase, "camelCase") # output: "cAMELcASE"
# convert from snake_case to ReversePascalCase
@show NamingConventions.convert(SnakeCase, ReversePascalCase, "snake_case") # output: "sNAKEcASE"
Contributions, bug reports, and feature requests are welcome! Feel free to open an issue or submit a pull request.