• Jump To … +
    assert_Array.litcoffee assert_Boolean.litcoffee assert_Function.litcoffee assert_Number.litcoffee assert_Object.litcoffee assert_String.litcoffee fluentnode.coffee index.md Array.litcoffee Boolean.litcoffee Function.litcoffee Number.litcoffee Object.litcoffee String.litcoffee console.litcoffee crypto.litcoffee fs.litcoffee http.litcoffee path.litcoffee process.litcoffee encoding.litcoffee globals.litcoffee assert_Array.test.coffee assert_Boolean.test.coffee assert_Function.test.coffee assert_Number.test.coffee assert_Object.test.coffee assert_String.test.coffee fluentnode.test.coffee Array.test.coffee Boolean.test.coffee Function.test.coffee Number.test.coffee Object.test.coffee String.test.coffee console.test.coffee crypto.test.coffee fs.test.coffee http.test.coffee path.test.coffee process.test.coffee encoding.test.coffee globals.test.coffee
  • Number.litcoffee

  • ¶

    Adds helper methods to the native javascript Number class

    @.add value

    Returns @ incremented by value

    If value is not a number the original value is returned unmodifed

    Note that the original @ value is not modified

    Number::add = (value)->
      if is_Number(value)
        @ + value
      else
        @
  • ¶

    @.dec [value]

    Returns @ decremented by 1 or by [value] (if provided)

    Note that the original @ value is not modified

    Number::dec = (value)->
      if is_Number(value)
        @ - value
      else
        @ - 1
  • ¶

    @.in_Between min, max

    Returns true if @ is between min and max for example

    (10).in_Between(5,15)  # returns true
    (10).in_Between(10,15) # returns false
    (10).in_Between(50,50) # returns false
    
    Number::in_Between = (min,max )->
        (min < @ < max)
  • ¶

    @.inc [value]

    Returns @ incremented by 1 or by [value] (if provided)

    Note that the original @ value is not modified

    Number::inc = (value)->
      if is_Number(value)
        @ + value
      else
        @ + 1
  • ¶

    @.invoke_After callback

    Invokes the callback function after @ miliseconds

    Number::invoke_After = (callback)->
        if callback instanceof Function
            setTimeout callback, @
    
    Number::wait = Number::invoke_After
  • ¶

    @.is_Number

    Returns true if @ is a number

    Returns false if @ is NaN (i.e. Not a Number)

    Number::is_Number = ->
      return @ instanceof Number and @.str().is_Not('NaN')
  • ¶

    @.log

    Logs @ to the console

    Number::log =
      -> console.log @.toString()
  • ¶

    @.random

    returns a random number between 0 and @

    Number::random = -> ~~(Math.random()*@)
  • ¶

    @.str

    Short version of toString

    Number::str = -> @.toString()


  • ¶

    back to index