Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # pify [![Build Status](https://travis-ci.org/sindresorhus/pify.svg?branch=master)](https://travis-ci.org/sindresorhus/pify)
  2. > Promisify a callback-style function
  3. ## Install
  4. ```
  5. $ npm install --save pify
  6. ```
  7. ## Usage
  8. ```js
  9. const fs = require('fs');
  10. const pify = require('pify');
  11. // Promisify a single function
  12. pify(fs.readFile)('package.json', 'utf8').then(data => {
  13. console.log(JSON.parse(data).name);
  14. //=> 'pify'
  15. });
  16. // Promisify all methods in a module
  17. pify(fs).readFile('package.json', 'utf8').then(data => {
  18. console.log(JSON.parse(data).name);
  19. //=> 'pify'
  20. });
  21. ```
  22. ## API
  23. ### pify(input, [options])
  24. Returns a `Promise` wrapped version of the supplied function or module.
  25. #### input
  26. Type: `Function` `Object`
  27. Callback-style function or module whose methods you want to promisify.
  28. #### options
  29. ##### multiArgs
  30. Type: `boolean`<br>
  31. Default: `false`
  32. 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.
  33. ```js
  34. const request = require('request');
  35. const pify = require('pify');
  36. pify(request, {multiArgs: true})('https://sindresorhus.com').then(result => {
  37. const [httpResponse, body] = result;
  38. });
  39. ```
  40. ##### include
  41. Type: `string[]` `RegExp[]`
  42. Methods in a module to promisify. Remaining methods will be left untouched.
  43. ##### exclude
  44. Type: `string[]` `RegExp[]`<br>
  45. Default: `[/.+(Sync|Stream)$/]`
  46. Methods in a module **not** to promisify. Methods with names ending with `'Sync'` are excluded by default.
  47. ##### excludeMain
  48. Type: `boolean`<br>
  49. Default: `false`
  50. 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.
  51. ```js
  52. const pify = require('pify');
  53. function fn() {
  54. return true;
  55. }
  56. fn.method = (data, callback) => {
  57. setImmediate(() => {
  58. callback(null, data);
  59. });
  60. };
  61. // Promisify methods but not `fn()`
  62. const promiseFn = pify(fn, {excludeMain: true});
  63. if (promiseFn()) {
  64. promiseFn.method('hi').then(data => {
  65. console.log(data);
  66. });
  67. }
  68. ```
  69. ##### errorFirst
  70. Type: `boolean`<br>
  71. Default: `true`
  72. 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.
  73. ##### promiseModule
  74. Type: `Function`
  75. Custom promise module to use instead of the native one.
  76. Check out [`pinkie-promise`](https://github.com/floatdrop/pinkie-promise) if you need a tiny promise polyfill.
  77. ## Related
  78. - [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted
  79. - [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently
  80. - [More…](https://github.com/sindresorhus/promise-fun)
  81. ## License
  82. MIT © [Sindre Sorhus](https://sindresorhus.com)