@daysnap/utils 0.0.66 → 0.0.68

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/es/clamp.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 首选值超出最小值,返回最小值;首选值超出最大值,返回最大值;其余返回首选值
3
+ * @param min 最小值
4
+ * @param x 首选值
5
+ * @param max 最大值
6
+ */
7
+ export declare function clamp(min: number, val: number, max: number): number;
package/es/clamp.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 首选值超出最小值,返回最小值;首选值超出最大值,返回最大值;其余返回首选值
3
+ * @param min 最小值
4
+ * @param x 首选值
5
+ * @param max 最大值
6
+ */
7
+ export function clamp(min, val, max) {
8
+ if (val < min) {
9
+ return min;
10
+ }
11
+ if (val > max) {
12
+ return max;
13
+ }
14
+ return val;
15
+ }
@@ -0,0 +1,10 @@
1
+ import { Loose } from '@daysnap/types';
2
+ /**
3
+ * loading 生成器
4
+ * const withLoading = createWithLoading(() => showLoading())
5
+ * const fn = withLoading(async () => { // ... })
6
+ * fn() 执行的时候就会执行showLoading
7
+ */
8
+ export declare function createWithLoading<O = any>(showLoading: (options: O) => Loose<{
9
+ close: () => any;
10
+ }>): <T extends (...args: any[]) => Promise<any>>(fn: T, options?: O) => (...params: [...Parameters<T>, (O | undefined)?]) => Promise<Awaited<ReturnType<T>>>;
@@ -0,0 +1,35 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /**
11
+ * loading 生成器
12
+ * const withLoading = createWithLoading(() => showLoading())
13
+ * const fn = withLoading(async () => { // ... })
14
+ * fn() 执行的时候就会执行showLoading
15
+ */
16
+ export function createWithLoading(showLoading) {
17
+ return function withLoading(fn, options) {
18
+ return (...params) => __awaiter(this, void 0, void 0, function* () {
19
+ if (params.length > fn.length) {
20
+ options = params.pop();
21
+ }
22
+ const toast = options ? showLoading(options) : null;
23
+ try {
24
+ return yield fn(params);
25
+ // eslint-disable-next-line no-useless-catch
26
+ }
27
+ catch (error) {
28
+ throw error;
29
+ }
30
+ finally {
31
+ toast === null || toast === void 0 ? void 0 : toast.close();
32
+ }
33
+ });
34
+ };
35
+ }
package/es/index.d.ts CHANGED
@@ -4,11 +4,13 @@ export * from './cached';
4
4
  export * from './camelCase';
5
5
  export * from './canvasToBlob';
6
6
  export * from './capitalize';
7
+ export * from './clamp';
7
8
  export * from './clone';
8
9
  export * from './cloneSimple';
9
10
  export * from './compareVersion';
10
11
  export * from './compressImage';
11
12
  export * from './createHexColorByHash';
13
+ export * from './createWithLoading';
12
14
  export * from './debounce';
13
15
  export * from './downloadFile';
14
16
  export * from './each';
package/es/index.js CHANGED
@@ -5,11 +5,13 @@ export * from './cached';
5
5
  export * from './camelCase';
6
6
  export * from './canvasToBlob';
7
7
  export * from './capitalize';
8
+ export * from './clamp';
8
9
  export * from './clone';
9
10
  export * from './cloneSimple';
10
11
  export * from './compareVersion';
11
12
  export * from './compressImage';
12
13
  export * from './createHexColorByHash';
14
+ export * from './createWithLoading';
13
15
  export * from './debounce';
14
16
  export * from './downloadFile';
15
17
  export * from './each';
package/lib/clamp.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 首选值超出最小值,返回最小值;首选值超出最大值,返回最大值;其余返回首选值
3
+ * @param min 最小值
4
+ * @param x 首选值
5
+ * @param max 最大值
6
+ */
7
+ export declare function clamp(min: number, val: number, max: number): number;
package/lib/clamp.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clamp = void 0;
4
+ /**
5
+ * 首选值超出最小值,返回最小值;首选值超出最大值,返回最大值;其余返回首选值
6
+ * @param min 最小值
7
+ * @param x 首选值
8
+ * @param max 最大值
9
+ */
10
+ function clamp(min, val, max) {
11
+ if (val < min) {
12
+ return min;
13
+ }
14
+ if (val > max) {
15
+ return max;
16
+ }
17
+ return val;
18
+ }
19
+ exports.clamp = clamp;
@@ -0,0 +1,10 @@
1
+ import { Loose } from '@daysnap/types';
2
+ /**
3
+ * loading 生成器
4
+ * const withLoading = createWithLoading(() => showLoading())
5
+ * const fn = withLoading(async () => { // ... })
6
+ * fn() 执行的时候就会执行showLoading
7
+ */
8
+ export declare function createWithLoading<O = any>(showLoading: (options: O) => Loose<{
9
+ close: () => any;
10
+ }>): <T extends (...args: any[]) => Promise<any>>(fn: T, options?: O) => (...params: [...Parameters<T>, (O | undefined)?]) => Promise<Awaited<ReturnType<T>>>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createWithLoading = void 0;
13
+ /**
14
+ * loading 生成器
15
+ * const withLoading = createWithLoading(() => showLoading())
16
+ * const fn = withLoading(async () => { // ... })
17
+ * fn() 执行的时候就会执行showLoading
18
+ */
19
+ function createWithLoading(showLoading) {
20
+ return function withLoading(fn, options) {
21
+ return (...params) => __awaiter(this, void 0, void 0, function* () {
22
+ if (params.length > fn.length) {
23
+ options = params.pop();
24
+ }
25
+ const toast = options ? showLoading(options) : null;
26
+ try {
27
+ return yield fn(params);
28
+ // eslint-disable-next-line no-useless-catch
29
+ }
30
+ catch (error) {
31
+ throw error;
32
+ }
33
+ finally {
34
+ toast === null || toast === void 0 ? void 0 : toast.close();
35
+ }
36
+ });
37
+ };
38
+ }
39
+ exports.createWithLoading = createWithLoading;
package/lib/index.d.ts CHANGED
@@ -4,11 +4,13 @@ export * from './cached';
4
4
  export * from './camelCase';
5
5
  export * from './canvasToBlob';
6
6
  export * from './capitalize';
7
+ export * from './clamp';
7
8
  export * from './clone';
8
9
  export * from './cloneSimple';
9
10
  export * from './compareVersion';
10
11
  export * from './compressImage';
11
12
  export * from './createHexColorByHash';
13
+ export * from './createWithLoading';
12
14
  export * from './debounce';
13
15
  export * from './downloadFile';
14
16
  export * from './each';
package/lib/index.js CHANGED
@@ -21,11 +21,13 @@ __exportStar(require("./cached"), exports);
21
21
  __exportStar(require("./camelCase"), exports);
22
22
  __exportStar(require("./canvasToBlob"), exports);
23
23
  __exportStar(require("./capitalize"), exports);
24
+ __exportStar(require("./clamp"), exports);
24
25
  __exportStar(require("./clone"), exports);
25
26
  __exportStar(require("./cloneSimple"), exports);
26
27
  __exportStar(require("./compareVersion"), exports);
27
28
  __exportStar(require("./compressImage"), exports);
28
29
  __exportStar(require("./createHexColorByHash"), exports);
30
+ __exportStar(require("./createWithLoading"), exports);
29
31
  __exportStar(require("./debounce"), exports);
30
32
  __exportStar(require("./downloadFile"), exports);
31
33
  __exportStar(require("./each"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daysnap/utils",
3
- "version": "0.0.66",
3
+ "version": "0.0.68",
4
4
  "description": "通用的工具库",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -54,6 +54,7 @@
54
54
  "devDependencies": {
55
55
  "@commitlint/cli": "^16.2.1",
56
56
  "@commitlint/config-conventional": "^16.2.1",
57
+ "@daysnap/types": "^0.0.4",
57
58
  "@types/jest": "^27.5.2",
58
59
  "@typescript-eslint/eslint-plugin": "^5.55.0",
59
60
  "@typescript-eslint/parser": "^5.55.0",