Below is a list of some of the methods available from Rebuy util. These are helper functions and context for their application can vary greatly.
const util = window.Rebuy.util;
amountToCents
This method accepts a number or a string of numbers and returns the absolute value of the number to the hundredth decimal.
util.amountToCents(amount);
util.amountToCents(159.59);
// Expected Output: 15959
debounce
This method takes a callback function, number and optional boolean.
util.debounce(fn, wait, immediate);
filterArray
util.filterArray(items, filters, possessive);
formatMoney
This method takes a number and returns a string which is a DOM element (span) with the number formatted.
util.formatMoney(cents, format);
Rebuy.util.formatMoney(1299);
// Expected Output: '<span class="money">$12.99</span>'
formatNumber
Takes a number or string of numbers and returns a formatted string with comma separators and decimal places.
util.formatNumber(number, decimal_count, thousands_separator, decimial_separator);
Rebuy.util.formatNumber(1562, 2, ",", ".");
// Expected Output: '1,562.00'
getLocation
Returns an object containing information about the current url or the url that is passed in as an argument.
util.getLocation(url);
util.getLocation();
// Expected Output:
// { hash: ""
// host: "example-brand.com"
// hostname: "example-brand.com"
// href: "https://example-brand.com/?preview=true"
// pathname: "/"
// port: undefined
// protocol: "https:"
// search: "?preview=true" }
isRebuyItem
This method takes an item object as an argument and returns a boolean (true) if the specified item was added via a Rebuy widget.
util.isRebuyItem(item);
numberWithCommas
Returns a string of comma separated numbers.
util.numberWithCommas(num);
util.numberWithCommas(1563);
// Expected Output: '1,563'
productImage
util.productImage(product, size);
randomRange
Returns a random number between the specified min and max numbers passed in as arguments.
util.randomRange(min, max);
timestamp
util.timestamp();
wait
Will call the callback function which is the first argument after the time in milliseconds which is the second argument expected to be a number.
util.wait(callback, ms);