applying transfer to react app

This commit is contained in:
Tyler Koenig
2021-09-20 16:54:47 -04:00
parent 8819f31dd0
commit c612b7d702
37373 changed files with 3775588 additions and 2871 deletions
+65
View File
@@ -0,0 +1,65 @@
# @gar/promisify
### Promisify an entire object or class instance
This module leverages es6 Proxy and Reflect to promisify every function in an
object or class instance.
It assumes the callback that the function is expecting is the last
parameter, and that it is an error-first callback with only one value,
i.e. `(err, value) => ...`. This mirrors node's `util.promisify` method.
In order that you can use it as a one-stop-shop for all your promisify
needs, you can also pass it a function. That function will be
promisified as normal using node's built-in `util.promisify` method.
[node's custom promisified
functions](https://nodejs.org/api/util.html#util_custom_promisified_functions)
will also be mirrored, further allowing this to be a drop-in replacement
for the built-in `util.promisify`.
### Examples
Promisify an entire object
```javascript
const promisify = require('@gar/promisify')
class Foo {
constructor (attr) {
this.attr = attr
}
double (input, cb) {
cb(null, input * 2)
}
const foo = new Foo('baz')
const promisified = promisify(foo)
console.log(promisified.attr)
console.log(await promisified.double(1024))
```
Promisify a function
```javascript
const promisify = require('@gar/promisify')
function foo (a, cb) {
if (a !== 'bad') {
return cb(null, 'ok')
}
return cb('not ok')
}
const promisified = promisify(foo)
// This will resolve to 'ok'
promisified('good')
// this will reject
promisified('bad')
```
+36
View File
@@ -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')
}
+65
View File
@@ -0,0 +1,65 @@
{
"_from": "@gar/promisify@^1.0.1",
"_id": "@gar/promisify@1.1.2",
"_inBundle": false,
"_integrity": "sha512-82cpyJyKRoQoRi+14ibCeGPu0CwypgtBAdBhq1WfvagpCZNKqwXbKwXllYSMG91DhmG4jt9gN8eP6lGOtozuaw==",
"_location": "/@gar/promisify",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@gar/promisify@^1.0.1",
"name": "@gar/promisify",
"escapedName": "@gar%2fpromisify",
"scope": "@gar",
"rawSpec": "^1.0.1",
"saveSpec": null,
"fetchSpec": "^1.0.1"
},
"_requiredBy": [
"/@npmcli/fs"
],
"_resolved": "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.2.tgz",
"_shasum": "30aa825f11d438671d585bd44e7fd564535fc210",
"_spec": "@gar/promisify@^1.0.1",
"_where": "/Users/tylerkoenig/Code/personal/react-scss2/node_modules/@npmcli/fs",
"author": {
"name": "Gar",
"email": "gar+npm@danger.computer"
},
"bugs": {
"url": "https://github.com/wraithgar/gar-promisify/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Promisify an entire class or object",
"devDependencies": {
"@hapi/code": "^8.0.1",
"@hapi/lab": "^24.1.0",
"standard": "^16.0.3"
},
"files": [
"index.js"
],
"homepage": "https://github.com/wraithgar/gar-promisify#readme",
"keywords": [
"promisify",
"all",
"class",
"object"
],
"license": "MIT",
"main": "index.js",
"name": "@gar/promisify",
"repository": {
"type": "git",
"url": "git+https://github.com/wraithgar/gar-promisify.git"
},
"scripts": {
"lint": "standard",
"lint:fix": "standard --fix",
"posttest": "npm run lint",
"test": "lab -a @hapi/code -t 100"
},
"version": "1.1.2"
}