fizzy-ui-utils
Advanced tools
Comparing version 2.0.5 to 2.0.6
{ | ||
"name": "fizzy-ui-utils", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "UI utilities", | ||
@@ -5,0 +5,0 @@ "main": "utils.js", |
@@ -19,4 +19,4 @@ QUnit.test( 'makeArray', function( assert ) { | ||
var empty = makeArray(); | ||
assert.ok( Array.isArray( empty ), 'makeArray on undefined is array' ); | ||
assert.equal( empty.length, 1, 'length = 1' ); | ||
assert.deepEqual( empty, [], 'makeArray on undefined is empty array' ); | ||
assert.equal( empty.length, 0, 'length = 0' ); | ||
assert.ok( empty[0] === undefined, '[0] is undefined' ); | ||
@@ -28,2 +28,9 @@ | ||
var nullAry = makeArray( null ); | ||
assert.deepEqual( nullAry, [], 'makeArray(null) returns empty array' ); | ||
var falseAry = makeArray( false ); | ||
assert.deepEqual( falseAry, [ false ], 'makeArray(false) returns array with false' ); | ||
assert.equal( falseAry.length, 1, 'falseyAry has 1 item' ); | ||
}); |
42
utils.js
/** | ||
* Fizzy UI utils v2.0.5 | ||
* Fizzy UI utils v2.0.6 | ||
* MIT license | ||
@@ -57,19 +57,23 @@ */ | ||
var arraySlice = Array.prototype.slice; | ||
// turn element or nodeList into an array | ||
utils.makeArray = function( obj ) { | ||
var ary = []; | ||
if ( Array.isArray( obj ) ) { | ||
// use object if already an array | ||
ary = obj; | ||
} else if ( obj && typeof obj == 'object' && | ||
typeof obj.length == 'number' ) { | ||
return obj; | ||
} | ||
// return empty array if undefined or null. #6 | ||
if ( obj === null || obj === undefined ) { | ||
return []; | ||
} | ||
var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number'; | ||
if ( isArrayLike ) { | ||
// convert nodeList to array | ||
for ( var i=0; i < obj.length; i++ ) { | ||
ary.push( obj[i] ); | ||
} | ||
} else { | ||
// array of single index | ||
ary.push( obj ); | ||
return arraySlice.call( obj ); | ||
} | ||
return ary; | ||
// array of single index | ||
return [ obj ]; | ||
}; | ||
@@ -153,18 +157,14 @@ | ||
utils.debounceMethod = function( _class, methodName, threshold ) { | ||
threshold = threshold || 100; | ||
// original method | ||
var method = _class.prototype[ methodName ]; | ||
var timeoutName = methodName + 'Timeout'; | ||
var timeout; | ||
_class.prototype[ methodName ] = function() { | ||
var timeout = this[ timeoutName ]; | ||
if ( timeout ) { | ||
clearTimeout( timeout ); | ||
} | ||
clearTimeout( timeout ); | ||
var args = arguments; | ||
var _this = this; | ||
this[ timeoutName ] = setTimeout( function() { | ||
timeout = setTimeout( function() { | ||
method.apply( _this, args ); | ||
delete _this[ timeoutName ]; | ||
}, threshold || 100 ); | ||
}, threshold ); | ||
}; | ||
@@ -171,0 +171,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13890
310
11