Skip to content

Instantly share code, notes, and snippets.

@Clickys
Last active October 24, 2018 06:35
Show Gist options
  • Save Clickys/f86cf7df186c4535e866ca7b2983b56f to your computer and use it in GitHub Desktop.
Save Clickys/f86cf7df186c4535e866ca7b2983b56f to your computer and use it in GitHub Desktop.
test
function checkCurrencyFormat(format) {
var defaults = lib.settings.currency.format;
// Allow function as format parameter (should return string or object):
if ( typeof format === "function" ) format = format();
// Format can be a string, in which case `value` ("%v") must be present:
if ( isString( format ) && format.match("%v") ) {
// Create and return positive, negative and zero formats:
return {
pos : format,
neg : format.replace("-", "").replace("%v", "-%v"),
zero : format
};
// If no format, or object is missing valid positive value, use defaults:
} else if ( !format || !format.pos || !format.pos.match("%v") ) {
// If defaults is a string, casts it to an object for faster checking next time:
return ( !isString( defaults ) ) ? defaults : lib.settings.currency.format = {
pos : defaults,
neg : defaults.replace("%v", "-%v"),
zero : defaults
};
}
// Otherwise, assume format was fine:
return format;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment