Initial import with skill sheet working
This commit is contained in:
		
							
								
								
									
										68
									
								
								node_modules/pify/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								node_modules/pify/index.js
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const processFn = (fn, options) => function (...args) { | ||||
| 	const P = options.promiseModule; | ||||
|  | ||||
| 	return new P((resolve, reject) => { | ||||
| 		if (options.multiArgs) { | ||||
| 			args.push((...result) => { | ||||
| 				if (options.errorFirst) { | ||||
| 					if (result[0]) { | ||||
| 						reject(result); | ||||
| 					} else { | ||||
| 						result.shift(); | ||||
| 						resolve(result); | ||||
| 					} | ||||
| 				} else { | ||||
| 					resolve(result); | ||||
| 				} | ||||
| 			}); | ||||
| 		} else if (options.errorFirst) { | ||||
| 			args.push((error, result) => { | ||||
| 				if (error) { | ||||
| 					reject(error); | ||||
| 				} else { | ||||
| 					resolve(result); | ||||
| 				} | ||||
| 			}); | ||||
| 		} else { | ||||
| 			args.push(resolve); | ||||
| 		} | ||||
|  | ||||
| 		fn.apply(this, args); | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| module.exports = (input, options) => { | ||||
| 	options = Object.assign({ | ||||
| 		exclude: [/.+(Sync|Stream)$/], | ||||
| 		errorFirst: true, | ||||
| 		promiseModule: Promise | ||||
| 	}, options); | ||||
|  | ||||
| 	const objType = typeof input; | ||||
| 	if (!(input !== null && (objType === 'object' || objType === 'function'))) { | ||||
| 		throw new TypeError(`Expected \`input\` to be a \`Function\` or \`Object\`, got \`${input === null ? 'null' : objType}\``); | ||||
| 	} | ||||
|  | ||||
| 	const filter = key => { | ||||
| 		const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key); | ||||
| 		return options.include ? options.include.some(match) : !options.exclude.some(match); | ||||
| 	}; | ||||
|  | ||||
| 	let ret; | ||||
| 	if (objType === 'function') { | ||||
| 		ret = function (...args) { | ||||
| 			return options.excludeMain ? input(...args) : processFn(input, options).apply(this, args); | ||||
| 		}; | ||||
| 	} else { | ||||
| 		ret = Object.create(Object.getPrototypeOf(input)); | ||||
| 	} | ||||
|  | ||||
| 	for (const key in input) { // eslint-disable-line guard-for-in | ||||
| 		const property = input[key]; | ||||
| 		ret[key] = typeof property === 'function' && filter(key) ? processFn(property, options) : property; | ||||
| 	} | ||||
|  | ||||
| 	return ret; | ||||
| }; | ||||
							
								
								
									
										9
									
								
								node_modules/pify/license
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								node_modules/pify/license
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| MIT License | ||||
|  | ||||
| Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||||
|  | ||||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||||
|  | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||
							
								
								
									
										51
									
								
								node_modules/pify/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								node_modules/pify/package.json
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| { | ||||
| 	"name": "pify", | ||||
| 	"version": "4.0.1", | ||||
| 	"description": "Promisify a callback-style function", | ||||
| 	"license": "MIT", | ||||
| 	"repository": "sindresorhus/pify", | ||||
| 	"author": { | ||||
| 		"name": "Sindre Sorhus", | ||||
| 		"email": "sindresorhus@gmail.com", | ||||
| 		"url": "sindresorhus.com" | ||||
| 	}, | ||||
| 	"engines": { | ||||
| 		"node": ">=6" | ||||
| 	}, | ||||
| 	"scripts": { | ||||
| 		"test": "xo && ava", | ||||
| 		"optimization-test": "node --allow-natives-syntax optimization-test.js" | ||||
| 	}, | ||||
| 	"files": [ | ||||
| 		"index.js" | ||||
| 	], | ||||
| 	"keywords": [ | ||||
| 		"promise", | ||||
| 		"promises", | ||||
| 		"promisify", | ||||
| 		"all", | ||||
| 		"denodify", | ||||
| 		"denodeify", | ||||
| 		"callback", | ||||
| 		"cb", | ||||
| 		"node", | ||||
| 		"then", | ||||
| 		"thenify", | ||||
| 		"convert", | ||||
| 		"transform", | ||||
| 		"wrap", | ||||
| 		"wrapper", | ||||
| 		"bind", | ||||
| 		"to", | ||||
| 		"async", | ||||
| 		"await", | ||||
| 		"es2015", | ||||
| 		"bluebird" | ||||
| 	], | ||||
| 	"devDependencies": { | ||||
| 		"ava": "^0.25.0", | ||||
| 		"pinkie-promise": "^2.0.0", | ||||
| 		"v8-natives": "^1.1.0", | ||||
| 		"xo": "^0.23.0" | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										145
									
								
								node_modules/pify/readme.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								node_modules/pify/readme.md
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,145 @@ | ||||
| # pify [](https://travis-ci.org/sindresorhus/pify) | ||||
|  | ||||
| > Promisify a callback-style function | ||||
|  | ||||
| --- | ||||
|  | ||||
| <div align="center"> | ||||
| 	<b> | ||||
| 		<a href="https://tidelift.com/subscription/pkg/npm-pify?utm_source=npm-pify&utm_medium=referral&utm_campaign=readme">Get professional support for 'pify' with a Tidelift subscription</a> | ||||
| 	</b> | ||||
| 	<br> | ||||
| 	<sub> | ||||
| 		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||||
| 	</sub> | ||||
| </div> | ||||
|  | ||||
| --- | ||||
|  | ||||
|  | ||||
| ## Install | ||||
|  | ||||
| ``` | ||||
| $ npm install pify | ||||
| ``` | ||||
|  | ||||
|  | ||||
| ## Usage | ||||
|  | ||||
| ```js | ||||
| const fs = require('fs'); | ||||
| const pify = require('pify'); | ||||
|  | ||||
| // Promisify a single function | ||||
| pify(fs.readFile)('package.json', 'utf8').then(data => { | ||||
| 	console.log(JSON.parse(data).name); | ||||
| 	//=> 'pify' | ||||
| }); | ||||
|  | ||||
| // Promisify all methods in a module | ||||
| pify(fs).readFile('package.json', 'utf8').then(data => { | ||||
| 	console.log(JSON.parse(data).name); | ||||
| 	//=> 'pify' | ||||
| }); | ||||
| ``` | ||||
|  | ||||
|  | ||||
| ## API | ||||
|  | ||||
| ### pify(input, [options]) | ||||
|  | ||||
| Returns a `Promise` wrapped version of the supplied function or module. | ||||
|  | ||||
| #### input | ||||
|  | ||||
| Type: `Function` `Object` | ||||
|  | ||||
| Callback-style function or module whose methods you want to promisify. | ||||
|  | ||||
| #### options | ||||
|  | ||||
| ##### multiArgs | ||||
|  | ||||
| Type: `boolean`<br> | ||||
| Default: `false` | ||||
|  | ||||
| By default, the promisified function will only return the second argument from the callback, which works fine for most APIs. This option can be useful for modules like `request` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, excluding the error argument, instead of just the second argument. This also applies to rejections, where it returns an array of all the callback arguments, including the error. | ||||
|  | ||||
| ```js | ||||
| const request = require('request'); | ||||
| const pify = require('pify'); | ||||
|  | ||||
| pify(request, {multiArgs: true})('https://sindresorhus.com').then(result => { | ||||
| 	const [httpResponse, body] = result; | ||||
| }); | ||||
| ``` | ||||
|  | ||||
| ##### include | ||||
|  | ||||
| Type: `string[]` `RegExp[]` | ||||
|  | ||||
| Methods in a module to promisify. Remaining methods will be left untouched. | ||||
|  | ||||
| ##### exclude | ||||
|  | ||||
| Type: `string[]` `RegExp[]`<br> | ||||
| Default: `[/.+(Sync|Stream)$/]` | ||||
|  | ||||
| Methods in a module **not** to promisify. Methods with names ending with `'Sync'` are excluded by default. | ||||
|  | ||||
| ##### excludeMain | ||||
|  | ||||
| Type: `boolean`<br> | ||||
| Default: `false` | ||||
|  | ||||
| If given module is a function itself, it will be promisified. Turn this option on if you want to promisify only methods of the module. | ||||
|  | ||||
| ```js | ||||
| const pify = require('pify'); | ||||
|  | ||||
| function fn() { | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| fn.method = (data, callback) => { | ||||
| 	setImmediate(() => { | ||||
| 		callback(null, data); | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| // Promisify methods but not `fn()` | ||||
| const promiseFn = pify(fn, {excludeMain: true}); | ||||
|  | ||||
| if (promiseFn()) { | ||||
| 	promiseFn.method('hi').then(data => { | ||||
| 		console.log(data); | ||||
| 	}); | ||||
| } | ||||
| ``` | ||||
|  | ||||
| ##### errorFirst | ||||
|  | ||||
| Type: `boolean`<br> | ||||
| Default: `true` | ||||
|  | ||||
| Whether the callback has an error as the first argument. You'll want to set this to `false` if you're dealing with an API that doesn't have an error as the first argument, like `fs.exists()`, some browser APIs, Chrome Extension APIs, etc. | ||||
|  | ||||
| ##### promiseModule | ||||
|  | ||||
| Type: `Function` | ||||
|  | ||||
| Custom promise module to use instead of the native one. | ||||
|  | ||||
| Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill. | ||||
|  | ||||
|  | ||||
| ## Related | ||||
|  | ||||
| - [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted | ||||
| - [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently | ||||
| - [More…](https://github.com/sindresorhus/promise-fun) | ||||
|  | ||||
|  | ||||
| ## License | ||||
|  | ||||
| MIT © [Sindre Sorhus](https://sindresorhus.com) | ||||
		Reference in New Issue
	
	Block a user