umaki 0.2.6 → 0.3.1
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/README.md +41 -1
- package/dist/_virtual/_commonjsHelpers.cjs.js +1 -1
- package/dist/_virtual/_commonjsHelpers.es.js +1 -1
- package/dist/_virtual/isBetween.cjs.js +1 -1
- package/dist/_virtual/isBetween.es.js +1 -1
- package/dist/index.cjs.js +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +5 -1
- package/dist/libs/control/bgScrollStop.cjs.js +1 -1
- package/dist/libs/control/bgScrollStop.es.js +1 -1
- package/dist/libs/control/pd.cjs.js +1 -1
- package/dist/libs/control/pd.es.js +1 -1
- package/dist/libs/control/scrollToHash.cjs.js +1 -1
- package/dist/libs/control/scrollToHash.es.js +1 -1
- package/dist/libs/control/videoPlayControl.cjs.js +3 -3
- package/dist/libs/control/videoPlayControl.d.ts +1 -1
- package/dist/libs/control/videoPlayControl.es.js +3 -3
- package/dist/libs/convert/changeDateStringToSpecificFormat.cjs.js +1 -1
- package/dist/libs/convert/changeDateStringToSpecificFormat.es.js +1 -1
- package/dist/libs/convert/jsonStringToJsonObject.cjs.js +1 -1
- package/dist/libs/convert/jsonStringToJsonObject.es.js +1 -1
- package/dist/libs/eventControl/debounce.cjs.js +24 -0
- package/dist/libs/eventControl/debounce.d.ts +11 -0
- package/dist/libs/eventControl/debounce.es.js +24 -0
- package/dist/libs/eventControl/debounce.test.d.ts +1 -0
- package/dist/libs/eventControl/index.d.ts +5 -0
- package/dist/libs/eventControl/throttle.cjs.js +24 -0
- package/dist/libs/eventControl/throttle.d.ts +12 -0
- package/dist/libs/eventControl/throttle.es.js +24 -0
- package/dist/libs/eventControl/throttle.test.d.ts +1 -0
- package/dist/libs/get/getAspectRatio.cjs.js +1 -1
- package/dist/libs/get/getAspectRatio.es.js +1 -1
- package/dist/libs/get/getClassNames.cjs.js +1 -1
- package/dist/libs/get/getClassNames.es.js +1 -1
- package/dist/libs/get/getDocumentHeight.cjs.js +1 -1
- package/dist/libs/get/getDocumentHeight.es.js +1 -1
- package/dist/libs/get/getEventPaths.cjs.js +1 -1
- package/dist/libs/get/getEventPaths.es.js +1 -1
- package/dist/libs/get/getGcd.cjs.js +1 -1
- package/dist/libs/get/getGcd.es.js +1 -1
- package/dist/libs/get/getOrientation.cjs.js +1 -1
- package/dist/libs/get/getOrientation.es.js +1 -1
- package/dist/libs/get/getParentList.cjs.js +1 -1
- package/dist/libs/get/getParentList.es.js +1 -1
- package/dist/libs/get/getQueryParams.cjs.js +1 -1
- package/dist/libs/get/getQueryParams.es.js +1 -1
- package/dist/libs/get/getRem.cjs.js +1 -1
- package/dist/libs/get/getRem.es.js +1 -1
- package/dist/libs/get/getScrollbarWidth.cjs.js +1 -1
- package/dist/libs/get/getScrollbarWidth.es.js +1 -1
- package/dist/libs/get/getSessionStorage.cjs.js +1 -1
- package/dist/libs/get/getSessionStorage.es.js +1 -1
- package/dist/libs/get/getStringLength.cjs.js +1 -1
- package/dist/libs/get/getStringLength.es.js +1 -1
- package/dist/libs/get/getStylePropertyValue.cjs.js +1 -1
- package/dist/libs/get/getStylePropertyValue.es.js +1 -1
- package/dist/libs/get/getStylePropertyValueToNumber.cjs.js +1 -1
- package/dist/libs/get/getStylePropertyValueToNumber.es.js +1 -1
- package/dist/libs/get/getUaData.cjs.js +1 -1
- package/dist/libs/get/getUaData.es.js +1 -1
- package/dist/libs/is/isBetweenDateTime.cjs.js +1 -1
- package/dist/libs/is/isBetweenDateTime.es.js +1 -1
- package/dist/libs/is/isExistAllElements.cjs.js +1 -1
- package/dist/libs/is/isExistAllElements.es.js +1 -1
- package/dist/libs/is/isIpad.cjs.js +1 -1
- package/dist/libs/is/isIpad.es.js +1 -1
- package/dist/libs/is/isKeyExists.cjs.js +1 -1
- package/dist/libs/is/isKeyExists.es.js +1 -1
- package/dist/libs/is/isSafari.cjs.js +1 -1
- package/dist/libs/is/isSafari.es.js +1 -1
- package/dist/libs/is/isScrollable.cjs.js +1 -1
- package/dist/libs/is/isScrollable.es.js +1 -1
- package/dist/libs/is/isTouchSupport.cjs.js +1 -1
- package/dist/libs/is/isTouchSupport.es.js +1 -1
- package/dist/libs/remove/removeAllHtmlTags.cjs.js +1 -1
- package/dist/libs/remove/removeAllHtmlTags.es.js +1 -1
- package/dist/libs/remove/removeAttribute.cjs.js +1 -1
- package/dist/libs/remove/removeAttribute.es.js +1 -1
- package/dist/libs/remove/removeSessionStorage.cjs.js +1 -1
- package/dist/libs/remove/removeSessionStorage.es.js +1 -1
- package/dist/libs/remove/removeStylePropertyValue.cjs.js +1 -1
- package/dist/libs/remove/removeStylePropertyValue.es.js +1 -1
- package/dist/libs/set/set100vh.cjs.js +1 -1
- package/dist/libs/set/set100vh.es.js +1 -1
- package/dist/libs/set/set100vw.cjs.js +1 -1
- package/dist/libs/set/set100vw.es.js +1 -1
- package/dist/libs/set/setAttribute.cjs.js +1 -1
- package/dist/libs/set/setAttribute.es.js +1 -1
- package/dist/libs/set/setScrollPositionToCenter.cjs.js +1 -1
- package/dist/libs/set/setScrollPositionToCenter.es.js +1 -1
- package/dist/libs/set/setSessionStorage.cjs.js +1 -1
- package/dist/libs/set/setSessionStorage.es.js +1 -1
- package/dist/libs/set/setStylePropertyValue.cjs.js +1 -1
- package/dist/libs/set/setStylePropertyValue.es.js +1 -1
- package/dist/libs/to/toBoolean.cjs.js +1 -1
- package/dist/libs/to/toBoolean.es.js +1 -1
- package/dist/libs/to/toPositiveNumber.cjs.js +1 -1
- package/dist/libs/to/toPositiveNumber.es.js +1 -1
- package/dist/libs/transform/wrapTextWithSpans.cjs.js +1 -1
- package/dist/libs/transform/wrapTextWithSpans.es.js +1 -1
- package/dist/libs/wait/sleep.cjs.js +1 -1
- package/dist/libs/wait/sleep.es.js +1 -1
- package/dist/libs/wait/waitForAllMediaLoaded.cjs.js +1 -1
- package/dist/libs/wait/waitForAllMediaLoaded.es.js +1 -1
- package/dist/node_modules/dayjs/plugin/isBetween.cjs.js +1 -1
- package/dist/node_modules/dayjs/plugin/isBetween.es.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,9 @@ import { foo } from 'umaki'
|
|
|
26
26
|
- [Convert](#convert)
|
|
27
27
|
- [changeDateStringToSpecificFormat](#changedatestringtospecificformat)
|
|
28
28
|
- [jsonStringToJsonObject](#jsonstringtojsonobject)
|
|
29
|
+
- [EventControl](#eventcontrol)
|
|
30
|
+
- [debounce](#debounce)
|
|
31
|
+
- [throttle](#throttle)
|
|
29
32
|
- [Get](#get)
|
|
30
33
|
- [getAspectRatio](#getaspectratio)
|
|
31
34
|
- [getClassNames](#getclassnames)
|
|
@@ -129,6 +132,9 @@ import { videoPlayControl } from 'umaki'
|
|
|
129
132
|
const videoElement = document.getElementById('myVideo')
|
|
130
133
|
videoPlayControl(videoElement, true) // play
|
|
131
134
|
videoPlayControl(videoElement, false) // pause
|
|
135
|
+
|
|
136
|
+
// set currentTime
|
|
137
|
+
videoPlayControl(videoElement, true, 10) // play and set currentTime to 10
|
|
132
138
|
```
|
|
133
139
|
|
|
134
140
|
[View file →](src/libs/control/videoPlayControl.ts)
|
|
@@ -163,6 +169,40 @@ console.log(jsonObject) // { name: 'John', age: 30 }
|
|
|
163
169
|
|
|
164
170
|
[View file →](src/libs/convert/jsonStringToJsonObject.ts)
|
|
165
171
|
|
|
172
|
+
## EventControl
|
|
173
|
+
|
|
174
|
+
### debounce
|
|
175
|
+
|
|
176
|
+
A function that limits the number of times a function is called to at most one time over a specified time period.
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
import { debounce } from 'umaki'
|
|
180
|
+
|
|
181
|
+
const debouncedFunction = debounce(() => {
|
|
182
|
+
console.log('Debounced!')
|
|
183
|
+
}, 300)
|
|
184
|
+
|
|
185
|
+
window.addEventListener('resize', debouncedFunction)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
[View file →](src/libs/eventControl/debounce.ts)
|
|
189
|
+
|
|
190
|
+
### throttle
|
|
191
|
+
|
|
192
|
+
A function that limits the number of times a function is called to a maximum of once in a specified period.
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import { throttle } from 'umaki'
|
|
196
|
+
|
|
197
|
+
const throttledFunction = throttle(() => {
|
|
198
|
+
console.log('Throttled!')
|
|
199
|
+
}, 300)
|
|
200
|
+
|
|
201
|
+
window.addEventListener('scroll', throttledFunction)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
[View file →](src/libs/eventControl/throttle.ts)
|
|
205
|
+
|
|
166
206
|
## Get
|
|
167
207
|
|
|
168
208
|
### getAspectRatio
|
|
@@ -681,7 +721,7 @@ import { sleep } from 'umaki'
|
|
|
681
721
|
|
|
682
722
|
;(async () => {
|
|
683
723
|
console.log('Start')
|
|
684
|
-
await sleep(1) //
|
|
724
|
+
await sleep(1) // 1s wait
|
|
685
725
|
console.log('End')
|
|
686
726
|
})()
|
|
687
727
|
```
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*!
|
|
3
3
|
* name: umaki
|
|
4
|
-
* version: v0.
|
|
4
|
+
* version: v0.3.1
|
|
5
5
|
* description: A utility that is often used in web production.
|
|
6
6
|
* author: TsubasaHiga
|
|
7
7
|
* homepage: https://github.com/TsubasaHiga/umaki
|
|
@@ -17,6 +17,8 @@ const scrollToHash = require("./libs/control/scrollToHash.cjs.js");
|
|
|
17
17
|
const videoPlayControl = require("./libs/control/videoPlayControl.cjs.js");
|
|
18
18
|
const changeDateStringToSpecificFormat = require("./libs/convert/changeDateStringToSpecificFormat.cjs.js");
|
|
19
19
|
const jsonStringToJsonObject = require("./libs/convert/jsonStringToJsonObject.cjs.js");
|
|
20
|
+
const debounce = require("./libs/eventControl/debounce.cjs.js");
|
|
21
|
+
const throttle = require("./libs/eventControl/throttle.cjs.js");
|
|
20
22
|
const getAspectRatio = require("./libs/get/getAspectRatio.cjs.js");
|
|
21
23
|
const getClassNames = require("./libs/get/getClassNames.cjs.js");
|
|
22
24
|
const getDocumentHeight = require("./libs/get/getDocumentHeight.cjs.js");
|
|
@@ -60,6 +62,8 @@ exports.scrollToHash = scrollToHash.scrollToHash;
|
|
|
60
62
|
exports.videoPlayControl = videoPlayControl.videoPlayControl;
|
|
61
63
|
exports.changeDateStringToSpecificFormat = changeDateStringToSpecificFormat.changeDateStringToSpecificFormat;
|
|
62
64
|
exports.jsonStringToJsonObject = jsonStringToJsonObject.jsonStringToJsonObject;
|
|
65
|
+
exports.debounce = debounce.debounce;
|
|
66
|
+
exports.throttle = throttle.throttle;
|
|
63
67
|
exports.getAspectRatio = getAspectRatio.getAspectRatio;
|
|
64
68
|
exports.getClassNames = getClassNames.getClassNames;
|
|
65
69
|
exports.getDocumentHeight = getDocumentHeight.getDocumentHeight;
|
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: umaki
|
|
3
|
-
* version: v0.
|
|
3
|
+
* version: v0.3.1
|
|
4
4
|
* description: A utility that is often used in web production.
|
|
5
5
|
* author: TsubasaHiga
|
|
6
6
|
* homepage: https://github.com/TsubasaHiga/umaki
|
|
@@ -15,6 +15,8 @@ import { scrollToHash } from "./libs/control/scrollToHash.es.js";
|
|
|
15
15
|
import { videoPlayControl } from "./libs/control/videoPlayControl.es.js";
|
|
16
16
|
import { changeDateStringToSpecificFormat } from "./libs/convert/changeDateStringToSpecificFormat.es.js";
|
|
17
17
|
import { jsonStringToJsonObject } from "./libs/convert/jsonStringToJsonObject.es.js";
|
|
18
|
+
import { debounce } from "./libs/eventControl/debounce.es.js";
|
|
19
|
+
import { throttle } from "./libs/eventControl/throttle.es.js";
|
|
18
20
|
import { getAspectRatio } from "./libs/get/getAspectRatio.es.js";
|
|
19
21
|
import { getClassNames } from "./libs/get/getClassNames.es.js";
|
|
20
22
|
import { getDocumentHeight } from "./libs/get/getDocumentHeight.es.js";
|
|
@@ -55,6 +57,7 @@ import { waitForAllMediaLoaded } from "./libs/wait/waitForAllMediaLoaded.es.js";
|
|
|
55
57
|
export {
|
|
56
58
|
bgScrollStop,
|
|
57
59
|
changeDateStringToSpecificFormat,
|
|
60
|
+
debounce,
|
|
58
61
|
getAspectRatio,
|
|
59
62
|
getClassNames,
|
|
60
63
|
getDocumentHeight,
|
|
@@ -91,6 +94,7 @@ export {
|
|
|
91
94
|
setSessionStorage,
|
|
92
95
|
setStylePropertyValue,
|
|
93
96
|
sleep,
|
|
97
|
+
throttle,
|
|
94
98
|
toBoolean,
|
|
95
99
|
toPositiveNumber,
|
|
96
100
|
videoPlayControl,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*!
|
|
3
3
|
* name: umaki
|
|
4
|
-
* version: v0.
|
|
4
|
+
* version: v0.3.1
|
|
5
5
|
* description: A utility that is often used in web production.
|
|
6
6
|
* author: TsubasaHiga
|
|
7
7
|
* homepage: https://github.com/TsubasaHiga/umaki
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
14
14
|
const toBoolean = require("../to/toBoolean.cjs.js");
|
|
15
|
-
const videoPlayControl = async (videoElement, state) => {
|
|
15
|
+
const videoPlayControl = async (videoElement, state, currentTime) => {
|
|
16
16
|
if (state && videoElement.paused) {
|
|
17
17
|
const isPlaying = toBoolean.toBoolean(videoElement.dataset.playing);
|
|
18
18
|
if (isPlaying) return;
|
|
@@ -20,7 +20,7 @@ const videoPlayControl = async (videoElement, state) => {
|
|
|
20
20
|
if (playPromise === void 0) return;
|
|
21
21
|
try {
|
|
22
22
|
await playPromise;
|
|
23
|
-
videoElement.currentTime = 0;
|
|
23
|
+
videoElement.currentTime = currentTime || 0;
|
|
24
24
|
videoElement.dataset.playing = "true";
|
|
25
25
|
} catch (error) {
|
|
26
26
|
}
|
|
@@ -11,4 +11,4 @@
|
|
|
11
11
|
* the video. The function also manages a custom `data-playing` attribute on the video element
|
|
12
12
|
* to track the playback state.
|
|
13
13
|
*/
|
|
14
|
-
export declare const videoPlayControl: (videoElement: HTMLVideoElement, state: boolean) => Promise<void>;
|
|
14
|
+
export declare const videoPlayControl: (videoElement: HTMLVideoElement, state: boolean, currentTime?: number) => Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: umaki
|
|
3
|
-
* version: v0.
|
|
3
|
+
* version: v0.3.1
|
|
4
4
|
* description: A utility that is often used in web production.
|
|
5
5
|
* author: TsubasaHiga
|
|
6
6
|
* homepage: https://github.com/TsubasaHiga/umaki
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* For license information, please see LICENSE.txt
|
|
11
11
|
*/
|
|
12
12
|
import { toBoolean } from "../to/toBoolean.es.js";
|
|
13
|
-
const videoPlayControl = async (videoElement, state) => {
|
|
13
|
+
const videoPlayControl = async (videoElement, state, currentTime) => {
|
|
14
14
|
if (state && videoElement.paused) {
|
|
15
15
|
const isPlaying = toBoolean(videoElement.dataset.playing);
|
|
16
16
|
if (isPlaying) return;
|
|
@@ -18,7 +18,7 @@ const videoPlayControl = async (videoElement, state) => {
|
|
|
18
18
|
if (playPromise === void 0) return;
|
|
19
19
|
try {
|
|
20
20
|
await playPromise;
|
|
21
|
-
videoElement.currentTime = 0;
|
|
21
|
+
videoElement.currentTime = currentTime || 0;
|
|
22
22
|
videoElement.dataset.playing = "true";
|
|
23
23
|
} catch (error) {
|
|
24
24
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* name: umaki
|
|
4
|
+
* version: v0.3.1
|
|
5
|
+
* description: A utility that is often used in web production.
|
|
6
|
+
* author: TsubasaHiga
|
|
7
|
+
* homepage: https://github.com/TsubasaHiga/umaki
|
|
8
|
+
* Released under the MIT License
|
|
9
|
+
*
|
|
10
|
+
* This software includes dependencies licensed under MIT, ISC, BSD-3-Clause, and Apache-2.0.
|
|
11
|
+
* For license information, please see LICENSE.txt
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
const debounce = (fn, delay) => {
|
|
15
|
+
let timeoutId = null;
|
|
16
|
+
return (...args) => {
|
|
17
|
+
timeoutId && clearTimeout(timeoutId);
|
|
18
|
+
timeoutId = setTimeout(() => {
|
|
19
|
+
fn(...args);
|
|
20
|
+
timeoutId = null;
|
|
21
|
+
}, delay);
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.debounce = debounce;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type DebounceProcedure = (...args: unknown[]) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Creates a debounced function that delays invoking the provided function until after the specified delay.
|
|
4
|
+
*
|
|
5
|
+
* @template F - The type of the function to debounce.
|
|
6
|
+
* @param {F} fn - The function to debounce.
|
|
7
|
+
* @param {number} delay - The number of milliseconds to delay.
|
|
8
|
+
* @returns {(...args: Parameters<F>) => void} - A debounced version of the provided function.
|
|
9
|
+
*/
|
|
10
|
+
export declare const debounce: <F extends DebounceProcedure>(fn: F, delay: number) => ((...args: Parameters<F>) => void);
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* name: umaki
|
|
3
|
+
* version: v0.3.1
|
|
4
|
+
* description: A utility that is often used in web production.
|
|
5
|
+
* author: TsubasaHiga
|
|
6
|
+
* homepage: https://github.com/TsubasaHiga/umaki
|
|
7
|
+
* Released under the MIT License
|
|
8
|
+
*
|
|
9
|
+
* This software includes dependencies licensed under MIT, ISC, BSD-3-Clause, and Apache-2.0.
|
|
10
|
+
* For license information, please see LICENSE.txt
|
|
11
|
+
*/
|
|
12
|
+
const debounce = (fn, delay) => {
|
|
13
|
+
let timeoutId = null;
|
|
14
|
+
return (...args) => {
|
|
15
|
+
timeoutId && clearTimeout(timeoutId);
|
|
16
|
+
timeoutId = setTimeout(() => {
|
|
17
|
+
fn(...args);
|
|
18
|
+
timeoutId = null;
|
|
19
|
+
}, delay);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
debounce
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* name: umaki
|
|
4
|
+
* version: v0.3.1
|
|
5
|
+
* description: A utility that is often used in web production.
|
|
6
|
+
* author: TsubasaHiga
|
|
7
|
+
* homepage: https://github.com/TsubasaHiga/umaki
|
|
8
|
+
* Released under the MIT License
|
|
9
|
+
*
|
|
10
|
+
* This software includes dependencies licensed under MIT, ISC, BSD-3-Clause, and Apache-2.0.
|
|
11
|
+
* For license information, please see LICENSE.txt
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
14
|
+
const throttle = (fn, wait) => {
|
|
15
|
+
let lastCallTime = 0;
|
|
16
|
+
return (...args) => {
|
|
17
|
+
const currentTime = Date.now();
|
|
18
|
+
if (currentTime - lastCallTime >= wait) {
|
|
19
|
+
fn(...args);
|
|
20
|
+
lastCallTime = currentTime;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.throttle = throttle;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type ThrottleFunction = (...args: unknown[]) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Creates a throttled version of the provided function that will only execute
|
|
4
|
+
* at most once in the specified wait period.
|
|
5
|
+
*
|
|
6
|
+
* @template F - The type of the function to be throttled.
|
|
7
|
+
* @param fn - The function to throttle.
|
|
8
|
+
* @param wait - The number of milliseconds to wait before allowing the next execution.
|
|
9
|
+
* @returns A throttled version of the provided function.
|
|
10
|
+
*/
|
|
11
|
+
export declare const throttle: <F extends ThrottleFunction>(fn: F, wait: number) => ((...args: Parameters<F>) => void);
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* name: umaki
|
|
3
|
+
* version: v0.3.1
|
|
4
|
+
* description: A utility that is often used in web production.
|
|
5
|
+
* author: TsubasaHiga
|
|
6
|
+
* homepage: https://github.com/TsubasaHiga/umaki
|
|
7
|
+
* Released under the MIT License
|
|
8
|
+
*
|
|
9
|
+
* This software includes dependencies licensed under MIT, ISC, BSD-3-Clause, and Apache-2.0.
|
|
10
|
+
* For license information, please see LICENSE.txt
|
|
11
|
+
*/
|
|
12
|
+
const throttle = (fn, wait) => {
|
|
13
|
+
let lastCallTime = 0;
|
|
14
|
+
return (...args) => {
|
|
15
|
+
const currentTime = Date.now();
|
|
16
|
+
if (currentTime - lastCallTime >= wait) {
|
|
17
|
+
fn(...args);
|
|
18
|
+
lastCallTime = currentTime;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
throttle
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|