@zlikemario/helper 0.0.1 → 0.0.3

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.
@@ -0,0 +1 @@
1
+ export declare function memoize<Args extends unknown[]>(duration?: number, computeKey?: (...args: Args) => unknown, isCacheVoid?: boolean): <T>(_: unknown, _key: string, descriptor: TypedPropertyDescriptor<(...args: Args) => Promise<T>>) => TypedPropertyDescriptor<(...args: Args) => Promise<T>> | void;
package/dist/number.d.ts CHANGED
@@ -4,9 +4,6 @@
4
4
  import BigNumber from "bignumber.js";
5
5
  export { BigNumber };
6
6
  export default BigNumber;
7
- export type Numberish = string | number | bigint | BigNumber;
8
- export type NumberString = string;
9
- export type MaybeUndefined<T> = T | undefined;
10
7
  /**
11
8
  * 判断是否为有效数字
12
9
  * @param num - 待判断的值
package/dist/number.js CHANGED
@@ -46,10 +46,7 @@ const p = (t, e = 4) => {
46
46
  }, $ = (t) => t.reduce((e, i) => e.plus(i), o(0)).toString();
47
47
  function b(t, e) {
48
48
  const i = typeof e == "function" ? (r) => e(r) : (r) => r?.[e] ?? "0";
49
- return t.reduce(
50
- (r, n) => r.plus(i(n)),
51
- o(0)
52
- ).toString();
49
+ return t.reduce((r, n) => r.plus(i(n)), o(0)).toString();
53
50
  }
54
51
  export {
55
52
  N as BigNumber,
package/dist/utils.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=(e=1500)=>new Promise(n=>setTimeout(n,e));function l(e,n=4,r=4,t="..."){return!e||e.length<=n+r?e:e.slice(0,n)+t+(r?e.slice(-r):"")}const i=e=>e===void 0,y=(...e)=>e.some(i),m=e=>!!e&&typeof e?.then=="function"&&typeof e?.catch=="function";function s(e){let n="";for(let r=0;r<e.length;r++)n+=String.fromCharCode(e[r]);return btoa(n)}function d(e){const n=atob(e),r=new Uint8Array(n.length);for(let t=0;t<n.length;t++)r[t]=n.charCodeAt(t);return r}function h(e){return s(new Uint8Array(e))}function o(e){if(typeof e!="string"||(e=e.toLowerCase(),!/^[0-9a-z.\-]+$/.test(e))||e.includes("--")||e.includes("-.")||e.includes(".-")||e.startsWith("-")||e.endsWith("-"))return!1;const n=e.split(".");return!(n.length<2||n.some(r=>!r.length)||n[n.length-1].length<2)}function g(e){const[n,...r]=e.toLowerCase().split("@");if(!n||!r.length||!/^[a-z0-9._-]+$/.test(n)||/^\.|\.$/.test(n)||/[.\-_]{2,}/.test(n)||/[.\-_](?![a-z0-9])/.test(n))return!1;for(const t of r)if(!o(t))return!1;return!0}const p=async(e,n)=>{try{return await e}catch(r){return n?.(r)}};async function T(e,n){const{errorMessage:r="Timeout",duration:t=15e3}=n||{},a=typeof e=="function"?e():e,u=new Promise((A,f)=>setTimeout(()=>f(new Error(r)),t));return Promise.race([a,u])}exports.arrayBufferToBase64=h;exports.base64ToUint8Array=d;exports.encrypt=l;exports.isDomain=o;exports.isEmail=g;exports.isHasUndefined=y;exports.isPromise=m;exports.isUndefined=i;exports.preventTimeout=T;exports.sleep=c;exports.tryCatchAsync=p;exports.uint8ArrayToBase64=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=(e=1500)=>new Promise(n=>setTimeout(n,e));function l(e,n=4,r=4,t="..."){return!e||e.length<=n+r?e:e.slice(0,n)+t+(r?e.slice(-r):"")}const i=e=>e===void 0,m=(...e)=>e.some(i),y=e=>!!e&&typeof e?.then=="function"&&typeof e?.catch=="function";function s(e){let n="";for(let r=0;r<e.length;r++)n+=String.fromCharCode(e[r]);return btoa(n)}function d(e){const n=atob(e),r=new Uint8Array(n.length);for(let t=0;t<n.length;t++)r[t]=n.charCodeAt(t);return r}function h(e){return s(new Uint8Array(e))}function o(e){if(typeof e!="string"||(e=e.toLowerCase(),!/^[0-9a-z.\-]+$/.test(e))||e.includes("--")||e.includes("-.")||e.includes(".-")||e.startsWith("-")||e.endsWith("-"))return!1;const n=e.split(".");return!(n.length<2||n.some(r=>!r.length)||n[n.length-1].length<2)}function g(e){const[n,...r]=e.toLowerCase().split("@");if(!n||!r.length||!/^[a-z0-9._-]+$/.test(n)||/^\.|\.$/.test(n)||/[.\-_]{2,}/.test(n)||/[.\-_](?![a-z0-9])/.test(n))return!1;for(const t of r)if(!o(t))return!1;return!0}const p=async(e,n)=>{try{return await e}catch(r){return n?.(r)}};async function T(e,n){const{errorMessage:r="Timeout",duration:t=15e3}=n||{},a=typeof e=="function"?e():e,u=new Promise((A,f)=>setTimeout(()=>f(new Error(r)),t));return Promise.race([a,u])}const P=(e,n,r)=>e.some(i)?r:n(...e);exports.arrayBufferToBase64=h;exports.base64ToUint8Array=d;exports.computeWithDefinedParams=P;exports.encrypt=l;exports.isDomain=o;exports.isEmail=g;exports.isHasUndefined=m;exports.isPromise=y;exports.isUndefined=i;exports.preventTimeout=T;exports.sleep=c;exports.tryCatchAsync=p;exports.uint8ArrayToBase64=s;
package/dist/utils.d.ts CHANGED
@@ -88,3 +88,7 @@ export declare function preventTimeout<R>(callback: (() => Promise<R>) | Promise
88
88
  errorMessage?: string;
89
89
  duration?: number;
90
90
  }): Promise<R>;
91
+ export type ParamsWithMaybeUndefined<T extends readonly unknown[]> = {
92
+ [K in keyof T]: T[K] | undefined;
93
+ };
94
+ export declare const computeWithDefinedParams: <T extends readonly unknown[], R, StandbyR extends MaybeUndefined<R>>(params: ParamsWithMaybeUndefined<T>, compute: (...args: T) => R, standby?: StandbyR) => StandbyR extends undefined ? MaybeUndefined<R> : R;
package/dist/utils.js CHANGED
@@ -1,57 +1,59 @@
1
- const l = (n = 1500) => new Promise((e) => setTimeout(e, n));
2
- function m(n, e = 4, r = 4, t = "...") {
3
- return !n || n.length <= e + r ? n : n.slice(0, e) + t + (r ? n.slice(-r) : "");
1
+ const l = (e = 1500) => new Promise((n) => setTimeout(n, e));
2
+ function m(e, n = 4, r = 4, t = "...") {
3
+ return !e || e.length <= n + r ? e : e.slice(0, n) + t + (r ? e.slice(-r) : "");
4
4
  }
5
- const a = (n) => n === void 0, h = (...n) => n.some(a), y = (n) => !!n && typeof n?.then == "function" && typeof n?.catch == "function";
6
- function u(n) {
7
- let e = "";
8
- for (let r = 0; r < n.length; r++)
9
- e += String.fromCharCode(n[r]);
10
- return btoa(e);
5
+ const s = (e) => e === void 0, h = (...e) => e.some(s), y = (e) => !!e && typeof e?.then == "function" && typeof e?.catch == "function";
6
+ function u(e) {
7
+ let n = "";
8
+ for (let r = 0; r < e.length; r++)
9
+ n += String.fromCharCode(e[r]);
10
+ return btoa(n);
11
11
  }
12
- function d(n) {
13
- const e = atob(n), r = new Uint8Array(e.length);
14
- for (let t = 0; t < e.length; t++)
15
- r[t] = e.charCodeAt(t);
12
+ function d(e) {
13
+ const n = atob(e), r = new Uint8Array(n.length);
14
+ for (let t = 0; t < n.length; t++)
15
+ r[t] = n.charCodeAt(t);
16
16
  return r;
17
17
  }
18
- function g(n) {
19
- return u(new Uint8Array(n));
18
+ function g(e) {
19
+ return u(new Uint8Array(e));
20
20
  }
21
- function f(n) {
22
- if (typeof n != "string" || (n = n.toLowerCase(), !/^[0-9a-z.\-]+$/.test(n)) || n.includes("--") || n.includes("-.") || n.includes(".-") || n.startsWith("-") || n.endsWith("-"))
21
+ function f(e) {
22
+ if (typeof e != "string" || (e = e.toLowerCase(), !/^[0-9a-z.\-]+$/.test(e)) || e.includes("--") || e.includes("-.") || e.includes(".-") || e.startsWith("-") || e.endsWith("-"))
23
23
  return !1;
24
- const e = n.split(".");
25
- return !(e.length < 2 || e.some((r) => !r.length) || e[e.length - 1].length < 2);
24
+ const n = e.split(".");
25
+ return !(n.length < 2 || n.some((r) => !r.length) || n[n.length - 1].length < 2);
26
26
  }
27
- function p(n) {
28
- const [e, ...r] = n.toLowerCase().split("@");
29
- if (!e || !r.length || !/^[a-z0-9._-]+$/.test(e) || /^\.|\.$/.test(e) || /[.\-_]{2,}/.test(e) || /[.\-_](?![a-z0-9])/.test(e)) return !1;
27
+ function p(e) {
28
+ const [n, ...r] = e.toLowerCase().split("@");
29
+ if (!n || !r.length || !/^[a-z0-9._-]+$/.test(n) || /^\.|\.$/.test(n) || /[.\-_]{2,}/.test(n) || /[.\-_](?![a-z0-9])/.test(n)) return !1;
30
30
  for (const t of r)
31
31
  if (!f(t)) return !1;
32
32
  return !0;
33
33
  }
34
- const w = async (n, e) => {
34
+ const w = async (e, n) => {
35
35
  try {
36
- return await n;
36
+ return await e;
37
37
  } catch (r) {
38
- return e?.(r);
38
+ return n?.(r);
39
39
  }
40
40
  };
41
- async function T(n, e) {
42
- const { errorMessage: r = "Timeout", duration: t = 15e3 } = e || {}, s = typeof n == "function" ? n() : n, i = new Promise((c, o) => setTimeout(() => o(new Error(r)), t));
43
- return Promise.race([s, i]);
41
+ async function P(e, n) {
42
+ const { errorMessage: r = "Timeout", duration: t = 15e3 } = n || {}, o = typeof e == "function" ? e() : e, i = new Promise((c, a) => setTimeout(() => a(new Error(r)), t));
43
+ return Promise.race([o, i]);
44
44
  }
45
+ const T = (e, n, r) => e.some(s) ? r : n(...e);
45
46
  export {
46
47
  g as arrayBufferToBase64,
47
48
  d as base64ToUint8Array,
49
+ T as computeWithDefinedParams,
48
50
  m as encrypt,
49
51
  f as isDomain,
50
52
  p as isEmail,
51
53
  h as isHasUndefined,
52
54
  y as isPromise,
53
- a as isUndefined,
54
- T as preventTimeout,
55
+ s as isUndefined,
56
+ P as preventTimeout,
55
57
  l as sleep,
56
58
  w as tryCatchAsync,
57
59
  u as uint8ArrayToBase64
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zlikemario/helper",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A utility library with number operations and common helper functions",
5
5
  "keywords": [
6
6
  "utility",
@@ -41,7 +41,15 @@
41
41
  "vite-plugin-dts": "^4.5.4",
42
42
  "vitest": "^3.2.4"
43
43
  },
44
+ "main": "./dist/number.js",
45
+ "module": "./dist/number.js",
46
+ "types": "./dist/number.d.ts",
44
47
  "exports": {
48
+ ".": {
49
+ "types": "./dist/number.d.ts",
50
+ "import": "./dist/number.js",
51
+ "require": "./dist/number.cjs"
52
+ },
45
53
  "./number": {
46
54
  "types": "./dist/number.d.ts",
47
55
  "import": "./dist/number.js",
package/dist/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>