react-hook-toolkit 1.1.5 → 1.1.6

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/dist/utils.js DELETED
@@ -1,104 +0,0 @@
1
- export var promise = function (time) { return new Promise(function (res) { return setTimeout(res, time); }); };
2
- export function throttle(func, limit) {
3
- var lastFunc;
4
- var lastRan;
5
- return function () {
6
- var _this = this;
7
- var args = [];
8
- for (var _i = 0; _i < arguments.length; _i++) {
9
- args[_i] = arguments[_i];
10
- }
11
- if (!lastRan) {
12
- func.apply(this, args);
13
- lastRan = Date.now();
14
- }
15
- else {
16
- clearTimeout(lastFunc);
17
- lastFunc = setTimeout(function () {
18
- if (Date.now() - lastRan >= limit) {
19
- func.apply(_this, args);
20
- lastRan = Date.now();
21
- }
22
- }, limit - (Date.now() - lastRan));
23
- }
24
- };
25
- }
26
- export var debounceUtils = function (func, delay) {
27
- var timeoutId;
28
- return function () {
29
- var args = [];
30
- for (var _i = 0; _i < arguments.length; _i++) {
31
- args[_i] = arguments[_i];
32
- }
33
- clearTimeout(timeoutId);
34
- timeoutId = setTimeout(function () { return func.apply(void 0, args); }, delay);
35
- };
36
- };
37
- export var isBrowser = !!(typeof window !== 'undefined' &&
38
- window.document &&
39
- window.document.createElement);
40
- export var isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
41
- export var isObject = function (value) {
42
- return value !== null && typeof value === 'object';
43
- };
44
- export var isFunction = function (value) {
45
- return typeof value === 'function';
46
- };
47
- export var isString = function (value) { return typeof value === 'string'; };
48
- export var isBoolean = function (value) { return typeof value === 'boolean'; };
49
- export var isNumber = function (value) { return typeof value === 'number'; };
50
- export var isUndef = function (value) { return typeof value === 'undefined'; };
51
- export var isAppleDevice = /(mac|iphone|ipod|ipad)/i.test(typeof navigator !== 'undefined' ? navigator === null || navigator === void 0 ? void 0 : navigator.platform : '');
52
- export var isNavigator = typeof navigator !== 'undefined';
53
- export var getScrollTop = function (el) {
54
- if (el === document || el === document.documentElement || el === document.body) {
55
- return Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop);
56
- }
57
- return el.scrollTop;
58
- };
59
- export var getScrollHeight = function (el) {
60
- return (el.scrollHeight ||
61
- Math.max(document.documentElement.scrollHeight, document.body.scrollHeight));
62
- };
63
- export var getClientHeight = function (el) {
64
- return (el.clientHeight ||
65
- Math.max(document.documentElement.clientHeight, document.body.clientHeight));
66
- };
67
- export function sleep(time) {
68
- return new Promise(function (resolve) {
69
- setTimeout(function () {
70
- resolve();
71
- }, time);
72
- });
73
- }
74
- export function request(req) {
75
- return new Promise(function (resolve, reject) {
76
- return setTimeout(function () {
77
- if (req === 0) {
78
- reject(new Error('fail'));
79
- }
80
- else {
81
- resolve('success');
82
- }
83
- }, 1000);
84
- });
85
- }
86
- export var noop = function () { };
87
- export function on(obj) {
88
- var args = [];
89
- for (var _i = 1; _i < arguments.length; _i++) {
90
- args[_i - 1] = arguments[_i];
91
- }
92
- if (obj && obj.addEventListener) {
93
- obj.addEventListener.apply(obj, args);
94
- }
95
- }
96
- export function off(obj) {
97
- var args = [];
98
- for (var _i = 1; _i < arguments.length; _i++) {
99
- args[_i - 1] = arguments[_i];
100
- }
101
- if (obj && obj.removeEventListener) {
102
- obj.removeEventListener.apply(obj, args);
103
- }
104
- }