@medipass/utils 11.84.8 → 11.84.9-chore-add-manual-pify.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medipass/utils",
3
- "version": "11.84.8",
3
+ "version": "11.84.9-chore-add-manual-pify.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -47,5 +47,5 @@
47
47
  "rimraf": "^2.6.2",
48
48
  "typescript": "4.8.4"
49
49
  },
50
- "gitHead": "efa4f79b05115a1173f22f7e3a24613de1b850be"
50
+ "gitHead": "b440b9a5835390ed72aea0208ff2d845ae92e8a7"
51
51
  }
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -0,0 +1 @@
1
+ export default function pify(input: any, options: any): any;
package/pify/index.js ADDED
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
+
15
+ var processFunction = function processFunction(function_, options, proxy, unwrapped) {
16
+ return function () {
17
+ var _this = this;
18
+
19
+ for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {
20
+ arguments_[_key] = arguments[_key];
21
+ }
22
+
23
+ var P = options.promiseModule;
24
+ return new P(function (resolve, reject) {
25
+ if (options.multiArgs) {
26
+ arguments_.push(function () {
27
+ for (var _len2 = arguments.length, result = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
28
+ result[_key2] = arguments[_key2];
29
+ }
30
+
31
+ if (options.errorFirst) {
32
+ if (result[0]) {
33
+ reject(result);
34
+ } else {
35
+ result.shift();
36
+ resolve(result);
37
+ }
38
+ } else {
39
+ resolve(result);
40
+ }
41
+ });
42
+ } else if (options.errorFirst) {
43
+ arguments_.push(function (error, result) {
44
+ if (error) {
45
+ reject(error);
46
+ } else {
47
+ resolve(result);
48
+ }
49
+ });
50
+ } else {
51
+ arguments_.push(resolve);
52
+ }
53
+
54
+ var self = _this === proxy ? unwrapped : _this;
55
+ Reflect.apply(function_, self, arguments_);
56
+ });
57
+ };
58
+ };
59
+
60
+ var filterCache = new WeakMap();
61
+ function pify(input, options) {
62
+ options = _objectSpread({
63
+ exclude: [/.+(?:Sync|Stream)$/],
64
+ errorFirst: true,
65
+ promiseModule: Promise
66
+ }, options);
67
+ var objectType = typeof input;
68
+
69
+ if (!(input !== null && (objectType === 'object' || objectType === 'function'))) {
70
+ throw new TypeError("Expected `input` to be a `Function` or `Object`, got `" + (input === null ? 'null' : objectType) + "`");
71
+ }
72
+
73
+ var filter = function filter(target, key) {
74
+ var cached = filterCache.get(target);
75
+
76
+ if (!cached) {
77
+ cached = {};
78
+ filterCache.set(target, cached);
79
+ }
80
+
81
+ if (key in cached) {
82
+ return cached[key];
83
+ }
84
+
85
+ var match = function match(pattern) {
86
+ return typeof pattern === 'string' || typeof key === 'symbol' ? key === pattern : pattern.test(key);
87
+ };
88
+
89
+ var descriptor = Reflect.getOwnPropertyDescriptor(target, key);
90
+ var writableOrConfigurableOwn = descriptor === undefined || descriptor.writable || descriptor.configurable;
91
+ var included = options.include ? options.include.some(function (element) {
92
+ return match(element);
93
+ }) : !options.exclude.some(function (element) {
94
+ return match(element);
95
+ });
96
+ var shouldFilter = included && writableOrConfigurableOwn;
97
+ cached[key] = shouldFilter;
98
+ return shouldFilter;
99
+ };
100
+
101
+ var cache = new WeakMap();
102
+ var proxy = new Proxy(input, {
103
+ apply: function apply(target, thisArg, args) {
104
+ var cached = cache.get(target);
105
+
106
+ if (cached) {
107
+ return Reflect.apply(cached, thisArg, args);
108
+ }
109
+
110
+ var pified = options.excludeMain ? target : processFunction(target, options, proxy, target);
111
+ cache.set(target, pified);
112
+ return Reflect.apply(pified, thisArg, args);
113
+ },
114
+ get: function get(target, key) {
115
+ var property = target[key];
116
+
117
+ if (!filter(target, key) || property === Function.prototype[key]) {
118
+ return property;
119
+ }
120
+
121
+ var cached = cache.get(property);
122
+
123
+ if (cached) {
124
+ return cached;
125
+ }
126
+
127
+ if (typeof property === 'function') {
128
+ var pified = processFunction(property, options, proxy, target);
129
+ cache.set(property, pified);
130
+ return pified;
131
+ }
132
+
133
+ return property;
134
+ }
135
+ });
136
+ return proxy;
137
+ }
138
+
139
+ exports["default"] = pify;