npmtest-auto-install (v0.0.1)

Code coverage report for node-npmtest-auto-install/auto-install/node_modules/onetime/index.js

Statements: 44.44% (8 / 18)      Branches: 46.15% (6 / 13)      Functions: 50% (1 / 2)      Lines: 44.44% (8 / 18)      Ignored: none     

All files » node-npmtest-auto-install/auto-install/node_modules/onetime/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  1 1       1 1 1   1                                 1   1      
'use strict';
module.exports = function (fn, errMsg) {
	Iif (typeof fn !== 'function') {
		throw new TypeError('Expected a function');
	}
 
	var ret;
	var called = false;
	var fnName = fn.displayName || fn.name || (/function ([^\(]+)/.exec(fn.toString()) || [])[1];
 
	var onetime = function () {
		if (called) {
			if (errMsg === true) {
				fnName = fnName ? fnName + '()' : 'Function';
				throw new Error(fnName + ' can only be called once.');
			}
 
			return ret;
		}
 
		called = true;
		ret = fn.apply(this, arguments);
		fn = null;
 
		return ret;
	};
 
	onetime.displayName = fnName;
 
	return onetime;
};