-
-
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(apis): clean typing for meteo ✨
- Loading branch information
1 parent
751adc9
commit aef85b3
Showing
8 changed files
with
98 additions
and
54 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,41 @@ | ||
const moment = require('moment'); | ||
const _ = require('lodash'); | ||
const path = require('path'); | ||
|
||
const AppError = require(path.resolve('./lib/helpers/AppError')); | ||
|
||
/** | ||
* @desc _DATE | ||
*/ | ||
exports.DATE = (data) => { | ||
let date = moment(data).format(); | ||
// fixs | ||
if (date === 'Invalid date') { | ||
const dateSplit = data.split('-'); | ||
if (dateSplit.length === 3) date = moment(`${dateSplit[0]}-${dateSplit[1]}`).add(Number(dateSplit[2]) - 1, 'days').format(); // Hot Fix if date containe more dats than a month | ||
else throw new AppError(`Typing : date invalid ${data}`, { code: 'HELPERS_ERROR', details: date }); | ||
} | ||
return date; | ||
}; | ||
|
||
/** | ||
* @desc _DATE_NEXT_DAY | ||
*/ | ||
exports.DATE_NEXT_DAY = (data) => { | ||
let date; | ||
const target = Number(data); | ||
const today = Number(moment().date()); | ||
if (target >= today) date = moment().add(target - today, 'days').format(); | ||
else date = moment().add(1, 'months').subtract(today - target, 'days').format(); | ||
return date; | ||
}; | ||
|
||
/** | ||
* @desc HOUR | ||
*/ | ||
exports.HOUR = (data, param, object) => { | ||
if (param) { | ||
return moment(_.get(object, param)).set('hour', Number(data)).format(); | ||
} | ||
return moment(_.get(object, param)).format(); | ||
}; |
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,13 @@ | ||
/** | ||
* @desc NUMBER | ||
*/ | ||
exports.NUMBER = (data) => { | ||
data = String(data).replace(/,/g, '.'); // switch , to . | ||
data = String(data).replace(/[^\d.-]/g, ''); // remove if it's not digit | ||
return Number(data); | ||
}; | ||
|
||
/** | ||
* @desc STRING | ||
*/ | ||
exports.STRING = (data) => String(data); |
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