mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 16:39:00 +02:00
helpers: add toSnakeCase converter
This commit is contained in:
parent
ac0ef61339
commit
89cac08ac7
1 changed files with 16 additions and 0 deletions
|
@ -6,6 +6,22 @@ with lib; {
|
||||||
|
|
||||||
emptyTable = {"__empty" = null;};
|
emptyTable = {"__empty" = null;};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Convert a string from camelCase to snake_case
|
||||||
|
Type: string -> string
|
||||||
|
*/
|
||||||
|
toSnakeCase = let
|
||||||
|
splitByWords = builtins.split "([A-Z])";
|
||||||
|
processWord = s:
|
||||||
|
if isString s
|
||||||
|
then s
|
||||||
|
else "_" + toLower (elemAt s 0);
|
||||||
|
in
|
||||||
|
string: let
|
||||||
|
words = splitByWords string;
|
||||||
|
in
|
||||||
|
concatStrings (map processWord words);
|
||||||
|
|
||||||
mkIfNonNull' = x: y: (mkIf (x != null) y);
|
mkIfNonNull' = x: y: (mkIf (x != null) y);
|
||||||
|
|
||||||
mkIfNonNull = x: (mkIfNonNull' x x);
|
mkIfNonNull = x: (mkIfNonNull' x x);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue