@xyx-utils/core 0.0.1 → 0.0.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @xyx-utils/core
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 增加 exports 字段
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ const date_parse_index = require('./date/parse/index.cjs');
5
5
  const date_friendly_index = require('./date/friendly/index.cjs');
6
6
  const common_padLeftZero_index = require('./common/padLeftZero/index.cjs');
7
7
  const debounce_index = require('./debounce/index.cjs');
8
+ const throttle_index = require('./throttle/index.cjs');
8
9
 
9
10
 
10
11
 
@@ -13,3 +14,4 @@ exports.parse = date_parse_index.parse;
13
14
  exports.formatTimeFriendly = date_friendly_index.formatTimeFriendly;
14
15
  exports.padLeftZero = common_padLeftZero_index.padLeftZero;
15
16
  exports.debounce = debounce_index.debounce;
17
+ exports.throttle = throttle_index.throttle;
package/dist/index.d.cts CHANGED
@@ -3,3 +3,4 @@ export { parse } from './date/parse/index.cjs';
3
3
  export { formatTimeFriendly } from './date/friendly/index.cjs';
4
4
  export { padLeftZero } from './common/padLeftZero/index.cjs';
5
5
  export { debounce } from './debounce/index.cjs';
6
+ export { throttle } from './throttle/index.cjs';
package/dist/index.d.mts CHANGED
@@ -3,3 +3,4 @@ export { parse } from './date/parse/index.mjs';
3
3
  export { formatTimeFriendly } from './date/friendly/index.mjs';
4
4
  export { padLeftZero } from './common/padLeftZero/index.mjs';
5
5
  export { debounce } from './debounce/index.mjs';
6
+ export { throttle } from './throttle/index.mjs';
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { parse } from './date/parse/index.js';
3
3
  export { formatTimeFriendly } from './date/friendly/index.js';
4
4
  export { padLeftZero } from './common/padLeftZero/index.js';
5
5
  export { debounce } from './debounce/index.js';
6
+ export { throttle } from './throttle/index.js';
package/dist/index.mjs CHANGED
@@ -3,3 +3,4 @@ export { parse } from './date/parse/index.mjs';
3
3
  export { formatTimeFriendly } from './date/friendly/index.mjs';
4
4
  export { padLeftZero } from './common/padLeftZero/index.mjs';
5
5
  export { debounce } from './debounce/index.mjs';
6
+ export { throttle } from './throttle/index.mjs';
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ function throttle(fn, interval = 200) {
4
+ let last;
5
+ let timer;
6
+ return function(...argu) {
7
+ const now = +/* @__PURE__ */ new Date();
8
+ if (last && now - last < interval) {
9
+ timer && clearTimeout(timer);
10
+ timer = setTimeout(() => {
11
+ last = now;
12
+ fn.apply(this, argu);
13
+ }, interval);
14
+ } else {
15
+ last = now;
16
+ fn.apply(this, argu);
17
+ }
18
+ };
19
+ }
20
+
21
+ exports.throttle = throttle;
@@ -0,0 +1,3 @@
1
+ declare function throttle<T extends any[], R = void>(fn: (...argu: T) => R, interval?: number): (this: void, ...argu: T) => void;
2
+
3
+ export { throttle };
@@ -0,0 +1,3 @@
1
+ declare function throttle<T extends any[], R = void>(fn: (...argu: T) => R, interval?: number): (this: void, ...argu: T) => void;
2
+
3
+ export { throttle };
@@ -0,0 +1,3 @@
1
+ declare function throttle<T extends any[], R = void>(fn: (...argu: T) => R, interval?: number): (this: void, ...argu: T) => void;
2
+
3
+ export { throttle };
@@ -0,0 +1,19 @@
1
+ function throttle(fn, interval = 200) {
2
+ let last;
3
+ let timer;
4
+ return function(...argu) {
5
+ const now = +/* @__PURE__ */ new Date();
6
+ if (last && now - last < interval) {
7
+ timer && clearTimeout(timer);
8
+ timer = setTimeout(() => {
9
+ last = now;
10
+ fn.apply(this, argu);
11
+ }, interval);
12
+ } else {
13
+ last = now;
14
+ fn.apply(this, argu);
15
+ }
16
+ };
17
+ }
18
+
19
+ export { throttle };
package/package.json CHANGED
@@ -1,12 +1,22 @@
1
1
  {
2
2
  "name": "@xyx-utils/core",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "",
6
6
  "main": "dist/index.mjs",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "readme.md",
10
+ "CHANGELOG.md"
9
11
  ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs"
17
+ },
18
+ "./*": "./dist/*"
19
+ },
10
20
  "keywords": [],
11
21
  "author": "",
12
22
  "license": "ISC",