@mightyplow/jslib
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| var i = 0; | ||
| /** | ||
| * Takes a function and logs the time it takes on the console. | ||
| * | ||
| * @memberOf function | ||
| * @function | ||
| * @param label | ||
| * @param fn | ||
| */ | ||
| var measureTime = function measureTime() { | ||
| var label = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : i++; | ||
| var fn = arguments[1]; | ||
| return function () { | ||
| console.time(label); | ||
| var result = fn.apply(undefined, arguments); | ||
| console.timeEnd(label); | ||
| return result; | ||
| }; | ||
| }; | ||
| exports.default = measureTime; |
@@ -23,7 +23,8 @@ "use strict"; | ||
| var timer = null; | ||
| var abortTimer = function abortTimer() { | ||
| var abort = function abort() { | ||
| return clearTimeout(timer); | ||
| }; | ||
| var debouncedFunction = function debouncedFunction() { | ||
| // extend function with abort method | ||
| return Object.assign(function () { | ||
| for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -33,11 +34,9 @@ args[_key] = arguments[_key]; | ||
| abortTimer(); | ||
| abort(); | ||
| timer = setTimeout(function () { | ||
| return fn.apply(undefined, args); | ||
| }, timeout); | ||
| }; | ||
| debouncedFunction.abort = abortTimer; | ||
| return debouncedFunction; | ||
| }, { | ||
| abort: abort | ||
| }); | ||
| }; |
@@ -88,2 +88,11 @@ 'use strict'; | ||
| var _measureTime = require('./measureTime'); | ||
| Object.defineProperty(exports, 'measureTime', { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _interopRequireDefault(_measureTime).default; | ||
| } | ||
| }); | ||
| var _noop = require('./noop'); | ||
@@ -90,0 +99,0 @@ |
+6
-0
@@ -108,2 +108,8 @@ 'use strict'; | ||
| }); | ||
| Object.defineProperty(exports, 'measureTime', { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _function.measureTime; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, 'memoize', { | ||
@@ -110,0 +116,0 @@ enumerable: true, |
+1
-1
| { | ||
| "name": "@mightyplow/jslib", | ||
| "version": "0.17.0", | ||
| "version": "0.18.0", | ||
| "description": "js helpers library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+13
-0
@@ -125,2 +125,3 @@ ## Objects | ||
| * [.indentity(arg)](#function.indentity) | ||
| * [.measureTime(label, fn)](#function.measureTime) | ||
| * [.memoize(fn, [timeout])](#function.memoize) ⇒ [<code>function</code>](#function) | ||
@@ -205,2 +206,14 @@ * [.module.exports()](#function.module.exports) | ||
| <a name="function.measureTime"></a> | ||
| ### function.measureTime(label, fn) | ||
| Takes a function and logs the time it takes on the console. | ||
| **Kind**: static method of [<code>function</code>](#function) | ||
| | Param | | ||
| | --- | | ||
| | label | | ||
| | fn | | ||
| <a name="function.memoize"></a> | ||
@@ -207,0 +220,0 @@ |
49575
2.42%44
2.33%1201
3.18%429
3.13%