1.0.4 • Published 8 years ago

underline v1.0.4

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

Underline.js - Underscore.js for modern Javascript

npm package Dependency Status

Using modern ES7 functional bind :: syntax you can now call the underscore.js function the 'right' or non-functional way. underline.js is a thin layer between your code and underscore.js which binds all underscore functions called to the target object.

Example

import { difference, all, keys, pluck } from 'underline'; // Require functions needed

// Differece of arrays
[12, 1, 2, 3, 10, 11]::difference([10, 11, 12])
// => [1, 2, 3]

// Check for all elements are less than 10
[1, 2, 3, 10]::all((e) => e < 10)
// => false

// Extract Keys
{ a: 1, b: 2 }::keys()
// => ["a", "b"]

// Pluck property
[
  {name: 'moe', age: 40},
  {name: 'larry', age: 50},
  {name: 'curly', age: 60}
]::pluck('name')
// => ["moe", "larry", "curly"]

/////
// VS
/////

// Underscore way for difference
_.difference([12, 1, 2, 3, 10, 11], [10, 11, 12])

// all
_.all([1, 2, 3, 10], (e) => e < 10)

// keys
_.keys({ a: 1, b: 2})
// OR
Object.keys({ a: 1, b: 2})

// and pluck
_.pluck([
  {name: 'moe', age: 40},
  {name: 'larry', age: 50},
  {name: 'curly', age: 60}
], 'name')

Underline supports chaining without wrapping like underscore

// Chaining difference and all
[12, 1, 2, 3, 10, 11]::difference([10, 11, 12])
                     ::all((e) => e < 10)
// => true

/////
// VS
/////

// Too much typing to chain in underscore and get its value
_.chain([12, 1, 2, 3, 10, 11]).difference([10, 11, 12])
                              .all((e) => e < 10)
                              .value()

Try it

Try it out in the REPL

Usage

To get started you will need to use Babel transpiler with experimental feature es7.functionBind enabled. Then:

  1. Install this library using npm - npm install --save underline
  2. Import functions as needed - import { map } from 'underline'
  3. Call a function using :: operator as such [1, 2, 3]::map((e) => e * 10)

Functions Available

All of the functions available in underscore.js are available in underline.js.

  • iteratee
  • forEach
  • each
  • collect
  • map
  • inject
  • foldl
  • reduce
  • foldr
  • reduceRight
  • detect
  • find
  • select
  • filter
  • reject
  • all
  • every
  • any
  • some
  • include
  • includes
  • contains
  • invoke
  • pluck
  • where
  • findWhere
  • max
  • min
  • shuffle
  • sample
  • sortBy
  • groupBy
  • indexBy
  • countBy
  • toArray
  • size
  • partition
  • take
  • head
  • first
  • initial
  • last
  • drop
  • tail
  • rest
  • compact
  • flatten
  • without
  • unique
  • uniq
  • union
  • intersection
  • difference
  • zip
  • unzip
  • object
  • findIndex
  • findLastIndex
  • sortedIndex
  • indexOf
  • lastIndexOf
  • range
  • bind
  • partial
  • bindAll
  • memoize
  • delay
  • defer
  • throttle
  • debounce
  • wrap
  • negate
  • compose
  • after
  • before
  • once
  • keys
  • allKeys
  • values
  • mapObject
  • pairs
  • invert
  • methods
  • functions
  • extend
  • assign
  • extendOwn
  • findKey
  • pick
  • omit
  • defaults
  • create
  • clone
  • tap
  • isMatch
  • isEqual
  • isEmpty
  • isElement
  • isArray
  • isObject
  • isArguments
  • isFunction
  • isString
  • isNumber
  • isDate
  • isRegExp
  • isError
  • isFinite
  • isNaN
  • isBoolean
  • isNull
  • isUndefined
  • has
  • noConflict
  • identity
  • constant
  • noop
  • property
  • propertyOf
  • matches
  • matcher
  • times
  • random
  • now
  • escape
  • unescape
  • result
  • uniqueId
  • templateSettings
  • template
  • chain
  • mixin
1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago