-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Omar-Belghaouti/chore/dry-utils
Chore: DRY utilities
- Loading branch information
Showing
8 changed files
with
64 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @function getComponentName | ||
* @description Get the name of the component | ||
* @param {string} name - name of component. | ||
* @example getComponentName("component-name"); | ||
* @returns {string} "ComponentName" | ||
* @author [Omar Belghaouti](https://github.com/Omar-Belghaouti) | ||
*/ | ||
exports.getComponentName = (name) => { | ||
let component = name.charAt(0).toUpperCase() + name.slice(1); | ||
if (name.includes("-")) { | ||
component = ""; | ||
let words = name.split("-"); | ||
words.forEach((w) => { | ||
component += w.charAt(0).toUpperCase() + w.slice(1); | ||
}); | ||
} | ||
return component; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
const { config } = require("./configs"); | ||
const { loadConfig } = require("./load-config"); | ||
const { rootChecker } = require("./root-checker"); | ||
const { languageChecker } = require("./language-checker"); | ||
const { getComponentName } = require("./get-component-name"); | ||
|
||
exports.config = config; | ||
exports.loadConfig = loadConfig; | ||
exports.rootChecker = rootChecker; | ||
exports.languageChecker = languageChecker; | ||
exports.getComponentName = getComponentName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const fs = require("file-system"); | ||
|
||
/** | ||
* @function languageChecker | ||
* @description Checks if the react project is written in javascript or typescript. | ||
* @returns {string} "js" if the project is written in javascript and "ts" if the project is written in typescript. | ||
* @author [Omar Belghaouti](https://github.com/Omar-Belghaouti) | ||
*/ | ||
exports.languageChecker = () => { | ||
let faf = fs.readdirSync("."); // folders and files | ||
for (let i = 0; i < faf.length; i++) { | ||
if (faf[i].endsWith("tsx")) { | ||
return "ts"; | ||
} | ||
} | ||
return "js"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fs = require("file-system"); | ||
|
||
/** | ||
* @function rootChecker | ||
* @description Check if the current directory is the root of a react project. | ||
* @returns {boolean} true if the current directory is the root of a react project. | ||
* @author [Omar Belghaouti](https://github.com/Omar-Belghaouti) | ||
*/ | ||
exports.rootChecker = () => { | ||
return fs.existsSync("package.json"); | ||
}; |