sugarcubes
v1.2.0
Published
sweet JavaScript functions and extension
Downloads
13
Maintainers
Readme
#Sugarcubes.js
Enough Underscore, Lodash, Ramda... a lot of functionality can be replaced by ES6/ES7 https://github.com/reindexio/youmightnotneedunderscore
Issue of large libraries is that in real project you will use just a fraction of their functionality
Most of the concepts stay unused, or even not well understood
Though we need some sugar for vanilla JS
##Checks
Empty object
isempty({}); //true
isempty({foo: 'bar'}); //false
Empty array
isempty([]); //true
isempty(['bar']); //false
Undeclared variable
isset(x); //false
var y;
isset(y); //true
Blank string
''.isBlank(); //true
' '.isBlank(); //true
'bar'.isBlank(); //false
##Object
Get values
{first: 'foo', second: 'bar'}.values() //['foo', 'bar']
##Array
Remove items
['first', 'second', 'third', 'fourth'].remove(['second', 'third']) //['first', 'fourth']
Min and Max
[1, 3, 4, 8, 2].max() //8
[1, 3, 4, 8, 2].min() //1
##Log
log(obj) //logs object and its constructor
log(HTMLElement) //logs element as expandable DOM element and JS object
log(HTMLElement) //logs element as expandable DOM element and JS object
log('msg') //logs msg
log('msg', 'red') //logs in red color
log('msg', 'blue') //logs in blue color
log('msg', 'green') //logs in blue green