Skip to content

steinfletcher/lodash-mix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lodash-mix

Build Status npm version

This isn't really maintained, but feel free to use it as a basis for your own mixins.

lodash mixins I've collected - for node and the browser.

To use in the browser, include lodash before including this library.

mixins

_.format

_.format('Other {} are {}', 'people', 'good plumbers')
// produces 'Other people are good plumbers'

_.format('/categ/{cat}/{isbn}', {cat: 'books', isbn: '034038204X'})
// produces '/categ/books/034038204X'

_.format('/categ/{cat}/{isbn}', 'books', '034038204X')
// produces '/categ/books/034038204X'

_.uuid

_.uuid()
// generates an RFC 4122 compliant version 4 uuid

_.isUuid

_.isUuid('262182b1-f92c-42bd-ab39-8faedb47b4dc')
// produces true|false. Validates an RFC 4122 compliant version 4 uuid

_.immutableMerge

_.immutableMerge({a: 1}, {b: 2})
// produces {a:1 , b:2} without mutating the input objects

_.upsert

var base = [{id: 1, data: 2}, {id: 2, data: 3}, {id: 3, data: {nested: 4}}];
var matcher = {id: 3, data: {nested: 4}}
var newElement = {id: 3, data: 5}
_.upsert(base, matcher, newElement);
// produces [{id: 1, data: 2}, {id: 2, data: 3}, {id: 3, data: 5}]

_.compactObject

_.compactObject({a: false, b: 4, c: {d: null}})
// produces {b: 4, c: {d: null}} removing properties with falsy values

_.compactObject({a: false, b: 4, c: {d: null}}, true)
// produces {b: 4, c: {}} removing nested properties with falsy values

_.ordinal

_.ordinal(142)
// produces 'nd'

tests

Tests run in node and the browser. Browserify and tape must be installed globally.

Execute from the command line

npm install -g tape
tape test/**/*.js