Module FILLZ.UTIL.v1

Provides general-purpose utility functions.

Module Summary

Using days_old

var item = FILLZ.ITEM.v1
var util = FILLZ.UTIL.v1
debug( 'This item is '+util.days_old(item.open_date)+' day(s) old')

Using format_currency

var util = FILLZ.UTIL.v1
util.format_currency(14.999);  //"14.99"
util.format_currency(14.0123); //"14.01"
util.format_currency(0);       //"0.00"
util.format_currency(.01);     //"0.01"
util.format_currency(.001);    //"0.00"
util.format_currency(10);      //"10.00"

Using difference_in_cents

var util = FILLZ.UTIL.v1
util.difference_in_cents(10,10.00001) // == 0 (equal)
util.difference_in_cents(10,9.9999)   // == 0 
util.difference_in_cents(1,1.1)       // == -10  
util.difference_in_cents(10,9)        // == 100
util.difference_in_cents(0.1+0.2,0.3) // == 0

Using shipping_by_type

var util = FILLZ.UTIL.v1;
var shipping = util.shipping_by_type('book', 9.99);
debug('shipping cost for book is '+shipping+' on '+FILLZ.venue); //outputs "shipping cost for book is 3.99 on amazon"

Methods

  • days_old(date)

    Returns the number of days between date and now.

    Parameters

    • date -- a Date object

    Returns

    • The number of days between date and current time, as maximum number of whole days. If the difference is less than 24 hours, then the function returns 0.
  • format_currency(price)

    Formats a number as currency, with exactly 2 digits after decimal point and at least 1 before.

    Parameters

    Returns

    • A String of price in currency format.
  • difference_in_cents(price1,price2)

    Computes difference two numbers as currency.

    Parameters

    Returns

    • A number representing the difference between price1 and price2 in cents.
      • == 0 -- the prices are equal
      • < 0 -- price1 is smaller than price2
      • > 0 -- price1 is greater than price2
  • shipping_by_type(type,default,venue)

    Provides typical shipping matrix values for the current venue.

    Parameters

    • type -- product type from the Amazon.com catalog (FILLZ.ITEM.v1.type)
    • default -- (optional) price to return if shipping value unknown
    • venue -- (optional) venue to predict shipping for (default is FILLZ.venue)

      Returns

    • A number providing the shipping cost an item of the given type will probably have, or undefined.