Methods
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.
amountToCents¶
This method accepts a number or a string of numbers and returns the absolute value of the number to the hundredth decimal.
debounce¶
This method takes a callback function, number and optional boolean.
filterArray¶
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.
numberWithCommas¶
Returns a string of comma separated numbers.
productImage¶
randomRange¶
Returns a random number between the specified min and max numbers passed in as arguments.
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.
--- title: Methods excerpt: '' deprecated: false hidden: false metadata: title: '' description: '' robots: index next: description: '' --- 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. ```javascript 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. ```javascript util.amountToCents(amount); util.amountToCents(159.59); // Expected Output: 15959 ``` ## debounce This method takes a callback function, number and optional boolean. ```javascript util.debounce(fn, wait, immediate); ``` ## filterArray ```javascript 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. ```javascript 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. ```javascript 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. ```javascript 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. ```javascript util.isRebuyItem(item); ``` ## numberWithCommas Returns a string of comma separated numbers. ```javascript util.numberWithCommas(num); util.numberWithCommas(1563); // Expected Output: '1,563' ``` ## productImage ```javascript util.productImage(product, size); ``` ## randomRange Returns a random number between the specified min and max numbers passed in as arguments. ```javascript util.randomRange(min, max); ``` ## timestamp ```javascript 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. ```javascript util.wait(callback, ms); ```