Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@gar')
-rw-r--r--node_modules/@gar/promisify/index.js36
-rw-r--r--node_modules/@gar/promisify/package.json32
2 files changed, 68 insertions, 0 deletions
diff --git a/node_modules/@gar/promisify/index.js b/node_modules/@gar/promisify/index.js
new file mode 100644
index 000000000..d0be95f6f
--- /dev/null
+++ b/node_modules/@gar/promisify/index.js
@@ -0,0 +1,36 @@
+'use strict'
+
+const { promisify } = require('util')
+
+const handler = {
+ get: function (target, prop, receiver) {
+ if (typeof target[prop] !== 'function') {
+ return target[prop]
+ }
+ if (target[prop][promisify.custom]) {
+ return function () {
+ return Reflect.get(target, prop, receiver)[promisify.custom].apply(target, arguments)
+ }
+ }
+ return function () {
+ return new Promise((resolve, reject) => {
+ Reflect.get(target, prop, receiver).apply(target, [...arguments, function (err, result) {
+ if (err) {
+ return reject(err)
+ }
+ resolve(result)
+ }])
+ })
+ }
+ }
+}
+
+module.exports = function (thingToPromisify) {
+ if (typeof thingToPromisify === 'function') {
+ return promisify(thingToPromisify)
+ }
+ if (typeof thingToPromisify === 'object') {
+ return new Proxy(thingToPromisify, handler)
+ }
+ throw new TypeError('Can only promisify functions or objects')
+}
diff --git a/node_modules/@gar/promisify/package.json b/node_modules/@gar/promisify/package.json
new file mode 100644
index 000000000..b5140876c
--- /dev/null
+++ b/node_modules/@gar/promisify/package.json
@@ -0,0 +1,32 @@
+{
+ "name": "@gar/promisify",
+ "version": "1.1.2",
+ "description": "Promisify an entire class or object",
+ "main": "index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/wraithgar/gar-promisify.git"
+ },
+ "scripts": {
+ "lint": "standard",
+ "lint:fix": "standard --fix",
+ "test": "lab -a @hapi/code -t 100",
+ "posttest": "npm run lint"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "promisify",
+ "all",
+ "class",
+ "object"
+ ],
+ "author": "Gar <gar+npm@danger.computer>",
+ "license": "MIT",
+ "devDependencies": {
+ "@hapi/code": "^8.0.1",
+ "@hapi/lab": "^24.1.0",
+ "standard": "^16.0.3"
+ }
+}