Collection of reusable typed functions
Last active
July 31, 2019 06:04
-
-
Save jeremyswann/9a3447f21d44cc6b1c5579eb61d20a9e to your computer and use it in GitHub Desktop.
Utility Functions
This file contains hidden or 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
| //@ts-check | |
| /** | |
| * *Filter Array | |
| * Filter an array of objects by a specific key | |
| * @param {Array} array | |
| * @param {String} filterKey | |
| * @returns {Promise<String>} value of object | |
| */ | |
| async function filterArray(array, filterKey) { | |
| /** Array.prototype.filter() */ | |
| const result = await array.filter(object => object.key === filterKey) | |
| /** Destruct resulting array */ | |
| const [{ value }] = await result | |
| return value | |
| } |
This file contains hidden or 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
| //@ts-check | |
| /** | |
| * *Format Date | |
| * Format a datetime string to en-AU locale date | |
| * @param {String} datetime | |
| * @returns {Promise<String>} presentation date DD/MM/YYYY | |
| */ | |
| async function formatDate(datetime) { | |
| const date = await new Date(datetime) | |
| const day = await date.getDate() | |
| const month = (await date.getMonth()) + 1 | |
| const year = await date.getFullYear() | |
| return day + '/' + month + '/' + year | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment