Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename object/defaults to object/fillIn. Add lang/defaults and array/…
…find. `fillIn` describes better the action and avoids naming conflicts. `find` is required by `defaults` so "abstract ALL things!".
- Loading branch information
1 parent
bb8fbb4
commit 7fb9838
Showing
19 changed files
with
165 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
define(['./some'], function (some) { | ||
|
||
/** | ||
* Returns first item that matches criteria | ||
* @version 0.1.0 (2012/02/28) | ||
*/ | ||
function find(arr, iterator, thisObj){ | ||
var needle; | ||
some(arr, function(val, i, arr){ | ||
if (iterator.call(thisObj, val, i, arr)) { | ||
needle = val; | ||
return true; // stop loop | ||
} | ||
}); | ||
return needle; | ||
} | ||
|
||
return find; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
define(['./toArray', '../array/find'], function (toArray, find) { | ||
|
||
/** | ||
* Return first non void argument | ||
* @version 0.1.0 (2012/02/28) | ||
*/ | ||
function defaults(var_args){ | ||
return find(toArray(arguments), nonVoid); | ||
} | ||
|
||
function nonVoid(val){ | ||
return val != null; | ||
} | ||
|
||
return defaults; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
define(['src/array/find'], function (find) { | ||
|
||
describe('array/find', function () { | ||
|
||
it('should return first match', function () { | ||
|
||
var obj = {a : 'b'}, | ||
arr = [123, 'foo', 'bar', obj]; | ||
|
||
expect( find(arr, function(val){ return val === 123; }) ).toEqual( 123 ); | ||
expect( find(arr, function(val){ return typeof val === 'string'; }) ).toEqual( 'foo' ); | ||
expect( find(arr, function(val){ return val.a === 'b'; }) ).toEqual( obj ); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
define(['src/lang/defaults'], function (defaults) { | ||
|
||
describe('lang/defaults', function () { | ||
|
||
it('should return first non void value', function () { | ||
|
||
var a, | ||
b = null; | ||
|
||
expect( defaults(a, 'foo') ).toEqual( 'foo' ); | ||
expect( defaults(b, 'bar') ).toEqual( 'bar' ); | ||
expect( defaults(a, b, 123) ).toEqual( 123 ); | ||
expect( defaults(a, b, 123, 'dolor') ).toEqual( 123 ); | ||
expect( defaults(a, false, b, 123, 'dolor') ).toEqual( false ); | ||
expect( defaults(a, true, b, 123, 'dolor') ).toEqual( true ); | ||
|
||
var obj = {}; | ||
expect( defaults(obj, a, b, 123, 'dolor') ).toEqual( obj ); | ||
expect( defaults(a, b, obj, 123, 'dolor') ).toEqual( obj ); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters