@secret-momo/utils 1.0.3 → 1.0.4
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/lib/date-time.d.ts +0 -1
- package/lib/date-time.js +1 -16
- package/lib/download/extension.d.ts +21 -0
- package/lib/download/extension.js +1 -0
- package/lib/download/index.d.ts +9 -0
- package/lib/download/index.js +1 -0
- package/lib/env.d.ts +0 -1
- package/lib/env.js +1 -44
- package/lib/fetch.d.ts +1 -1
- package/lib/fetch.js +1 -118
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -9
- package/lib/log.d.ts +0 -1
- package/lib/log.js +1 -20
- package/lib/num.d.ts +0 -1
- package/lib/num.js +1 -12
- package/lib/sleep.d.ts +0 -1
- package/lib/sleep.js +1 -8
- package/lib/url.d.ts +0 -1
- package/lib/url.js +1 -18
- package/lib/uuid.d.ts +0 -1
- package/lib/uuid.js +1 -14
- package/package.json +5 -5
- package/lib/date-time.d.ts.map +0 -1
- package/lib/env.d.ts.map +0 -1
- package/lib/fetch.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/log.d.ts.map +0 -1
- package/lib/num.d.ts.map +0 -1
- package/lib/sleep.d.ts.map +0 -1
- package/lib/url.d.ts.map +0 -1
- package/lib/uuid.d.ts.map +0 -1
package/lib/date-time.d.ts
CHANGED
package/lib/date-time.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function dateTimeToNow(fmt = "YYYY-MM-DD HH:mm:ss") {
|
|
4
|
-
return dayjs().format(fmt);
|
|
5
|
-
}
|
|
6
|
-
function dateToNow(fmt = "YYYY-MM-DD") {
|
|
7
|
-
return dayjs().format(fmt);
|
|
8
|
-
}
|
|
9
|
-
function yesterdayDate(fmt = "YYYY-MM-DD") {
|
|
10
|
-
return dayjs().subtract(1, "day").format(fmt);
|
|
11
|
-
}
|
|
12
|
-
function timestampToDate(timestamp, fmt = "YYYY-MM-DD") {
|
|
13
|
-
return dayjs(timestamp).format(fmt);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { dateTimeToNow, dateToNow, timestampToDate, yesterdayDate };
|
|
1
|
+
import r from"dayjs";function Y(t="YYYY-MM-DD HH:mm:ss"){return r().format(t)}function e(t="YYYY-MM-DD"){return r().format(t)}function a(t="YYYY-MM-DD"){return r().subtract(1,"day").format(t)}function n(t,o="YYYY-MM-DD"){return r(t).format(o)}export{Y as dateTimeToNow,e as dateToNow,n as timestampToDate,a as yesterdayDate};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 推断视频文件的扩展名,按以下优先级:
|
|
3
|
+
* 1. URL 路径中的视频扩展名
|
|
4
|
+
* 2. `Content-Type` 映射
|
|
5
|
+
* 3. 兜底 `'mp4'`
|
|
6
|
+
* @param url 资源 URL
|
|
7
|
+
* @param contentType `Content-Type` 响应头,可为 `null`
|
|
8
|
+
* @returns 视频扩展名(不含点号)
|
|
9
|
+
*/
|
|
10
|
+
export declare function pickVideoExtension(url: string, contentType: string | null): string;
|
|
11
|
+
/**
|
|
12
|
+
* 推断图片文件的扩展名,按以下优先级:
|
|
13
|
+
* 1. URL 路径中的图片扩展名(`jpeg` 统一为 `jpg`)
|
|
14
|
+
* 2. `Content-Type` 映射
|
|
15
|
+
* 3. 兜底 `'jpg'`
|
|
16
|
+
*
|
|
17
|
+
* @param url 资源 URL
|
|
18
|
+
* @param contentType `Content-Type` 响应头,可为 `null`
|
|
19
|
+
* @returns 图片扩展名(不含点号)
|
|
20
|
+
*/
|
|
21
|
+
export declare function pickImageExtension(url: string, contentType: string | null): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a=new Set(["mp4","webm","mov","m4v","mkv","avi","ogv"]),v=new Set(["jpg","jpeg","png","gif","webp","svg","bmp","avif","ico"]),r={"video/mp4":"mp4","video/webm":"webm","video/quicktime":"mov","video/x-m4v":"m4v","video/x-matroska":"mkv","video/x-msvideo":"avi","video/ogg":"ogv"},c={"image/jpeg":"jpg","image/jpg":"jpg","image/png":"png","image/gif":"gif","image/webp":"webp","image/svg+xml":"svg","image/bmp":"bmp","image/x-ms-bmp":"bmp","image/avif":"avif","image/x-icon":"ico"};function g(e,i){try{const{pathname:m}=new URL(e),n=m.split("/").pop()??"",o=/\.([a-zA-Z0-9]+)$/.exec(n);if(!o?.[1])return null;const t=o[1].toLowerCase();return i.has(t)?t:null}catch{return null}}function p(e,i){if(!e)return null;const m=e.split(";")[0]?.trim().toLowerCase()??"";return i[m]??null}function s(e,i){return g(e,a)??p(i,r)??"mp4"}function u(e,i){const m=g(e,v);if(m==="jpeg")return"jpg";const n=p(i,c);return m??n??"jpg"}export{u as pickImageExtension,s as pickVideoExtension};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface DownloadOptions {
|
|
2
|
+
/** 资源 URL */
|
|
3
|
+
url: string;
|
|
4
|
+
/** 资源保存目录 */
|
|
5
|
+
dir: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function downloadVideo({ url, dir }: DownloadOptions): Promise<string | null>;
|
|
8
|
+
export declare function downloadImage({ url, dir }: DownloadOptions): Promise<string | null>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mkdirSync as i,createWriteStream as a}from"node:fs";import{join as m}from"node:path";import{Readable as c}from"node:stream";import{pipeline as s}from"node:stream/promises";import d from"consola";import{dateTimeToNow as p}from"../date-time.js";import{pickImageExtension as f,pickVideoExtension as y}from"./extension.js";async function u({url:r,dir:e}){try{i(e,{recursive:!0});const o=await fetch(r);if(!o.body)throw new Error("Response has no body");const n=y(r,o.headers.get("content-type")),t=m(e,`${p("YYYYMMDD_HHmmss")}.${n}`);return await s(c.fromWeb(o.body),a(t)),t}catch(o){return d.error(o),null}}async function w({url:r,dir:e}){try{i(e,{recursive:!0});const o=await fetch(r);if(!o.body)throw new Error("Response has no body");const n=f(r,o.headers.get("content-type")),t=m(e,`${p("YYYYMMDD_HHmmss")}.${n}`);return await s(c.fromWeb(o.body),a(t)),t}catch(o){return d.error(o),null}}export{w as downloadImage,u as downloadVideo};
|
package/lib/env.d.ts
CHANGED
package/lib/env.js
CHANGED
|
@@ -1,44 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { info } from './log.js';
|
|
3
|
-
|
|
4
|
-
let macHardwareInfo = null;
|
|
5
|
-
function getMacHardwareInfo() {
|
|
6
|
-
if (macHardwareInfo) {
|
|
7
|
-
return macHardwareInfo;
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
const output = execSync("system_profiler SPHardwareDataType", {
|
|
11
|
-
encoding: "utf-8",
|
|
12
|
-
stdio: ["pipe", "pipe", "ignore"]
|
|
13
|
-
});
|
|
14
|
-
const getValue = (key) => {
|
|
15
|
-
const regex = new RegExp(`${key}:\\s+(.+)`);
|
|
16
|
-
const match = output.match(regex);
|
|
17
|
-
return match?.[1]?.trim() ?? null;
|
|
18
|
-
};
|
|
19
|
-
macHardwareInfo = {
|
|
20
|
-
modelName: getValue("Model Name"),
|
|
21
|
-
modelIdentifier: getValue("Model Identifier"),
|
|
22
|
-
chip: getValue("Chip") || getValue("Processor Name"),
|
|
23
|
-
// 兼容 Intel
|
|
24
|
-
raw: output
|
|
25
|
-
};
|
|
26
|
-
return macHardwareInfo;
|
|
27
|
-
} catch (_e) {
|
|
28
|
-
return {
|
|
29
|
-
modelName: null,
|
|
30
|
-
modelIdentifier: null,
|
|
31
|
-
chip: null,
|
|
32
|
-
raw: ""
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function getNodeName() {
|
|
37
|
-
const { modelName, chip } = getMacHardwareInfo();
|
|
38
|
-
return `${modelName}(${chip})`;
|
|
39
|
-
}
|
|
40
|
-
if (import.meta.main) {
|
|
41
|
-
info(`getNodeName: ${getNodeName()}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { getNodeName };
|
|
1
|
+
import{execSync as m}from"child_process";import{info as l}from"./log.js";let t=null;function a(){if(t)return t;try{const r=m("system_profiler SPHardwareDataType",{encoding:"utf-8",stdio:["pipe","pipe","ignore"]}),e=o=>{const i=new RegExp(`${o}:\\s+(.+)`);return r.match(i)?.[1]?.trim()??null};return t={modelName:e("Model Name"),modelIdentifier:e("Model Identifier"),chip:e("Chip")||e("Processor Name"),raw:r},t}catch{return{modelName:null,modelIdentifier:null,chip:null,raw:""}}}function n(){const{modelName:r,chip:e}=a();return`${r}(${e})`}import.meta.main&&l(`getNodeName: ${n()}`);export{n as getNodeName};
|
package/lib/fetch.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
2
|
+
export declare const mobileUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1";
|
|
2
3
|
/**
|
|
3
4
|
* 对 `globalThis.fetch` 的轻量封装:
|
|
4
5
|
* - 最多重试 `MAX_RETRIES` 次(默认 5 次),总尝试次数为 `MAX_RETRIES + 1`。
|
|
@@ -10,4 +11,3 @@ export declare function fetch(input: string | URL | Request, init?: RequestInit)
|
|
|
10
11
|
export declare function fetchText(input: string | URL | Request, init?: RequestInit): Promise<string>;
|
|
11
12
|
export declare function fetchHtml(input: string | URL | Request, init?: RequestInit): Promise<string>;
|
|
12
13
|
export declare function fetchJson(input: string | URL | Request, init?: RequestInit): Promise<unknown>;
|
|
13
|
-
//# sourceMappingURL=fetch.d.ts.map
|
package/lib/fetch.js
CHANGED
|
@@ -1,118 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { sleep } from './sleep.js';
|
|
3
|
-
|
|
4
|
-
const MAX_RETRIES = 5;
|
|
5
|
-
const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
|
|
6
|
-
function originFromUrl(url) {
|
|
7
|
-
try {
|
|
8
|
-
const parsed = new URL(url);
|
|
9
|
-
return parsed.origin;
|
|
10
|
-
} catch {
|
|
11
|
-
return url;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function refererFromUrl(url) {
|
|
15
|
-
return originFromUrl(url) + "/";
|
|
16
|
-
}
|
|
17
|
-
function formatErrorSummary(error) {
|
|
18
|
-
const err = error;
|
|
19
|
-
const name = err?.name ?? "Error";
|
|
20
|
-
const message = err?.message ?? String(error);
|
|
21
|
-
const code = err?.cause?.code ? ` [code=${String(err.cause.code)}]` : "";
|
|
22
|
-
return `${name}: ${message}${code}`;
|
|
23
|
-
}
|
|
24
|
-
function isRetryableError(error, signal) {
|
|
25
|
-
if (signal?.aborted) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
const err = error;
|
|
29
|
-
const message = (err?.message ?? String(error)).toLowerCase();
|
|
30
|
-
const code = String(err?.cause?.code ?? "").toLowerCase();
|
|
31
|
-
const isNetworkLikeMessage = [
|
|
32
|
-
"network",
|
|
33
|
-
"socket",
|
|
34
|
-
"econnreset",
|
|
35
|
-
"econnrefused",
|
|
36
|
-
"etimedout",
|
|
37
|
-
"timeout",
|
|
38
|
-
"failed to fetch",
|
|
39
|
-
"unable to connect",
|
|
40
|
-
// TLS/证书错误(常见于本地代理 Clash / 系统证书轮换后 session ticket 失效)
|
|
41
|
-
"certificate",
|
|
42
|
-
"unknown cert",
|
|
43
|
-
"ssl",
|
|
44
|
-
"tls"
|
|
45
|
-
].some((m) => message.includes(m));
|
|
46
|
-
const isNetworkLikeCode = ["econnreset", "econnrefused", "etimedout"].some((m) => code === m);
|
|
47
|
-
return err?.name === "TimeoutError" || err?.name === "AbortError" || isNetworkLikeMessage || isNetworkLikeCode;
|
|
48
|
-
}
|
|
49
|
-
async function fetch(input, init) {
|
|
50
|
-
const originalSignal = init?.signal ?? void 0;
|
|
51
|
-
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
52
|
-
try {
|
|
53
|
-
init = {
|
|
54
|
-
...init,
|
|
55
|
-
headers: {
|
|
56
|
-
...init?.headers,
|
|
57
|
-
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
|
58
|
-
Referer: refererFromUrl(input.toString()),
|
|
59
|
-
"User-Agent": userAgent
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
return await globalThis.fetch(input, init);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
const shouldRetry = attempt < MAX_RETRIES && isRetryableError(error, originalSignal);
|
|
65
|
-
if (!shouldRetry) {
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
const totalAttempts = MAX_RETRIES + 1;
|
|
69
|
-
const currentAttempt = attempt + 1;
|
|
70
|
-
const seconds = Math.pow(2, attempt);
|
|
71
|
-
const remainingRetries = MAX_RETRIES - attempt - 1;
|
|
72
|
-
warn(
|
|
73
|
-
`\u8BF7\u6C42\u5931\u8D25\uFF0C\u7B2C ${currentAttempt}/${totalAttempts} \u6B21\u5C1D\u8BD5\uFF0C${seconds}s \u540E\u91CD\u8BD5\uFF08\u5269\u4F59 ${remainingRetries} \u6B21\uFF09\uFF1A${input}\uFF1B\u9519\u8BEF\uFF1A${formatErrorSummary(error)}`
|
|
74
|
-
);
|
|
75
|
-
await sleep(1e3 * seconds);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
throw new Error("Unexpected fetch retry failure");
|
|
79
|
-
}
|
|
80
|
-
async function fetchText(input, init) {
|
|
81
|
-
return (await fetch(input, init)).text();
|
|
82
|
-
}
|
|
83
|
-
async function fetchHtml(input, init) {
|
|
84
|
-
init = {
|
|
85
|
-
...init,
|
|
86
|
-
headers: {
|
|
87
|
-
...init?.headers,
|
|
88
|
-
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
|
89
|
-
"Cache-Control": "no-cache",
|
|
90
|
-
"Content-Type": "text/html",
|
|
91
|
-
Pragma: "no-cache",
|
|
92
|
-
"Upgrade-Insecure-Requests": "1",
|
|
93
|
-
"Sec-Fetch-Site": "none",
|
|
94
|
-
"Sec-Fetch-Mode": "navigate",
|
|
95
|
-
"Sec-Fetch-User": "?1",
|
|
96
|
-
"Sec-Fetch-Dest": "document"
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
return await fetchText(input, init);
|
|
100
|
-
}
|
|
101
|
-
async function fetchJson(input, init) {
|
|
102
|
-
init = {
|
|
103
|
-
...init,
|
|
104
|
-
headers: {
|
|
105
|
-
...init?.headers,
|
|
106
|
-
Accept: "application/json, text/plain, */*",
|
|
107
|
-
Connection: "keep-alive",
|
|
108
|
-
"Content-Type": "application/json",
|
|
109
|
-
Origin: originFromUrl(input.toString()),
|
|
110
|
-
"Sec-Fetch-Site": "same-site",
|
|
111
|
-
"Sec-Fetch-Mode": "cors",
|
|
112
|
-
"Sec-Fetch-Dest": "empty"
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
return (await fetch(input, init)).json();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export { fetch, fetchHtml, fetchJson, fetchText, userAgent };
|
|
1
|
+
import{warn as p}from"./log.js";import{sleep as d}from"./sleep.js";const a=5,h="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",F="Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1";function l(t){try{return new URL(t).origin}catch{return t}}function g(t){return l(t)+"/"}function S(t){const e=t,o=e?.name??"Error",n=e?.message??String(t),r=e?.cause?.code?` [code=${String(e.cause.code)}]`:"";return`${o}: ${n}${r}`}function w(t,e){if(e?.aborted)return!1;const o=t,n=(o?.message??String(t)).toLowerCase(),r=String(o?.cause?.code??"").toLowerCase(),i=["network","socket","econnreset","econnrefused","etimedout","timeout","failed to fetch","unable to connect","certificate","unknown cert","ssl","tls"].some(c=>n.includes(c)),s=["econnreset","econnrefused","etimedout"].some(c=>r===c);return o?.name==="TimeoutError"||o?.name==="AbortError"||i||s}async function u(t,e){const o=e?.signal??void 0;for(let n=0;n<=a;n++)try{return e={...e,headers:{"Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8",Referer:g(t.toString()),"User-Agent":h,...e?.headers}},await globalThis.fetch(t,e)}catch(r){if(!(n<a&&w(r,o)))throw r;const i=a+1,s=n+1,c=Math.pow(2,n),m=a-n-1;p(`\u8BF7\u6C42\u5931\u8D25\uFF0C\u7B2C ${s}/${i} \u6B21\u5C1D\u8BD5\uFF0C${c}s \u540E\u91CD\u8BD5\uFF08\u5269\u4F59 ${m} \u6B21\uFF09\uFF1A${t}\uFF1B\u9519\u8BEF\uFF1A${S(r)}`),await d(1e3*c)}throw new Error("Unexpected fetch retry failure")}async function f(t,e){return(await u(t,e)).text()}async function C(t,e){return e={...e,headers:{Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","Cache-Control":"no-cache","Content-Type":"text/html",Pragma:"no-cache","Upgrade-Insecure-Requests":"1","Sec-Fetch-Site":"none","Sec-Fetch-Mode":"navigate","Sec-Fetch-User":"?1","Sec-Fetch-Dest":"document",...e?.headers}},await f(t,e)}async function x(t,e){return e={...e,headers:{Accept:"application/json, text/plain, */*",Connection:"keep-alive","Content-Type":"application/json",Origin:l(t.toString()),"Sec-Fetch-Site":"same-site","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",...e?.headers}},(await u(t,e)).json()}export{u as fetch,C as fetchHtml,x as fetchJson,f as fetchText,F as mobileUserAgent,h as userAgent};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { getNodeName } from './env.js';
|
|
3
|
-
export { fetch, fetchHtml, fetchJson, fetchText, userAgent } from './fetch.js';
|
|
4
|
-
export { error, info, log, success, warn } from './log.js';
|
|
5
|
-
export { fixed2, fixed4, toPercentage } from './num.js';
|
|
6
|
-
export { sleep, sleep_random } from './sleep.js';
|
|
7
|
-
export { genId, uuidv4 } from './uuid.js';
|
|
8
|
-
export { getRedirectUrl, removeQueryParams } from './url.js';
|
|
9
|
-
export { default as consola } from 'consola';
|
|
1
|
+
import{downloadImage as r,downloadVideo as t}from"./download/index.js";import{dateTimeToNow as a,dateToNow as f,timestampToDate as d,yesterdayDate as p}from"./date-time.js";import{getNodeName as x}from"./env.js";import{fetch as l,fetchHtml as c,fetchJson as i,fetchText as g,mobileUserAgent as u,userAgent as w}from"./fetch.js";import{error as h,info as N,log as y,success as v,warn as A}from"./log.js";import{fixed2 as I,fixed4 as P,toPercentage as U}from"./num.js";import{sleep as H,sleep_random as J}from"./sleep.js";import{genId as R,uuidv4 as V}from"./uuid.js";import{getRedirectUrl as j,removeQueryParams as k}from"./url.js";import{default as z}from"consola";export{z as consola,a as dateTimeToNow,f as dateToNow,r as downloadImage,t as downloadVideo,h as error,l as fetch,c as fetchHtml,i as fetchJson,g as fetchText,I as fixed2,P as fixed4,R as genId,x as getNodeName,j as getRedirectUrl,N as info,y as log,u as mobileUserAgent,k as removeQueryParams,H as sleep,J as sleep_random,v as success,d as timestampToDate,U as toPercentage,w as userAgent,V as uuidv4,A as warn,p as yesterdayDate};
|
package/lib/log.d.ts
CHANGED
package/lib/log.js
CHANGED
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import consola from
|
|
2
|
-
export { default as consola } from 'consola';
|
|
3
|
-
|
|
4
|
-
function log(message) {
|
|
5
|
-
consola.log(message);
|
|
6
|
-
}
|
|
7
|
-
function warn(message) {
|
|
8
|
-
consola.warn(message);
|
|
9
|
-
}
|
|
10
|
-
function error(e) {
|
|
11
|
-
consola.error(e);
|
|
12
|
-
}
|
|
13
|
-
function success(message) {
|
|
14
|
-
consola.success(message);
|
|
15
|
-
}
|
|
16
|
-
function info(message) {
|
|
17
|
-
consola.info(message);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { error, info, log, success, warn };
|
|
1
|
+
import n from"consola";import{default as a}from"consola";function r(o){n.log(o)}function c(o){n.warn(o)}function f(o){n.error(o)}function t(o){n.success(o)}function i(o){n.info(o)}export{a as consola,f as error,i as info,r as log,t as success,c as warn};
|
package/lib/num.d.ts
CHANGED
package/lib/num.js
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
return Number(n.toFixed(2));
|
|
3
|
-
}
|
|
4
|
-
function fixed4(n) {
|
|
5
|
-
return Number(n.toFixed(4));
|
|
6
|
-
}
|
|
7
|
-
function toPercentage(n) {
|
|
8
|
-
if (n === void 0) return "-";
|
|
9
|
-
return `${fixed2(n * 100)}%`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { fixed2, fixed4, toPercentage };
|
|
1
|
+
function t(e){return Number(e.toFixed(2))}function n(e){return Number(e.toFixed(4))}function r(e){return e===void 0?"-":`${t(e*100)}%`}export{t as fixed2,n as fixed4,r as toPercentage};
|
package/lib/sleep.d.ts
CHANGED
package/lib/sleep.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
|
-
}
|
|
4
|
-
function sleep_random() {
|
|
5
|
-
return sleep(Math.floor(Math.random() * 500) + 750);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { sleep, sleep_random };
|
|
1
|
+
function e(n){return new Promise(o=>setTimeout(o,n))}function r(){return e(Math.floor(Math.random()*500)+750)}export{e as sleep,r as sleep_random};
|
package/lib/url.d.ts
CHANGED
package/lib/url.js
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function removeQueryParams(url) {
|
|
4
|
-
return url.split("?")[0] ?? url;
|
|
5
|
-
}
|
|
6
|
-
async function getRedirectUrl(url) {
|
|
7
|
-
const res = await fetch(url, {
|
|
8
|
-
method: "GET",
|
|
9
|
-
redirect: "manual",
|
|
10
|
-
headers: { "User-Agent": userAgent }
|
|
11
|
-
});
|
|
12
|
-
if (res.status >= 300 && res.status < 400) {
|
|
13
|
-
return res.headers.get("location") || url;
|
|
14
|
-
}
|
|
15
|
-
return url;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { getRedirectUrl, removeQueryParams };
|
|
1
|
+
import{fetch as r,userAgent as a}from"./fetch.js";function n(e){return e.split("?")[0]??e}async function s(e){const t=await r(e,{method:"GET",redirect:"manual",headers:{"User-Agent":a}});return t.status>=300&&t.status<400&&t.headers.get("location")||e}export{s as getRedirectUrl,n as removeQueryParams};
|
package/lib/uuid.d.ts
CHANGED
package/lib/uuid.js
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
function
|
|
2
|
-
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
3
|
-
let result = "";
|
|
4
|
-
const bytes = crypto.getRandomValues(new Uint8Array(len));
|
|
5
|
-
for (let i = 0; i < len; i++) {
|
|
6
|
-
result += chars[bytes[i] % chars.length];
|
|
7
|
-
}
|
|
8
|
-
return result;
|
|
9
|
-
}
|
|
10
|
-
function uuidv4() {
|
|
11
|
-
return crypto.randomUUID();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { genId, uuidv4 };
|
|
1
|
+
function u(t=10){const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";let o="";const r=crypto.getRandomValues(new Uint8Array(t));for(let n=0;n<t;n++)o+=e[r[n]%e.length];return o}function c(){return crypto.randomUUID()}export{u as genId,c as uuidv4};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secret-momo/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"module": "src/index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@eslint/config-helpers": "0.6.0",
|
|
36
36
|
"@eslint/js": "10.0.1",
|
|
37
37
|
"@types/bun": "1.3.14",
|
|
38
|
-
"eslint": "10.
|
|
38
|
+
"eslint": "10.5.0",
|
|
39
39
|
"eslint-plugin-import-x": "4.16.2",
|
|
40
40
|
"eslint-plugin-react": "7.37.5",
|
|
41
41
|
"eslint-plugin-react-hooks": "7.1.1",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"husky": "9.1.7",
|
|
44
44
|
"jiti": "2.7.0",
|
|
45
45
|
"lint-staged": "17.0.7",
|
|
46
|
-
"prettier": "3.8.
|
|
47
|
-
"rollup": "4.
|
|
46
|
+
"prettier": "3.8.4",
|
|
47
|
+
"rollup": "4.62.0",
|
|
48
48
|
"rollup-plugin-esbuild": "6.2.1",
|
|
49
49
|
"typescript": "6.0.3",
|
|
50
|
-
"typescript-eslint": "8.
|
|
50
|
+
"typescript-eslint": "8.61.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"consola": "3.4.2",
|
package/lib/date-time.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"date-time.d.ts","sourceRoot":"","sources":["../src/date-time.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,GAAG,SAAwB,GAAG,MAAM,CAEjE;AAED,wBAAgB,SAAS,CAAC,GAAG,SAAe,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,SAAe,GAAG,MAAM,CAExD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,SAAe,GAAG,MAAM,CAE7E"}
|
package/lib/env.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAmDA,wBAAgB,WAAW,IAAI,MAAM,CAIpC"}
|
package/lib/fetch.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,oHAC6F,CAAC;AAqEpH;;;;;;GAMG;AACH,wBAAsB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkChG;AAED,wBAAsB,SAAS,CAC7B,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAC7B,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,wBAAsB,SAAS,CAC7B,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAC7B,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAED,wBAAsB,SAAS,CAC7B,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAC7B,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,OAAO,CAAC,CAgBlB"}
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC"}
|
package/lib/log.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,QAElC;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,QAEnC;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,QAE/B;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,QAEtC;AAED,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,QAEnC"}
|
package/lib/num.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../src/num.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAExC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI/C"}
|
package/lib/sleep.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../src/sleep.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAE/B;AAED,wBAAgB,YAAY,qBAE3B"}
|
package/lib/url.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAajE"}
|
package/lib/uuid.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../src/uuid.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,GAAG,SAAK,UAW7B;AAED,wBAAgB,MAAM,wDAErB"}
|