Skip to content

Support, Helpers, and Utils

Lance Pollard edited this page Oct 17, 2012 · 5 revisions

Helpers and such included in Tower.

Geocoordinates

User.within(miles: 10)

Array

  • extractArgs (args)
  • extractOptions
  • extractBlock
  • sortBy

Number

  • isInt
  • isFloat

Object

  • cloneHash
  • cloneArray
  • deepMerge
  • deepMergeWithArray
  • alias
  • defineProperty
  • accessor
  • getter
  • setter
  • methods
  • delegate
  • isHash
  • kind
  • isPresent
  • isBlank
  • has
  • isA

Function

  • functionName

String

  • parameterize
  • constantize
  • camelize
  • underscore
  • singularize
  • pluralize
  • capitalize
  • interpolate
  • trim

RegExp

  • regexpEscape

Date

  • now
  • date

Helpers

Most helpers in Tower are included in the underscore _ namespace, because they are generic enough to be useable outside of Tower itself. The rest are included in the Tower namespace.

Tower Helpers

Tower.urlFor
Tower.get
Tower.post
Tower.put
Tower.action
Tower.constant

Underscore Helpers

String Helpers

_.pluralize

_.pluralize('business')   #=> 'businesses'
_.pluralize('businesses') #=> 'businesses'
_.pluralize('person')     #=> 'people'
_.pluralize('people')     #=> 'people'

_.singularize

_.singularize('business')   #=> 'business'
_.singularize('businesses') #=> 'business'
_.singularize('person')     #=> 'person'
_.singularize('people')     #=> 'person'

Object Helpers

_.isHash

_.isHash({})                #=> true
_.isHash({key: 'value'})    #=> true
_.isHash(new App.User)      #=> false

_.isObject

_.isObject({})              #=> true
_.isObject({key: 'value'})  #=> true
_.isObject(new App.User)    #=> true

Date Helpers

_(number)[interval]()[timeframe]()
_(2).days().fromNow().toDate()
_(3).years().ago().toDate()
_('Dec 25, 2012').toDate()

Validation Helpers

Formatting Helpers

The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in US and Canadian Social Insurance Numbers. It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.

Resources

Clone this wiki locally