Changeset e29cc2e for trip-planner-front/node_modules/pify
- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- Location:
- trip-planner-front/node_modules/pify
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/pify/index.js
r59329aa re29cc2e 1 1 'use strict'; 2 2 3 var processFn = function (fn, P, opts) { 4 return function () { 5 var that = this; 6 var args = new Array(arguments.length); 3 const processFn = (fn, options) => function (...args) { 4 const P = options.promiseModule; 7 5 8 for (var i = 0; i < arguments.length; i++) { 9 args[i] = arguments[i]; 10 } 11 12 return new P(function (resolve, reject) { 13 args.push(function (err, result) { 14 if (err) { 15 reject(err); 16 } else if (opts.multiArgs) { 17 var results = new Array(arguments.length - 1); 18 19 for (var i = 1; i < arguments.length; i++) { 20 results[i - 1] = arguments[i]; 6 return new P((resolve, reject) => { 7 if (options.multiArgs) { 8 args.push((...result) => { 9 if (options.errorFirst) { 10 if (result[0]) { 11 reject(result); 12 } else { 13 result.shift(); 14 resolve(result); 21 15 } 22 23 resolve(results);24 16 } else { 25 17 resolve(result); 26 18 } 27 19 }); 20 } else if (options.errorFirst) { 21 args.push((error, result) => { 22 if (error) { 23 reject(error); 24 } else { 25 resolve(result); 26 } 27 }); 28 } else { 29 args.push(resolve); 30 } 28 31 29 fn.apply(that, args); 30 }); 31 }; 32 fn.apply(this, args); 33 }); 32 34 }; 33 35 34 var pify = module.exports = function (obj, P, opts) { 35 if (typeof P !== 'function') { 36 opts = P; 37 P = Promise; 36 module.exports = (input, options) => { 37 options = Object.assign({ 38 exclude: [/.+(Sync|Stream)$/], 39 errorFirst: true, 40 promiseModule: Promise 41 }, options); 42 43 const objType = typeof input; 44 if (!(input !== null && (objType === 'object' || objType === 'function'))) { 45 throw new TypeError(`Expected \`input\` to be a \`Function\` or \`Object\`, got \`${input === null ? 'null' : objType}\``); 38 46 } 39 47 40 opts = opts || {}; 41 opts.exclude = opts.exclude || [/.+Sync$/]; 42 43 var filter = function (key) { 44 var match = function (pattern) { 45 return typeof pattern === 'string' ? key === pattern : pattern.test(key); 46 }; 47 48 return opts.include ? opts.include.some(match) : !opts.exclude.some(match); 48 const filter = key => { 49 const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key); 50 return options.include ? options.include.some(match) : !options.exclude.some(match); 49 51 }; 50 52 51 var ret = typeof obj === 'function' ? function () { 52 if (opts.excludeMain) { 53 return obj.apply(this, arguments); 54 } 53 let ret; 54 if (objType === 'function') { 55 ret = function (...args) { 56 return options.excludeMain ? input(...args) : processFn(input, options).apply(this, args); 57 }; 58 } else { 59 ret = Object.create(Object.getPrototypeOf(input)); 60 } 55 61 56 return processFn(obj, P, opts).apply(this, arguments); 57 } : {}; 62 for (const key in input) { // eslint-disable-line guard-for-in 63 const property = input[key]; 64 ret[key] = typeof property === 'function' && filter(key) ? processFn(property, options) : property; 65 } 58 66 59 return Object.keys(obj).reduce(function (ret, key) { 60 var x = obj[key]; 61 62 ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x; 63 64 return ret; 65 }, ret); 67 return ret; 66 68 }; 67 68 pify.all = pify; -
trip-planner-front/node_modules/pify/license
r59329aa re29cc2e 1 The MIT License (MIT) 1 MIT License 2 2 3 3 Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) 4 4 5 Permission is hereby granted, free of charge, to any person obtaining a copy 6 of this software and associated documentation files (the "Software"), to deal 7 in the Software without restriction, including without limitation the rights 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 copies of the Software, and to permit persons to whom the Software is 10 furnished to do so, subject to the following conditions: 5 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: 11 6 12 The above copyright notice and this permission notice shall be included in 13 all copies or substantial portions of the Software. 7 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 14 8 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 THE SOFTWARE. 9 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. -
trip-planner-front/node_modules/pify/package.json
r59329aa re29cc2e 1 1 { 2 "_args": [ 3 [ 4 "pify@2.3.0", 5 "C:\\Users\\DELL\\Desktop\\bachelor-thesis\\trip-planner-front" 6 ] 7 ], 8 "_development": true, 9 "_from": "pify@2.3.0", 10 "_id": "pify@2.3.0", 2 "_from": "pify@^4.0.1", 3 "_id": "pify@4.0.1", 11 4 "_inBundle": false, 12 "_integrity": "sha 1-7RQaasBDqEnqWISY59yosVMw6Qw=",5 "_integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", 13 6 "_location": "/pify", 14 7 "_phantomChildren": {}, 15 8 "_requested": { 16 "type": " version",9 "type": "range", 17 10 "registry": true, 18 "raw": "pify@ 2.3.0",11 "raw": "pify@^4.0.1", 19 12 "name": "pify", 20 13 "escapedName": "pify", 21 "rawSpec": " 2.3.0",14 "rawSpec": "^4.0.1", 22 15 "saveSpec": null, 23 "fetchSpec": " 2.3.0"16 "fetchSpec": "^4.0.1" 24 17 }, 25 18 "_requiredBy": [ 26 "/read-cache" 19 "/del", 20 "/less/make-dir" 27 21 ], 28 "_resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", 29 "_spec": "2.3.0", 30 "_where": "C:\\Users\\DELL\\Desktop\\bachelor-thesis\\trip-planner-front", 22 "_resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", 23 "_shasum": "4b2cd25c50d598735c50292224fd8c6df41e3231", 24 "_spec": "pify@^4.0.1", 25 "_where": "C:\\Users\\DELL\\Desktop\\bachelor-thesis\\trip-planner-front\\node_modules\\less\\node_modules\\make-dir", 31 26 "author": { 32 27 "name": "Sindre Sorhus", … … 37 32 "url": "https://github.com/sindresorhus/pify/issues" 38 33 }, 34 "bundleDependencies": false, 35 "deprecated": false, 39 36 "description": "Promisify a callback-style function", 40 37 "devDependencies": { 41 "ava": " *",42 "pinkie-promise": "^ 1.0.0",43 "v8-natives": " 0.0.2",44 "xo": " *"38 "ava": "^0.25.0", 39 "pinkie-promise": "^2.0.0", 40 "v8-natives": "^1.1.0", 41 "xo": "^0.23.0" 45 42 }, 46 43 "engines": { 47 "node": ">= 0.10.0"44 "node": ">=6" 48 45 }, 49 46 "files": [ … … 55 52 "promises", 56 53 "promisify", 54 "all", 57 55 "denodify", 58 56 "denodeify", … … 69 67 "to", 70 68 "async", 71 "es2015" 69 "await", 70 "es2015", 71 "bluebird" 72 72 ], 73 73 "license": "MIT", … … 79 79 "scripts": { 80 80 "optimization-test": "node --allow-natives-syntax optimization-test.js", 81 "test": "xo && ava && npm run optimization-test"81 "test": "xo && ava" 82 82 }, 83 "version": " 2.3.0"83 "version": "4.0.1" 84 84 } -
trip-planner-front/node_modules/pify/readme.md
r59329aa re29cc2e 2 2 3 3 > Promisify a callback-style function 4 5 --- 6 7 <div align="center"> 8 <b> 9 <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> 10 </b> 11 <br> 12 <sub> 13 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. 14 </sub> 15 </div> 16 17 --- 4 18 5 19 … … 7 21 8 22 ``` 9 $ npm install --savepify23 $ npm install pify 10 24 ``` 11 25 … … 17 31 const pify = require('pify'); 18 32 19 // promisify a single function 20 33 // Promisify a single function 21 34 pify(fs.readFile)('package.json', 'utf8').then(data => { 22 35 console.log(JSON.parse(data).name); … … 24 37 }); 25 38 26 // or promisify all methods in a module 27 39 // Promisify all methods in a module 28 40 pify(fs).readFile('package.json', 'utf8').then(data => { 29 41 console.log(JSON.parse(data).name); … … 35 47 ## API 36 48 37 ### pify(input, [ promiseModule], [options])49 ### pify(input, [options]) 38 50 39 Returns a promisewrapped version of the supplied function or module.51 Returns a `Promise` wrapped version of the supplied function or module. 40 52 41 53 #### input 42 54 43 Type: ` function`, `object`55 Type: `Function` `Object` 44 56 45 57 Callback-style function or module whose methods you want to promisify. 46 47 #### promiseModule48 49 Type: `function`50 51 Custom promise module to use instead of the native one.52 53 Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill.54 58 55 59 #### options … … 57 61 ##### multiArgs 58 62 59 Type: `boolean` 63 Type: `boolean`<br> 60 64 Default: `false` 61 65 62 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. 66 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. 63 67 64 68 ```js … … 73 77 ##### include 74 78 75 Type: ` array` of (`string`|`regex`)79 Type: `string[]` `RegExp[]` 76 80 77 81 Methods in a module to promisify. Remaining methods will be left untouched. … … 79 83 ##### exclude 80 84 81 Type: ` array` of (`string`|`regex`)82 Default: `[/.+ Sync$/]`85 Type: `string[]` `RegExp[]`<br> 86 Default: `[/.+(Sync|Stream)$/]` 83 87 84 88 Methods in a module **not** to promisify. Methods with names ending with `'Sync'` are excluded by default. … … 86 90 ##### excludeMain 87 91 88 Type: `boolean` 92 Type: `boolean`<br> 89 93 Default: `false` 90 94 91 By default, if given module is a function itself, this functionwill be promisified. Turn this option on if you want to promisify only methods of the module.95 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. 92 96 93 97 ```js … … 100 104 fn.method = (data, callback) => { 101 105 setImmediate(() => { 102 callback( data, null);106 callback(null, data); 103 107 }); 104 108 }; 105 109 106 // promisify methods but not fn()110 // Promisify methods but not `fn()` 107 111 const promiseFn = pify(fn, {excludeMain: true}); 108 112 … … 114 118 ``` 115 119 120 ##### errorFirst 121 122 Type: `boolean`<br> 123 Default: `true` 124 125 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. 126 127 ##### promiseModule 128 129 Type: `Function` 130 131 Custom promise module to use instead of the native one. 132 133 Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill. 134 135 136 ## Related 137 138 - [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted 139 - [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently 140 - [More…](https://github.com/sindresorhus/promise-fun) 141 116 142 117 143 ## License 118 144 119 MIT © [Sindre Sorhus](http ://sindresorhus.com)145 MIT © [Sindre Sorhus](https://sindresorhus.com)
Note:
See TracChangeset
for help on using the changeset viewer.