1.0.4 • Published 10 years ago
underline v1.0.4
Underline.js - Underscore.js for modern Javascript
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:
- Install this library using npm -
npm install --save underline - Import functions as needed -
import { map } from 'underline' - 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.
iterateeforEacheachcollectmapinjectfoldlreducefoldrreduceRightdetectfindselectfilterrejectalleveryanysomeincludeincludescontainsinvokepluckwherefindWheremaxminshufflesamplesortBygroupByindexBycountBytoArraysizepartitiontakeheadfirstinitiallastdroptailrestcompactflattenwithoutuniqueuniqunionintersectiondifferencezipunzipobjectfindIndexfindLastIndexsortedIndexindexOflastIndexOfrangebindpartialbindAllmemoizedelaydeferthrottledebouncewrapnegatecomposeafterbeforeoncekeysallKeysvaluesmapObjectpairsinvertmethodsfunctionsextendassignextendOwnfindKeypickomitdefaultscreateclonetapisMatchisEqualisEmptyisElementisArrayisObjectisArgumentsisFunctionisStringisNumberisDateisRegExpisErrorisFiniteisNaNisBooleanisNullisUndefinedhasnoConflictidentityconstantnooppropertypropertyOfmatchesmatchertimesrandomnowescapeunescaperesultuniqueIdtemplateSettingstemplatechainmixin