Sha256: 92ee3c24b0239df2a47c226b5e271cb1041d1cff2b7199d88524f49007832c52

Contents?: true

Size: 1.4 KB

Versions: 103

Compression:

Stored size: 1.4 KB

Contents

'use strict';

var processFn = function (fn, P, opts) {
	return function () {
		var that = this;
		var args = new Array(arguments.length);

		for (var i = 0; i < arguments.length; i++) {
			args[i] = arguments[i];
		}

		return new P(function (resolve, reject) {
			args.push(function (err, result) {
				if (err) {
					reject(err);
				} else if (opts.multiArgs) {
					var results = new Array(arguments.length - 1);

					for (var i = 1; i < arguments.length; i++) {
						results[i - 1] = arguments[i];
					}

					resolve(results);
				} else {
					resolve(result);
				}
			});

			fn.apply(that, args);
		});
	};
};

var pify = module.exports = function (obj, P, opts) {
	if (typeof P !== 'function') {
		opts = P;
		P = Promise;
	}

	opts = opts || {};
	opts.exclude = opts.exclude || [/.+Sync$/];

	var filter = function (key) {
		var match = function (pattern) {
			return typeof pattern === 'string' ? key === pattern : pattern.test(key);
		};

		return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
	};

	var ret = typeof obj === 'function' ? function () {
		if (opts.excludeMain) {
			return obj.apply(this, arguments);
		}

		return processFn(obj, P, opts).apply(this, arguments);
	} : {};

	return Object.keys(obj).reduce(function (ret, key) {
		var x = obj[key];

		ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;

		return ret;
	}, ret);
};

pify.all = pify;

Version data entries

103 entries across 87 versions & 18 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/pify/index.js
decidim-0.26.8 packages/eslint-config/node_modules/pify/index.js
disco_app-0.18.0 test/dummy/node_modules/pify/index.js
disco_app-0.18.2 test/dummy/node_modules/pify/index.js
disco_app-0.16.1 test/dummy/node_modules/pify/index.js
disco_app-0.15.2 test/dummy/node_modules/pify/index.js
disco_app-0.18.4 test/dummy/node_modules/pify/index.js
disco_app-0.18.1 test/dummy/node_modules/pify/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/pify/index.js
disco_app-0.14.0 test/dummy/node_modules/pify/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/pify/index.js
tang-0.2.1 spec/tang_app/node_modules/pify/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/pify/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/pify/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/pify/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/pify/index.js
tang-0.2.0 spec/tang_app/node_modules/pify/index.js
tang-0.1.0 spec/tang_app/node_modules/pify/index.js
tang-0.0.9 spec/tang_app/node_modules/pify/index.js
enju_library-0.3.8 spec/dummy/node_modules/pify/index.js