Dress is a javascript helper library which includes basic functional programming methods and commonly used shortcuts. You can use Dress for your browser application or your node.js application.
Note: This library is still experimental, please do not use this in a production project for now. Many methods may change or delete until the beta or stable version release.
Installation
Node.js
To use Dress in your node project, first install the module.
npm install dress
After npm installation run this command in the beggining of your project.(e.g. app.js)
;
Browser
Download index.min.js
and load in the beggining of head tag.
Arrays
$map
1 2 3; 2 3 4
$$map
array = 1 2 3 array console 2 3 4
$first
5 3 2 6 5
$last
5 3 2 6 6
$find
people = name: 'Albert Einstein' birthPlace: 'Ulm, Germany' name: 'Nikola Tesla' birthPlace: 'Smiljan, Croatia' peoplebirthPlace "Smiljan, Croatia"
$contains
1 4 9 3 true
1 4 9 3 false
$max
5 3 -2 11 -3 11
$min
5 3 -2 11 -3 -3
$sort
5 3 -2 11 -3 -3 -2 3 5 11
array = a: 1 b: 6 a: 9 b: 3 b: 7 c: 1 array a: 9 b: 3 a: 1 b: 6 b: 7 c: 1
$$sort
array = 5 3 -2 11 -3 array console -3 -2 3 5 11
$sample
5 3 -2 11 -3 11
5 3 -2 11 -3 3
$samples
5 3 -2 11 -3 -3 5
5 3 -2 11 -3 11
$$samples
array = 5 3 -2 11 -3 array console 11 -2
$each
array = 5 3 -2 array 5 3 -2
$where
array = a: 1 b: 2 a: 2 c: 8 a: -5 c: 8 array a: 2 c: 8 a: -5 c: 8
array a: 2 c: 8
$$where
array = a: 1 b: 2 a: 2 c: 8 a: -5 c: 8 array console a: -5 c: 8
$reject
1 2 3 4 5 6 1 3 5
$$reject
array = 1 2 3 4 5 6 array console 1 3 5
$take
4 2 8 3 4 2
$$take
array = 4 2 8 3 array console 4 2 8
$drop
4 2 8 3 8 3
$$drop
array = 4 2 8 3 array console 2 8 3
$invoke
1 4 2 3 2 5 2 5
$$invoke
array = 1 4 2 3 2 5 array console 2 5
$pluck
a: 1 b: 2 a: 7 b: 6 a: 9 1 7 9
$$pluck
array = a: 1 b: 2 a: 7 b: 6 a: 9 array console 1 7 9
$group
array = 17 43 49 array '1': 17 '4': 43 49
array = 'this' 'is' 'test' array '2' : 'is' '4': 'this' 'test'
$count
array = 1 2 3 4 5 array odd: 3 even: 2
$shuffle
1 2 3 4 5 3 5 1 4 2 1 2 3 4 5 2 4 3 5 1
$$shuffle
array = 1 2 3 4 5 array console 4 1 2 5 3
Objects
$pick
a: 1 b: 2 c: 3 d: 4 a: 1 d: 4
$$pick
object = a: 1 b: 2 c: 3 d: 4 object console a: 1 d: 4
$keys
a: 1 b: 2 c: 3 d: 4 'a' 'b' 'c' 'd'
$values
a: 1 b: 2 c: 3 d: 4 1 2 3 4
$invert
a: 1 b: 2 c: 3 '1': 'a' '2': 'b' '3': 'c'
$$invert
object = a: 1 b: 2 c: 3 object console '1': 'a' '2': 'b' '3': 'c'
$each
object = a: 1 b: 2 c: 3 result = object console 1 2 3
$pairs
a: 1 b: 2 c: 3 'a' 1 'b' 2 'c' 3
$functions
object = a: 1 b: 2 { return 'I am the function'; } object 'c'
$merge
a: 1 b: 2 a: 1 b: 2 c: 3 d: 4
$$merge
object = a: 1 b: 2 object console a: 1 b: 2 c: 3 d: 4
$omit
a: 1 b: 2 c: 3 a: 1
a: 1 b: 2 c: 3 b: 2
$$omit
object = a: 1 b: 2 c: 3 object console c: 3
$defaults
a: 1 b: 2 c: 3 a: 1 b: 2 c: 3 e: 9
$$defaults
object = a: 1 b: 2 c: 3 object console a: 1 b: 2 c: 3 e: 9
$clone
object = a: 1 b: 2 object2 = object console a: 1 b: 2 console false
$tap
object = a: 1 b: 2 result = false { result = true } object a: 1 c: 1 console true
$isFunction
{ } true name: 'Walter White' false
$isArray
true { } false
$isEmpty
{} true a: 1 false
$isString
"woo" true false
$isNumber
4 true {} false
$isBoolean
true true "true" false
$isDate
true "Date" false
$json
a: 12 b: 'hey' '{"a":12,"b":"hey"}' 1 2 3 '[1,2,3]'
Strings
$starts
'This is a test string' true 'This is a test string' false
$ends
'This is a test string' true 'This is a test string' false
$capitalize
'nikola tesla' 'Nikola tesla'
$titleize
'nikola tesla' 'Nikola Tesla'
$integer
'2014' 2014 '2.43' 2
$number
'2.12' 212
$date
'10.10.2010 10:11:12' 1286694672000
$parse
'{ "a": 12, "b": "test" }' a: 12 b: 'test'
Numbers
$times
result = 5 console 0 1 2 3 4
$date
1286658123123 Sun Oct 10 2010 00:02:03 GMT+
License
The MIT License (MIT)
Copyright (c) 2014 Ali Davut
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.