-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helpers): add typing map functions ✨
- Loading branch information
1 parent
b84dea1
commit 18a7d66
Showing
3 changed files
with
78 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const path = require('path'); | ||
const _ = require('lodash'); | ||
|
||
const AppError = require(path.resolve('./lib/helpers/AppError')); | ||
|
||
/** | ||
* @desc STRING_MAP_TO_STRING | ||
*/ | ||
exports.STRING_MAP_TO_STRING = (data, params) => { | ||
const choices = params.map((value) => value.split('=')[0]); | ||
const find = choices.indexOf(data); | ||
if (find > -1) return String(params[find].split('=')[1]); | ||
throw new AppError('Typing : STRING_MAP_TO_STRING'); | ||
}; | ||
|
||
/** | ||
* @desc STRING_MAP_TO_STRING_CAMEL | ||
*/ | ||
exports.STRING_MAP_TO_STRING_CAMEL = (data, params) => { | ||
const choices = params.map((value) => _.camelCase(value.split('=')[0])); | ||
const find = choices.indexOf(_.camelCase(data)); | ||
if (find > -1) return String(params[find].split('=')[1]); | ||
throw new AppError('Typing : STRING_MAP_TO_STRING_CAMEL'); | ||
}; | ||
|
||
|
||
/** | ||
* @desc STRING_MAP_TO_NUMBER | ||
*/ | ||
exports.STRING_MAP_TO_NUMBER = (data, params) => { | ||
const choices = params.map((value) => value.split('=')[0]); | ||
const find = choices.indexOf(data); | ||
if (find > -1) return Number(params[find].split('=')[1]); | ||
throw new AppError('Typing : STRING_MAP_TO_NUMBER'); | ||
}; | ||
|
||
/** | ||
* @desc STRING_MAP_TO_NUMBER_CAMEL | ||
*/ | ||
exports.STRING_MAP_TO_NUMBER_CAMEL = (data, params) => { | ||
const choices = params.map((value) => _.camelCase(value.split('=')[0])); | ||
const find = choices.indexOf(_.camelCase(data)); | ||
if (find > -1) return Number(params[find].split('=')[1]); | ||
throw new AppError('Typing : STRING_MAP_TO_NUMBER_CAMEL'); | ||
}; |