ソースを参照

Add operations To {Snake,Camel,Kebab} case

toby 8 年 前
コミット
d5def01a9d

+ 1 - 0
package.json

@@ -72,6 +72,7 @@
     "jquery": "^3.1.1",
     "jsbn": "^1.1.0",
     "jsrsasign": "^7.1.0",
+    "lodash": "^4.17.4",
     "moment": "^2.17.1",
     "moment-timezone": "^0.5.11",
     "sladex-blowfish": "^0.8.1",

+ 3 - 0
src/core/config/Categories.js

@@ -181,6 +181,9 @@ const Categories = [
             "Parse UNIX file permissions",
             "Swap endianness",
             "Parse colour code",
+            "To Snake case",
+            "To Camel case",
+            "To Kebab case",
         ]
     },
     {

+ 42 - 0
src/core/config/OperationConfig.js

@@ -3249,6 +3249,48 @@ const OperationConfig = {
             },
         ]
     },
+    "To Snake case": {
+        description: [
+            "Converts the input string to snake case.",
+            "<br><br>",
+            "Snake case is all lower case with underscores as word boundaries.",
+            "<br><br>",
+            "e.g. this_is_snake_case",
+        ].join("\n"),
+        run: StrUtils.runToSnakeCase,
+        inputType: "string",
+        outputType: "string",
+        args: [
+        ]
+    },
+    "To Camel case": {
+        description: [
+            "Converts the input string to camel case.",
+            "<br><br>",
+            "Camel case is all lower case except letters after word boundaries which are uppercase.",
+            "<br><br>",
+            "e.g. thisIsCamelCase",
+        ].join("\n"),
+        run: StrUtils.runToCamelCase,
+        inputType: "string",
+        outputType: "string",
+        args: [
+        ]
+    },
+    "To Kebab case": {
+        description: [
+            "Converts the input string to kebab case.",
+            "<br><br>",
+            "Kebab case is all lower case with dashes as word boundaries.",
+            "<br><br>",
+            "e.g. this-is-kebab-case",
+        ].join("\n"),
+        run: StrUtils.runToKebabCase,
+        inputType: "string",
+        outputType: "string",
+        args: [
+        ]
+    },
 };
 
 export default OperationConfig;

+ 40 - 0
src/core/operations/StrUtils.js

@@ -1,3 +1,5 @@
+import {camelCase, kebabCase, snakeCase} from "lodash";
+
 import Utils from "../Utils.js";
 import * as JsDiff from "diff";
 
@@ -593,6 +595,44 @@ const StrUtils = {
         return output;
     },
 
+
+    /**
+     * Converts to snake_case.
+     *
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     *
+     */
+    runToSnakeCase(input, args) {
+        return snakeCase(input);
+    },
+
+
+    /**
+     * Converts to camelCase.
+     *
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     *
+     */
+    runToCamelCase(input, args) {
+        return camelCase(input);
+    },
+
+
+    /**
+     * Converts to kebab-case.
+     *
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     *
+     */
+    runToKebabCase(input, args) {
+        return kebabCase(input);
+    },
 };
 
 export default StrUtils;