Changeset e29cc2e for trip-planner-front/node_modules/pify/readme.md
- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.