@zlikemario/helper 0.0.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 +79 -0
- package/dist/number.cjs +1 -0
- package/dist/number.d.ts +66 -0
- package/dist/number.js +65 -0
- package/dist/utils.cjs +1 -0
- package/dist/utils.d.ts +90 -0
- package/dist/utils.js +58 -0
- package/dist/vite.svg +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @zlikemario/helper
|
|
2
|
+
|
|
3
|
+
A utility library with number operations and common helper functions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @zlikemario/helper
|
|
9
|
+
# or
|
|
10
|
+
yarn add @zlikemario/helper
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @zlikemario/helper
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Number Operations
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { BigNumber, isNumber, simplifyNumber } from '@zlikemario/helper/number'
|
|
21
|
+
|
|
22
|
+
// Check if a value is a number
|
|
23
|
+
console.log(isNumber('123')) // true
|
|
24
|
+
|
|
25
|
+
// Simplify large numbers
|
|
26
|
+
console.log(simplifyNumber(1234567)) // "1.2M"
|
|
27
|
+
|
|
28
|
+
// Use BigNumber for precise calculations
|
|
29
|
+
const result = new BigNumber('0.1').plus('0.2')
|
|
30
|
+
console.log(result.toString()) // "0.3"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Utility Functions
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { sleep, encrypt, isEmail } from '@zlikemario/helper/utils'
|
|
37
|
+
|
|
38
|
+
// Sleep function
|
|
39
|
+
await sleep(1000) // Wait for 1 second
|
|
40
|
+
|
|
41
|
+
// Encrypt sensitive data
|
|
42
|
+
console.log(encrypt('1234567890', 2, 2)) // "12****90"
|
|
43
|
+
|
|
44
|
+
// Validate email
|
|
45
|
+
console.log(isEmail('user@example.com')) // true
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API Reference
|
|
49
|
+
|
|
50
|
+
### Number Module (`@zlikemario/helper/number`)
|
|
51
|
+
|
|
52
|
+
- `BigNumber` - BigNumber.js instance for precise calculations
|
|
53
|
+
- `isNumber(num, isInt?)` - Check if value is a number
|
|
54
|
+
- `simplifyNumber(num, decimal?, rm?)` - Simplify large numbers (1.2K, 3.4M)
|
|
55
|
+
- `readabilityNumber(num)` - Add thousand separators
|
|
56
|
+
- `toPercentage(num, precision?, isHiddenUnit?)` - Convert to percentage
|
|
57
|
+
- `formatPrecision(num, precision?)` - Format with specific precision
|
|
58
|
+
- `readableNumber(num, decimals?)` - Advanced readable formatting
|
|
59
|
+
- `sum(data)` - Sum array of numbers
|
|
60
|
+
- `sumBy(data, key)` - Sum by object property or function
|
|
61
|
+
|
|
62
|
+
### Utils Module (`@zlikemario/helper/utils`)
|
|
63
|
+
|
|
64
|
+
- `sleep(interval?)` - Async sleep function
|
|
65
|
+
- `encrypt(text, prefix?, suffix?, placeholder?)` - Mask sensitive data
|
|
66
|
+
- `isUndefined(v)` - Check if value is undefined
|
|
67
|
+
- `isHasUndefined(...vs)` - Check if any value is undefined
|
|
68
|
+
- `isPromise(v)` - Check if value is a Promise
|
|
69
|
+
- `uint8ArrayToBase64(array)` - Convert Uint8Array to Base64
|
|
70
|
+
- `base64ToUint8Array(base64)` - Convert Base64 to Uint8Array
|
|
71
|
+
- `arrayBufferToBase64(buffer)` - Convert ArrayBuffer to Base64
|
|
72
|
+
- `isDomain(text)` - Validate domain name
|
|
73
|
+
- `isEmail(text)` - Validate email address
|
|
74
|
+
- `tryCatchAsync(p, catchFn?)` - Async try-catch wrapper
|
|
75
|
+
- `preventTimeout(callback, options?)` - Execute with timeout protection
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
package/dist/number.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("bignumber.js");i.config({EXPONENTIAL_AT:99});function s(e,t=!1){if(!["string","number","bigint"].includes(typeof e))return!1;try{e=i(e).toFixed()}catch{return!1}return t?/^-?\d+$/.test(e):/^-?\d+(\.\d+)?$/.test(e)}function l(e,t=3,n=i.ROUND_HALF_UP){if(!s(e))return String(e);const r=1e3;let o=i(e);if(o.abs().lt(r))return o.toFixed(t,n).replace(/\.0+$/,"");const u=["","K","M","B"];let a=0;for(;++a<u.length&&(o=o.div(r),!o.abs().lt(r)););return o.toFixed(1,n)+u[a]}function c(e){return s(e)?i(e).toFormat({decimalSeparator:".",groupSeparator:",",groupSize:3}):String(e)}function f(e,t=2,n=!1){if(!s(e))return String(e);const r=i(e).times(100).toFixed(t);return parseFloat(r)+(n?"":"%")}function g(e,t=4){return s(e)?i(e).dp(t).toString():String(e)}const d=(e,t=4)=>{if(!s(e))return String(e);const n=i(e).toFixed().match(/(-?)(\d+)\.(0+)(\d+)/);if(!n)return c(i(e).dp(t).toFixed());const[,r,o,u,a]=n;return u.length>3?`${r}${c(o)}.0{${u.length}}${a.slice(0,t-2).replace(/0+$/,"")}`:`${r}${c(o)}.${u}${a.slice(0,t-2).replace(/0+$/,"")}`},b=e=>e.reduce((t,n)=>t.plus(n),i(0)).toString();function p(e,t){const n=typeof t=="function"?r=>t(r):r=>r?.[t]??"0";return e.reduce((r,o)=>r.plus(n(o)),i(0)).toString()}exports.BigNumber=i;exports.default=i;exports.formatPrecision=g;exports.isNumber=s;exports.readabilityNumber=c;exports.readableNumber=d;exports.simplifyNumber=l;exports.sum=b;exports.sumBy=p;exports.toPercentage=f;
|
package/dist/number.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数字相关工具函数
|
|
3
|
+
*/
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
export { BigNumber };
|
|
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
|
+
/**
|
|
11
|
+
* 判断是否为有效数字
|
|
12
|
+
* @param num - 待判断的值
|
|
13
|
+
* @param isInt - 是否要求为整数
|
|
14
|
+
* @returns 是否为数字
|
|
15
|
+
*/
|
|
16
|
+
export declare function isNumber(num: any, isInt?: boolean): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 数字简化显示(如 1.2K, 3.4M)
|
|
19
|
+
* @param num - 数字
|
|
20
|
+
* @param decimal - 保留小数位
|
|
21
|
+
* @param rm - 舍入模式
|
|
22
|
+
* @returns 简化后的字符串
|
|
23
|
+
*/
|
|
24
|
+
export declare function simplifyNumber(num: Numberish, decimal?: number, rm?: BigNumber.RoundingMode): string;
|
|
25
|
+
/**
|
|
26
|
+
* 数字千分位分隔显示
|
|
27
|
+
* @param num - 数字
|
|
28
|
+
* @returns 格式化后的字符串
|
|
29
|
+
*/
|
|
30
|
+
export declare function readabilityNumber(num: Numberish): string;
|
|
31
|
+
/**
|
|
32
|
+
* 转为百分比字符串
|
|
33
|
+
* @param num - 数字
|
|
34
|
+
* @param precision - 保留小数位
|
|
35
|
+
* @param isHiddenUnit - 是否隐藏百分号
|
|
36
|
+
* @returns 百分比字符串
|
|
37
|
+
*/
|
|
38
|
+
export declare function toPercentage(num: Numberish, precision?: number, isHiddenUnit?: boolean): string;
|
|
39
|
+
/**
|
|
40
|
+
* 保留指定精度
|
|
41
|
+
* @param num - 数字
|
|
42
|
+
* @param precision - 保留小数位
|
|
43
|
+
* @returns 格式化后的字符串
|
|
44
|
+
*/
|
|
45
|
+
export declare function formatPrecision(num: Numberish, precision?: number): string;
|
|
46
|
+
/**
|
|
47
|
+
* 高级可读性数字格式化(如 1,234.0{4}1)
|
|
48
|
+
* @param number - 数字
|
|
49
|
+
* @param decimals - 保留小数位
|
|
50
|
+
* @returns 格式化后的字符串
|
|
51
|
+
*/
|
|
52
|
+
export declare const readableNumber: (number: Numberish, decimals?: number) => string;
|
|
53
|
+
/**
|
|
54
|
+
* 数组求和
|
|
55
|
+
* @param data - 数字数组
|
|
56
|
+
* @returns 求和结果字符串
|
|
57
|
+
*/
|
|
58
|
+
export declare const sum: (data: Array<Numberish>) => string;
|
|
59
|
+
/**
|
|
60
|
+
* 按 key 或函数求和
|
|
61
|
+
* @param data - 对象数组
|
|
62
|
+
* @param key - 属性名或函数
|
|
63
|
+
* @returns 求和结果字符串
|
|
64
|
+
*/
|
|
65
|
+
export declare function sumBy<T, K extends keyof T>(data: T[], key: T[K] extends MaybeUndefined<Numberish> ? K : never): NumberString;
|
|
66
|
+
export declare function sumBy<T>(data: T[], key: (item: T) => Numberish): NumberString;
|
package/dist/number.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import o from "bignumber.js";
|
|
2
|
+
import { default as N, default as x } from "bignumber.js";
|
|
3
|
+
o.config({ EXPONENTIAL_AT: 99 });
|
|
4
|
+
function a(t, e = !1) {
|
|
5
|
+
if (!["string", "number", "bigint"].includes(typeof t)) return !1;
|
|
6
|
+
try {
|
|
7
|
+
t = o(t).toFixed();
|
|
8
|
+
} catch {
|
|
9
|
+
return !1;
|
|
10
|
+
}
|
|
11
|
+
return e ? /^-?\d+$/.test(t) : /^-?\d+(\.\d+)?$/.test(t);
|
|
12
|
+
}
|
|
13
|
+
function l(t, e = 3, i = o.ROUND_HALF_UP) {
|
|
14
|
+
if (!a(t)) return String(t);
|
|
15
|
+
const r = 1e3;
|
|
16
|
+
let n = o(t);
|
|
17
|
+
if (n.abs().lt(r)) return n.toFixed(e, i).replace(/\.0+$/, "");
|
|
18
|
+
const s = ["", "K", "M", "B"];
|
|
19
|
+
let u = 0;
|
|
20
|
+
for (; ++u < s.length && (n = n.div(r), !n.abs().lt(r)); )
|
|
21
|
+
;
|
|
22
|
+
return n.toFixed(1, i) + s[u];
|
|
23
|
+
}
|
|
24
|
+
function c(t) {
|
|
25
|
+
return a(t) ? o(t).toFormat({
|
|
26
|
+
decimalSeparator: ".",
|
|
27
|
+
groupSeparator: ",",
|
|
28
|
+
groupSize: 3
|
|
29
|
+
}) : String(t);
|
|
30
|
+
}
|
|
31
|
+
function g(t, e = 2, i = !1) {
|
|
32
|
+
if (!a(t)) return String(t);
|
|
33
|
+
const r = o(t).times(100).toFixed(e);
|
|
34
|
+
return parseFloat(r) + (i ? "" : "%");
|
|
35
|
+
}
|
|
36
|
+
function d(t, e = 4) {
|
|
37
|
+
return a(t) ? o(t).dp(e).toString() : String(t);
|
|
38
|
+
}
|
|
39
|
+
const p = (t, e = 4) => {
|
|
40
|
+
if (!a(t)) return String(t);
|
|
41
|
+
const i = o(t).toFixed().match(/(-?)(\d+)\.(0+)(\d+)/);
|
|
42
|
+
if (!i)
|
|
43
|
+
return c(o(t).dp(e).toFixed());
|
|
44
|
+
const [, r, n, s, u] = i;
|
|
45
|
+
return s.length > 3 ? `${r}${c(n)}.0{${s.length}}${u.slice(0, e - 2).replace(/0+$/, "")}` : `${r}${c(n)}.${s}${u.slice(0, e - 2).replace(/0+$/, "")}`;
|
|
46
|
+
}, $ = (t) => t.reduce((e, i) => e.plus(i), o(0)).toString();
|
|
47
|
+
function b(t, e) {
|
|
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();
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
N as BigNumber,
|
|
56
|
+
x as default,
|
|
57
|
+
d as formatPrecision,
|
|
58
|
+
a as isNumber,
|
|
59
|
+
c as readabilityNumber,
|
|
60
|
+
p as readableNumber,
|
|
61
|
+
l as simplifyNumber,
|
|
62
|
+
$ as sum,
|
|
63
|
+
b as sumBy,
|
|
64
|
+
g as toPercentage
|
|
65
|
+
};
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +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;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for common operations.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Sleep for a specified interval (ms).
|
|
6
|
+
* @param interval - Time in milliseconds to sleep. Default: 1500ms.
|
|
7
|
+
*/
|
|
8
|
+
export declare const sleep: (interval?: number) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Encrypts a string by masking the middle part.
|
|
11
|
+
* @param text - The input string.
|
|
12
|
+
* @param prefix - Number of characters to keep at the start.
|
|
13
|
+
* @param suffix - Number of characters to keep at the end.
|
|
14
|
+
* @param placeholder - Masking string. Default: '...'.
|
|
15
|
+
* @returns Masked string.
|
|
16
|
+
*/
|
|
17
|
+
export declare function encrypt(text: string, prefix?: number, suffix?: number, placeholder?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a value is undefined.
|
|
20
|
+
* @param v - Value to check.
|
|
21
|
+
*/
|
|
22
|
+
export declare const isUndefined: (v: unknown) => v is undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if any of the provided values are undefined.
|
|
25
|
+
* @param vs - Values to check.
|
|
26
|
+
*/
|
|
27
|
+
export declare const isHasUndefined: (...vs: unknown[]) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a value is a Promise.
|
|
30
|
+
* @param v - Value to check.
|
|
31
|
+
*/
|
|
32
|
+
export declare const isPromise: <T = any>(v: unknown) => v is Promise<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a Uint8Array to a Base64 string.
|
|
35
|
+
* @param array - Uint8Array to convert.
|
|
36
|
+
*/
|
|
37
|
+
export declare function uint8ArrayToBase64(array: Uint8Array): string;
|
|
38
|
+
/**
|
|
39
|
+
* Converts a Base64 string to a Uint8Array.
|
|
40
|
+
* @param base64 - Base64 string to convert.
|
|
41
|
+
*/
|
|
42
|
+
export declare function base64ToUint8Array(base64: string): Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Converts an ArrayBuffer to a Base64 string.
|
|
45
|
+
* @param buffer - ArrayBuffer to convert.
|
|
46
|
+
*/
|
|
47
|
+
export declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
|
|
48
|
+
/**
|
|
49
|
+
* Validates a domain name.
|
|
50
|
+
* Rules:
|
|
51
|
+
* 1. Only numbers, letters, and hyphens allowed.
|
|
52
|
+
* 2. Composed of one or more parts separated by dots.
|
|
53
|
+
* 3. Last part must be at least two characters.
|
|
54
|
+
* 4. Cannot start or end with a hyphen.
|
|
55
|
+
* 5. No consecutive hyphens or hyphen-dot/dot-hyphen.
|
|
56
|
+
* @param text - Domain string to validate.
|
|
57
|
+
*/
|
|
58
|
+
export declare function isDomain(text: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Validates an email address.
|
|
61
|
+
* Rules:
|
|
62
|
+
* 1. Account part: letters, numbers, _, -, . allowed.
|
|
63
|
+
* 2. No leading/trailing dot.
|
|
64
|
+
* 3. No consecutive special characters.
|
|
65
|
+
* 4. Special character must be followed by at least one letter/number.
|
|
66
|
+
* 5. Domain part must be valid.
|
|
67
|
+
* @param text - Email string to validate.
|
|
68
|
+
*/
|
|
69
|
+
export declare function isEmail(text: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Async try-catch wrapper.
|
|
72
|
+
* @param p - Promise to execute.
|
|
73
|
+
* @param catchFn - Optional error handler.
|
|
74
|
+
*/
|
|
75
|
+
export declare const tryCatchAsync: <T, F extends ((error: unknown) => any) | undefined = undefined>(p: Promise<T>, catchFn?: F) => Promise<T | (F extends (...args: any) => any ? ReturnType<F> : undefined)>;
|
|
76
|
+
/**
|
|
77
|
+
* Executes a callback or promise and ensures it completes within a specified timeout duration.
|
|
78
|
+
* If the operation does not finish in time, the returned promise is rejected with a timeout error.
|
|
79
|
+
*
|
|
80
|
+
* @template R The type of the resolved value.
|
|
81
|
+
* @param callback - A function returning a promise or a promise to execute.
|
|
82
|
+
* @param options - Optional settings for timeout behavior.
|
|
83
|
+
* @param options.errorMessage - Custom error message for timeout rejection. Defaults to "Timeout".
|
|
84
|
+
* @param options.duration - Timeout duration in milliseconds. Defaults to 15000 ms.
|
|
85
|
+
* @returns A promise that resolves with the result of the callback or rejects if the timeout is reached.
|
|
86
|
+
*/
|
|
87
|
+
export declare function preventTimeout<R>(callback: (() => Promise<R>) | Promise<R>, options?: {
|
|
88
|
+
errorMessage?: string;
|
|
89
|
+
duration?: number;
|
|
90
|
+
}): Promise<R>;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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) : "");
|
|
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);
|
|
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);
|
|
16
|
+
return r;
|
|
17
|
+
}
|
|
18
|
+
function g(n) {
|
|
19
|
+
return u(new Uint8Array(n));
|
|
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("-"))
|
|
23
|
+
return !1;
|
|
24
|
+
const e = n.split(".");
|
|
25
|
+
return !(e.length < 2 || e.some((r) => !r.length) || e[e.length - 1].length < 2);
|
|
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;
|
|
30
|
+
for (const t of r)
|
|
31
|
+
if (!f(t)) return !1;
|
|
32
|
+
return !0;
|
|
33
|
+
}
|
|
34
|
+
const w = async (n, e) => {
|
|
35
|
+
try {
|
|
36
|
+
return await n;
|
|
37
|
+
} catch (r) {
|
|
38
|
+
return e?.(r);
|
|
39
|
+
}
|
|
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]);
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
g as arrayBufferToBase64,
|
|
47
|
+
d as base64ToUint8Array,
|
|
48
|
+
m as encrypt,
|
|
49
|
+
f as isDomain,
|
|
50
|
+
p as isEmail,
|
|
51
|
+
h as isHasUndefined,
|
|
52
|
+
y as isPromise,
|
|
53
|
+
a as isUndefined,
|
|
54
|
+
T as preventTimeout,
|
|
55
|
+
l as sleep,
|
|
56
|
+
w as tryCatchAsync,
|
|
57
|
+
u as uint8ArrayToBase64
|
|
58
|
+
};
|
package/dist/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
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>
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zlikemario/helper",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A utility library with number operations and common helper functions",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"utility",
|
|
7
|
+
"number",
|
|
8
|
+
"helper",
|
|
9
|
+
"typescript"
|
|
10
|
+
],
|
|
11
|
+
"author": "zlikemario",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/zlikemario/helper.git"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/zlikemario/helper#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/zlikemario/helper/issues"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "vite build && tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
29
|
+
"preview": "vite preview",
|
|
30
|
+
"test": "vitest",
|
|
31
|
+
"prepublishOnly": "yarn build",
|
|
32
|
+
"publish": "npm publish --access public"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^24",
|
|
36
|
+
"bignumber.js": "^9.3.1",
|
|
37
|
+
"dayjs": "^1.11.18",
|
|
38
|
+
"node": "^24.8.0",
|
|
39
|
+
"typescript": "~5.8.3",
|
|
40
|
+
"vite": "^7.1.2",
|
|
41
|
+
"vite-plugin-dts": "^4.5.4",
|
|
42
|
+
"vitest": "^3.2.4"
|
|
43
|
+
},
|
|
44
|
+
"exports": {
|
|
45
|
+
"./number": {
|
|
46
|
+
"types": "./dist/number.d.ts",
|
|
47
|
+
"import": "./dist/number.js",
|
|
48
|
+
"require": "./dist/number.cjs"
|
|
49
|
+
},
|
|
50
|
+
"./utils": {
|
|
51
|
+
"types": "./dist/utils.d.ts",
|
|
52
|
+
"import": "./dist/utils.js",
|
|
53
|
+
"require": "./dist/utils.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "yarn@4.9.4+sha512.7b1cb0b62abba6a537b3a2ce00811a843bea02bcf53138581a6ae5b1bf563f734872bd47de49ce32a9ca9dcaff995aa789577ffb16811da7c603dcf69e73750b",
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"bignumber.js": "*",
|
|
59
|
+
"dayjs": "*"
|
|
60
|
+
}
|
|
61
|
+
}
|