2018-05-26 19:04:53 +02:00
/ * *
* @ author tlwr [ toby @ toby . codes ]
* @ copyright Crown Copyright 2017
* @ license Apache - 2.0
* /
2019-07-09 13:23:59 +02:00
import snakeCase from "lodash/snakeCase.js" ;
import Operation from "../Operation.mjs" ;
import { replaceVariableNames } from "../lib/Code.mjs" ;
2018-05-26 19:04:53 +02:00
/ * *
* To Snake case operation
* /
class ToSnakeCase extends Operation {
/ * *
* ToSnakeCase constructor
* /
constructor ( ) {
super ( ) ;
this . name = "To Snake case" ;
this . module = "Code" ;
this . description = "Converts the input string to snake case.\n<br><br>\nSnake case is all lower case with underscores as word boundaries.\n<br><br>\ne.g. this_is_snake_case\n<br><br>\n'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names." ;
2018-08-21 20:07:13 +02:00
this . infoURL = "https://wikipedia.org/wiki/Snake_case" ;
2018-05-26 19:04:53 +02:00
this . inputType = "string" ;
this . outputType = "string" ;
this . args = [
{
"name" : "Attempt to be context aware" ,
"type" : "boolean" ,
"value" : false
}
] ;
}
/ * *
* @ param { string } input
* @ param { Object [ ] } args
* @ returns { string }
* /
run ( input , args ) {
const smart = args [ 0 ] ;
if ( smart ) {
return replaceVariableNames ( input , snakeCase ) ;
} else {
return snakeCase ( input ) ;
}
}
}
export default ToSnakeCase ;