@react-fabric/utilities 1.0.0-beta.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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/_ascii.js +76 -0
- package/dist/cjs/_boundingBox.js +59 -0
- package/dist/cjs/_countries.js +2805 -0
- package/dist/cjs/_debounce.js +53 -0
- package/dist/cjs/_dedupe.js +63 -0
- package/dist/cjs/_fetch.js +128 -0
- package/dist/cjs/_fileType.js +967 -0
- package/dist/cjs/_format.js +118 -0
- package/dist/cjs/_getByPath.js +125 -0
- package/dist/cjs/_hash.js +67 -0
- package/dist/cjs/_interpolate.js +47 -0
- package/dist/cjs/_isEqual.js +108 -0
- package/dist/cjs/_isType.js +98 -0
- package/dist/cjs/_mergeRefs.js +40 -0
- package/dist/cjs/_tokenize.js +67 -0
- package/dist/cjs/getImageColorset.js +70 -0
- package/dist/cjs/index.js +116 -0
- package/dist/cjs/useLogger.js +339 -0
- package/dist/cjs/yup.js +172 -0
- package/dist/esm/_ascii.js +76 -0
- package/dist/esm/_boundingBox.js +58 -0
- package/dist/esm/_countries.js +2805 -0
- package/dist/esm/_debounce.js +53 -0
- package/dist/esm/_dedupe.js +60 -0
- package/dist/esm/_fetch.js +128 -0
- package/dist/esm/_fileType.js +967 -0
- package/dist/esm/_format.js +120 -0
- package/dist/esm/_getByPath.js +124 -0
- package/dist/esm/_hash.js +65 -0
- package/dist/esm/_interpolate.js +46 -0
- package/dist/esm/_isEqual.js +106 -0
- package/dist/esm/_isType.js +85 -0
- package/dist/esm/_mergeRefs.js +40 -0
- package/dist/esm/_tokenize.js +66 -0
- package/dist/esm/getImageColorset.js +70 -0
- package/dist/esm/index.js +52 -0
- package/dist/esm/useLogger.js +339 -0
- package/dist/esm/yup.js +152 -0
- package/dist/types/_ascii.d.ts +5 -0
- package/dist/types/_boundingBox.d.ts +10 -0
- package/dist/types/_countries.d.ts +85 -0
- package/dist/types/_debounce.d.ts +8 -0
- package/dist/types/_dedupe.d.ts +4 -0
- package/dist/types/_fetch.d.ts +23 -0
- package/dist/types/_fileType.d.ts +926 -0
- package/dist/types/_format.d.ts +27 -0
- package/dist/types/_getByPath.d.ts +10 -0
- package/dist/types/_hash.d.ts +16 -0
- package/dist/types/_interpolate.d.ts +6 -0
- package/dist/types/_isEqual.d.ts +15 -0
- package/dist/types/_isType.d.ts +14 -0
- package/dist/types/_mergeRefs.d.ts +1 -0
- package/dist/types/_tokenize.d.ts +8 -0
- package/dist/types/getImageColorset.d.ts +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/useLogger.d.ts +25 -0
- package/dist/types/yup.d.ts +1 -0
- package/package.json +48 -0
- package/src/_ascii.ts +93 -0
- package/src/_boundingBox.ts +72 -0
- package/src/_countries.ts +3046 -0
- package/src/_debounce.ts +42 -0
- package/src/_dedupe.ts +56 -0
- package/src/_fetch.ts +109 -0
- package/src/_fileType.ts +993 -0
- package/src/_format.ts +141 -0
- package/src/_getByPath.ts +108 -0
- package/src/_hash.ts +62 -0
- package/src/_interpolate.ts +42 -0
- package/src/_isEqual.ts +102 -0
- package/src/_isType.ts +105 -0
- package/src/_mergeRefs.ts +33 -0
- package/src/_tokenize.ts +69 -0
- package/src/getImageColorset.ts +81 -0
- package/src/index.ts +51 -0
- package/src/useLogger.ts +304 -0
- package/src/yup.ts +75 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* React Fabric
|
|
5
|
+
* @version: 1.0.0
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
10
|
+
*
|
|
11
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
12
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
13
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
14
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
* subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
18
|
+
* portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
21
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
22
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* istanbul ignore file */
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* debounce callback
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
var debounce = function debounce(fn) {
|
|
33
|
+
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
|
|
34
|
+
/** ***************** create debounce timer id using callback hash *******************/
|
|
35
|
+
var _timer;
|
|
36
|
+
|
|
37
|
+
/** ***************** return debounced function *******************/
|
|
38
|
+
var cb = function cb() {
|
|
39
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
40
|
+
args[_key] = arguments[_key];
|
|
41
|
+
}
|
|
42
|
+
clearTimeout(_timer);
|
|
43
|
+
if (typeof window !== "undefined") _timer = window.setTimeout(function () {
|
|
44
|
+
return fn === null || fn === void 0 ? void 0 : fn.apply(void 0, args);
|
|
45
|
+
}, timeout);
|
|
46
|
+
};
|
|
47
|
+
cb.cancel = function () {
|
|
48
|
+
return clearTimeout(_timer);
|
|
49
|
+
};
|
|
50
|
+
return cb;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.debounce = debounce;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _isType = require('./_isType.js');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
var dedupe = function dedupe(list, key) {
|
|
29
|
+
var filtered = list.filter(function (i) {
|
|
30
|
+
return !_isType.isEmpty(i);
|
|
31
|
+
});
|
|
32
|
+
if (!key) {
|
|
33
|
+
return Array.from(new Set(filtered).values());
|
|
34
|
+
}
|
|
35
|
+
return Array.from(new Map(filtered.map(function (obj) {
|
|
36
|
+
var _obj$key;
|
|
37
|
+
return [(_obj$key = obj[key]) !== null && _obj$key !== void 0 ? _obj$key : obj, obj];
|
|
38
|
+
})).values());
|
|
39
|
+
};
|
|
40
|
+
var flatten = function flatten(list) {
|
|
41
|
+
return list.flat(5).filter(function (i) {
|
|
42
|
+
return !_isType.isEmpty(i);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var flattenAndDedupe = function flattenAndDedupe() {
|
|
46
|
+
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
47
|
+
var key = arguments.length > 1 ? arguments[1] : undefined;
|
|
48
|
+
return dedupe(flatten(list), key);
|
|
49
|
+
};
|
|
50
|
+
var groupBy = function groupBy(list, prop, missingKey) {
|
|
51
|
+
return list.reduce(function (r, i) {
|
|
52
|
+
var _i$prop;
|
|
53
|
+
var key = (_i$prop = i[prop]) !== null && _i$prop !== void 0 ? _i$prop : missingKey;
|
|
54
|
+
if (!r[key]) r[key] = [];
|
|
55
|
+
r[key].push(i);
|
|
56
|
+
return r;
|
|
57
|
+
}, {});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.dedupe = dedupe;
|
|
61
|
+
exports.flatten = flatten;
|
|
62
|
+
exports.flattenAndDedupe = flattenAndDedupe;
|
|
63
|
+
exports.groupBy = groupBy;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
5
|
+
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
6
|
+
var _isType = require('./_isType.js');
|
|
7
|
+
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
var _signals = new Map();
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fetch helper
|
|
14
|
+
* @param method
|
|
15
|
+
* @param url
|
|
16
|
+
* @param options.headers
|
|
17
|
+
* @param options.body
|
|
18
|
+
* @param options.signal
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
var _fetch = /*#__PURE__*/function () {
|
|
22
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(method, url, _ref) {
|
|
23
|
+
var _ref$headers, headers, body, signal, options, _s, ac;
|
|
24
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
25
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
_ref$headers = _ref.headers, headers = _ref$headers === void 0 ? {} : _ref$headers, body = _ref.body, signal = _ref.signal;
|
|
28
|
+
options = {
|
|
29
|
+
method: method
|
|
30
|
+
};
|
|
31
|
+
headers.accept = "application/json";
|
|
32
|
+
if (method === "post" || method === "put") {
|
|
33
|
+
options.body = body;
|
|
34
|
+
/** ***************** set body to json when not FormData *******************/
|
|
35
|
+
if (!(body instanceof FormData)) {
|
|
36
|
+
headers["content-type"] = "application/json";
|
|
37
|
+
options.body = JSON.stringify(body);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** ***************** reset abort signal *******************/
|
|
42
|
+
if (signal && _isType.isString(signal)) {
|
|
43
|
+
if (_signals.has(signal)) {
|
|
44
|
+
_s = _signals.get(signal);
|
|
45
|
+
_s === null || _s === void 0 || _s.abort();
|
|
46
|
+
_signals["delete"](signal);
|
|
47
|
+
}
|
|
48
|
+
ac = new AbortController();
|
|
49
|
+
options.signal = ac.signal;
|
|
50
|
+
_signals.set(signal, ac);
|
|
51
|
+
} else if (signal instanceof AbortSignal) {
|
|
52
|
+
options.signal = signal;
|
|
53
|
+
}
|
|
54
|
+
_context2.next = 7;
|
|
55
|
+
return fetch(url, _objectSpread(_objectSpread({}, options), {}, {
|
|
56
|
+
headers: headers
|
|
57
|
+
})).then( /*#__PURE__*/function () {
|
|
58
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resp) {
|
|
59
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
60
|
+
while (1) switch (_context.prev = _context.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (!(resp.status >= 200 && resp.status < 300)) {
|
|
63
|
+
_context.next = 4;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
_context.next = 3;
|
|
67
|
+
return resp.json();
|
|
68
|
+
case 3:
|
|
69
|
+
return _context.abrupt("return", _context.sent);
|
|
70
|
+
case 4:
|
|
71
|
+
throw {
|
|
72
|
+
status: resp.status,
|
|
73
|
+
code: -1,
|
|
74
|
+
message: resp.statusText
|
|
75
|
+
};
|
|
76
|
+
case 5:
|
|
77
|
+
case "end":
|
|
78
|
+
return _context.stop();
|
|
79
|
+
}
|
|
80
|
+
}, _callee);
|
|
81
|
+
}));
|
|
82
|
+
return function (_x4) {
|
|
83
|
+
return _ref3.apply(this, arguments);
|
|
84
|
+
};
|
|
85
|
+
}()).then(function (resp) {
|
|
86
|
+
var _ref4, _resp$error_code, _ref5, _resp$error_message;
|
|
87
|
+
/** ***************** check for possible error code propeties in response *******************/
|
|
88
|
+
var code = (_ref4 = (_resp$error_code = resp.error_code) !== null && _resp$error_code !== void 0 ? _resp$error_code : resp.errorCode) !== null && _ref4 !== void 0 ? _ref4 : resp.error;
|
|
89
|
+
var message = (_ref5 = (_resp$error_message = resp.error_message) !== null && _resp$error_message !== void 0 ? _resp$error_message : resp.errorMessage) !== null && _ref5 !== void 0 ? _ref5 : resp.message;
|
|
90
|
+
if (resp.status === "error" || code) {
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
92
|
+
throw {
|
|
93
|
+
status: 500,
|
|
94
|
+
code: code,
|
|
95
|
+
message: message
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return resp;
|
|
99
|
+
});
|
|
100
|
+
case 7:
|
|
101
|
+
return _context2.abrupt("return", _context2.sent);
|
|
102
|
+
case 8:
|
|
103
|
+
case "end":
|
|
104
|
+
return _context2.stop();
|
|
105
|
+
}
|
|
106
|
+
}, _callee2);
|
|
107
|
+
}));
|
|
108
|
+
return function _fetch(_x, _x2, _x3) {
|
|
109
|
+
return _ref2.apply(this, arguments);
|
|
110
|
+
};
|
|
111
|
+
}();
|
|
112
|
+
|
|
113
|
+
/** ***************** attach isAborted helper to fetch method *******************/
|
|
114
|
+
_fetch.isAborted = function (_ref6) {
|
|
115
|
+
var name = _ref6.name;
|
|
116
|
+
return name === "AbortError";
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** ***************** attach abort helper to fetch method *******************/
|
|
120
|
+
_fetch.abort = function (signal) {
|
|
121
|
+
if (_signals.has(signal)) {
|
|
122
|
+
var _s = _signals.get(signal);
|
|
123
|
+
_s === null || _s === void 0 || _s.abort();
|
|
124
|
+
_signals["delete"](signal);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
exports._fetch = _fetch;
|