@secret-momo/utils 1.0.6 → 1.1.0

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.
@@ -1 +1 @@
1
- import{mkdirSync as i,createWriteStream as m}from"node:fs";import{join as a}from"node:path";import{Readable as s}from"node:stream";import{pipeline as c}from"node:stream/promises";import d from"consola";import{fetch as p}from"../fetch.js";import{dateTimeToNow as f}from"../date-time.js";import{pickImageExtension as y,pickVideoExtension as u}from"./extension.js";async function w({url:r,dir:e}){try{i(e,{recursive:!0});const o=await p(r);if(!o.body)throw new Error("Response has no body");const n=u(r,o.headers.get("content-type")),t=a(e,`${f("YYYYMMDD_HHmmss")}.${n}`);return await c(s.fromWeb(o.body),m(t)),t}catch(o){return d.error(o),null}}async function l({url:r,dir:e}){try{i(e,{recursive:!0});const o=await p(r);if(!o.body)throw new Error("Response has no body");const n=y(r,o.headers.get("content-type")),t=a(e,`${f("YYYYMMDD_HHmmss")}.${n}`);return await c(s.fromWeb(o.body),m(t)),t}catch(o){return d.error(o),null}}export{l as downloadImage,w as downloadVideo};
1
+ import{mkdirSync as i,createWriteStream as a}from"node:fs";import{join as m}from"node:path";import{Readable as d}from"node:stream";import{pipeline as c}from"node:stream/promises";import{fetch as s}from"../fetch.js";import{dateTimeToNow as p}from"../date-time.js";import{pickImageExtension as l,pickVideoExtension as w}from"./extension.js";import{logger as f}from"../pino.js";async function y({url:r,dir:e}){try{i(e,{recursive:!0});const o=await s(r);if(!o.body)throw new Error("Response has no body");const n=w(r,o.headers.get("content-type")),t=m(e,`${p("YYYYMMDD_HHmmss")}.${n}`);return await c(d.fromWeb(o.body),a(t)),t}catch(o){return f.child({name:"downloadVideo"}).error(o),null}}async function u({url:r,dir:e}){try{i(e,{recursive:!0});const o=await s(r);if(!o.body)throw new Error("Response has no body");const n=l(r,o.headers.get("content-type")),t=m(e,`${p("YYYYMMDD_HHmmss")}.${n}`);return await c(d.fromWeb(o.body),a(t)),t}catch(o){return f.child({name:"downloadImage"}).error(o),null}}export{u as downloadImage,y as downloadVideo};
package/lib/env.js CHANGED
@@ -1 +1 @@
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};
1
+ import{execSync as o}from"child_process";let n=null;function l(){if(n)return n;try{const r=o("system_profiler SPHardwareDataType",{encoding:"utf-8",stdio:["pipe","pipe","ignore"]}),e=t=>{const i=new RegExp(`${t}:\\s+(.+)`);return r.match(i)?.[1]?.trim()??null};return n={modelName:e("Model Name"),modelIdentifier:e("Model Identifier"),chip:e("Chip")||e("Processor Name"),raw:r},n}catch{return{modelName:null,modelIdentifier:null,chip:null,raw:""}}}function m(){const{modelName:r,chip:e}=l();return`${r}(${e})`}export{m as getNodeName};
package/lib/fetch.js CHANGED
@@ -1 +1 @@
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};
1
+ import{logger as p}from"./pino.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",g="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 F(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:F(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.warn(`\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,g as mobileUserAgent,h as userAgent};
package/lib/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export * from './download';
2
2
  export * from './date-time';
3
3
  export * from './env';
4
4
  export * from './fetch';
5
- export * from './log';
6
5
  export * from './num';
7
6
  export * from './pino';
8
7
  export * from './sleep';
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import{downloadImage as r,downloadVideo as t}from"./download/index.js";import{dateTimeToNow as f,dateToNow as a,timestampToDate as d,yesterdayDate as p}from"./date-time.js";import{getNodeName as s}from"./env.js";import{fetch as n,fetchHtml as g,fetchJson as i,fetchText as c,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{logger as H}from"./pino.js";import{sleep as Q,sleep_random as R}from"./sleep.js";import{genId as _,uuidv4 as j}from"./uuid.js";import{getRedirectUrl as q,removeQueryParams as z}from"./url.js";import{default as C}from"consola";import{default as F}from"pino";export{C as consola,f as dateTimeToNow,a as dateToNow,r as downloadImage,t as downloadVideo,h as error,n as fetch,g as fetchHtml,i as fetchJson,c as fetchText,I as fixed2,P as fixed4,_ as genId,s as getNodeName,q as getRedirectUrl,N as info,y as log,H as logger,u as mobileUserAgent,F as pino,z as removeQueryParams,Q as sleep,R as sleep_random,v as success,d as timestampToDate,U as toPercentage,w as userAgent,j as uuidv4,A as warn,p as yesterdayDate};
1
+ import{downloadImage as r,downloadVideo as t}from"./download/index.js";import{dateTimeToNow as f,dateToNow as a,timestampToDate as d,yesterdayDate as p}from"./date-time.js";import{getNodeName as g}from"./env.js";import{fetch as l,fetchHtml as n,fetchJson as s,fetchText as c,mobileUserAgent as u,userAgent as T}from"./fetch.js";import{fixed2 as w,fixed4 as N,toPercentage as y}from"./num.js";import{logger as A}from"./pino.js";import{sleep as I,sleep_random as P}from"./sleep.js";import{genId as b,uuidv4 as H}from"./uuid.js";import{getRedirectUrl as Q,removeQueryParams as R}from"./url.js";import{default as _}from"pino";export{f as dateTimeToNow,a as dateToNow,r as downloadImage,t as downloadVideo,l as fetch,n as fetchHtml,s as fetchJson,c as fetchText,w as fixed2,N as fixed4,b as genId,g as getNodeName,Q as getRedirectUrl,A as logger,u as mobileUserAgent,_ as pino,R as removeQueryParams,I as sleep,P as sleep_random,d as timestampToDate,y as toPercentage,T as userAgent,H as uuidv4,p as yesterdayDate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secret-momo/utils",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -27,7 +27,6 @@
27
27
  ]
28
28
  },
29
29
  "scripts": {
30
- "postinstall": "bun outdated",
31
30
  "prepublishOnly": "bun run build",
32
31
  "build": "rm -rf lib && rollup -c && tsc -p tsconfig.json"
33
32
  },
@@ -42,7 +41,7 @@
42
41
  "eslint-plugin-unused-imports": "4.4.1",
43
42
  "husky": "9.1.7",
44
43
  "jiti": "2.7.0",
45
- "lint-staged": "17.0.7",
44
+ "lint-staged": "17.0.8",
46
45
  "prettier": "3.8.4",
47
46
  "rollup": "4.62.2",
48
47
  "rollup-plugin-esbuild": "6.2.1",
@@ -50,7 +49,6 @@
50
49
  "typescript-eslint": "8.61.1"
51
50
  },
52
51
  "dependencies": {
53
- "consola": "3.4.2",
54
52
  "dayjs": "1.11.21",
55
53
  "pino": "10.3.1",
56
54
  "pino-pretty": "13.1.3"
package/lib/log.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import consola from 'consola';
2
- export { consola };
3
- export declare function log(message: string): void;
4
- export declare function warn(message: string): void;
5
- export declare function error(e: unknown): void;
6
- export declare function success(message: string): void;
7
- export declare function info(message: string): void;
package/lib/log.js DELETED
@@ -1 +0,0 @@
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};