Created
June 19, 2018 09:59
-
-
Save lloydjatkinson/16496bc7151aa357a54740d3ad7587c3 to your computer and use it in GitHub Desktop.
Vue filter for user friendly display of boolean values
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
/** | |
* Returns a string representing the truthy/falsy value of the given value. Defaults to "Yes" or "No". | |
* @param {*} value The value to determine the truthy/falsy value of. | |
* @param {String} truthyString The string to use if the value is truthy. | |
* @param {String} falsyString The string to use if the value is falsy. | |
* @example {{ userSelected | boolean }} | |
* @example {{ userSelected | boolean('Included', 'Not Included') }} | |
*/ | |
const booleanFilter = (value, truthyString, falsyString) => | |
value | |
? truthyString | |
? truthyString | |
: 'Yes' | |
: falsyString | |
? falsyString | |
: 'No'; | |
export default booleanFilter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment