Skip to content

Instantly share code, notes, and snippets.

@lloydjatkinson
Created June 19, 2018 09:59
Show Gist options
  • Save lloydjatkinson/16496bc7151aa357a54740d3ad7587c3 to your computer and use it in GitHub Desktop.
Save lloydjatkinson/16496bc7151aa357a54740d3ad7587c3 to your computer and use it in GitHub Desktop.
Vue filter for user friendly display of boolean values
/**
* 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