qsu 1.11.6 → 1.12.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.
@@ -51,3 +51,7 @@ export interface HTTPRequestOption {
51
51
  headers?: AnyValueObject | undefined | null;
52
52
  onError?: (error: any) => void;
53
53
  }
54
+ export interface GetUptimeOption {
55
+ format?: boolean;
56
+ floor?: boolean;
57
+ }
@@ -6,4 +6,5 @@ export { md5Hash } from './md5Hash.js';
6
6
  export { objectId } from './objectId.js';
7
7
  export { sha1Hash } from './sha1Hash.js';
8
8
  export { sha256Hash } from './sha256Hash.js';
9
- export { strToNumberHash } from './strToNumberHash.js';
9
+ export { sha512Hash } from './sha512Hash.js';
10
+ export { numberHash } from './numberHash.js';
@@ -1 +1 @@
1
- export{decodeBase64}from"./decodeBase64.js";export{decrypt}from"./decrypt.js";export{encodeBase64}from"./encodeBase64.js";export{encrypt}from"./encrypt.js";export{md5Hash}from"./md5Hash.js";export{objectId}from"./objectId.js";export{sha1Hash}from"./sha1Hash.js";export{sha256Hash}from"./sha256Hash.js";export{strToNumberHash}from"./strToNumberHash.js";
1
+ export{decodeBase64}from"./decodeBase64.js";export{decrypt}from"./decrypt.js";export{encodeBase64}from"./encodeBase64.js";export{encrypt}from"./encrypt.js";export{md5Hash}from"./md5Hash.js";export{objectId}from"./objectId.js";export{sha1Hash}from"./sha1Hash.js";export{sha256Hash}from"./sha256Hash.js";export{sha512Hash}from"./sha512Hash.js";export{numberHash}from"./numberHash.js";
@@ -1 +1,2 @@
1
- export declare function md5Hash(str: string): string;
1
+ import type { BinaryToTextEncoding } from 'node:crypto';
2
+ export declare function md5Hash(str: string, encoding?: BinaryToTextEncoding): string;
@@ -1 +1 @@
1
- import{createHash as t}from"crypto";export function md5Hash(r){return t("md5").update(r).digest("hex")}
1
+ import{createHash as t}from"crypto";export function md5Hash(r,e){return t("md5").update(r).digest(e??"hex")}
@@ -0,0 +1 @@
1
+ export declare function numberHash(str: string): number;
@@ -0,0 +1 @@
1
+ export function numberHash(e){if(!e)return 0;let r=0;for(let t=0;t<e.length;t+=1)r=(r<<5)-r+e.charCodeAt(t),r|=0;return r}
@@ -1 +1,2 @@
1
- export declare function sha1Hash(str: string): string;
1
+ import type { BinaryToTextEncoding } from 'node:crypto';
2
+ export declare function sha1Hash(str: string, encoding?: BinaryToTextEncoding): string;
@@ -1 +1 @@
1
- import{createHash as t}from"crypto";export function sha1Hash(r){return t("sha1").update(r).digest("hex")}
1
+ import{createHash as t}from"crypto";export function sha1Hash(r,e){return t("sha1").update(r).digest(e??"hex")}
@@ -1 +1,2 @@
1
- export declare function sha256Hash(str: string): string;
1
+ import type { BinaryToTextEncoding } from 'node:crypto';
2
+ export declare function sha256Hash(str: string, encoding?: BinaryToTextEncoding): string;
@@ -1 +1 @@
1
- import{createHash as t}from"crypto";export function sha256Hash(r){return t("sha256").update(r).digest("hex")}
1
+ import{createHash as t}from"crypto";export function sha256Hash(r,e){return t("sha256").update(r).digest(e??"hex")}
@@ -0,0 +1,2 @@
1
+ import type { BinaryToTextEncoding } from 'node:crypto';
2
+ export declare function sha512Hash(str: string, encoding?: BinaryToTextEncoding): string;
@@ -0,0 +1 @@
1
+ import{createHash as t}from"crypto";export function sha512Hash(r,e){return t("sha512").update(r).digest(e??"hex")}
@@ -1 +1 @@
1
- import{objToQueryString as t}from"../../object/objToQueryString.js";import{urlJoin as e}from"../../string/urlJoin.js";import{Readable as r}from"node:stream";function a(t){let e;if(t?.headers?.["Content-Type"])e=t?.headers?.["Content-Type"];else switch(t?.bodyType){case"form-data":e="multipart/form-data";break;case"x-www-form-urlencoded":e="application/x-www-form-urlencoded";break;case"json":e="application/json;charset=UTF-8";break;case"text":e="plain/text;charset=UTF-8";break;default:e=null}const r={};return t?.auth?.bearer&&t?.auth?.bearer.length>0&&(r.Authorization=`Bearer ${t?.auth?.bearer}`),t?.auth?.apiKey&&t?.auth?.apiKey.length>0&&(r["x-API-key"]=t?.auth?.apiKey),{...r,...t?.headers,...e?{"Content-Type":e}:{},"Accept-Encoding":"gzip, deflate, br",Charset:"utf-8"}}export async function fetchData(o,i){const n=i||{},s=n.queryParameters?`?${t(n.queryParameters)}`:null;let h,l,u=null;if(o.length<1)throw new Error("`url` is required");if(n.body)switch(n.bodyType){case"x-www-form-urlencoded":u=t(n.body);break;case"form-data":u=n.body;break;default:u=JSON.stringify(n.body)}if(n.method&&(n.get||n.post||n.put||n.delete||n.patch))throw new Error("`method` and `get|post|put|delete|patch` cannot be used together");if(h=n.get?"GET":n.post?"POST":n.put?"PUT":n.delete?"DELETE":n.patch?"PATCH":n.method||"GET",!n.host&&!o.startsWith("/"))throw new Error("`url` must begin with `/`.");if(n.host&&n.host.length>0){if(o.startsWith("http")||o.includes("://"))throw new Error("If `host` is specified, `url` must begin with `/`.");l=e(n.host,o)}else l=o;try{const t=await fetch(e(l,s),{...n.auth?{credentials:"include"}:{},...n.timeout?{signal:AbortSignal.timeout(n.timeout)}:{},method:h,body:u,headers:n.headers||a(n)});if(!t.ok||!t.body)return null;const o=t.headers.get("content-type")||"",i=function(t,e){if(/attachment|filename=/i.test(e))return!0;const r=t.split(";")?.[0]?.trim()?.toLowerCase()||"";return!["text/html","text/css","text/javascript","application/json","application/ld+json","application/xml","text/xml","text/plain"].some(t=>r===t)&&!r.startsWith("text/")&&(r.startsWith("application/")||r.startsWith("image/")||r.startsWith("video/")||r.startsWith("audio/")||r.startsWith("font/"))}(o,t.headers.get("content-disposition")||"");return n.toStream?r.fromWeb(t.body):i?Buffer.from(await t.arrayBuffer()):o.length<1?await t.text():o.includes("application/json")?await t.json():await t.text()}catch(t){return n.onError&&n.onError(t),null}}
1
+ import{objToQueryString as t}from"../../object/objToQueryString.js";import{urlJoin as e}from"../../string/urlJoin.js";import{Readable as r}from"node:stream";function a(t){let e;if(t?.headers?.["Content-Type"])e=t?.headers?.["Content-Type"];else switch(t?.bodyType){case"form-data":e="multipart/form-data";break;case"x-www-form-urlencoded":e="application/x-www-form-urlencoded";break;case"json":e="application/json;charset=UTF-8";break;case"text":e="plain/text;charset=UTF-8";break;default:e=null}const r={};return t?.auth?.bearer&&t?.auth?.bearer.length>0&&(r.Authorization=`Bearer ${t?.auth?.bearer}`),t?.auth?.apiKey&&t?.auth?.apiKey.length>0&&(r["x-API-key"]=t?.auth?.apiKey),{...r,...e?{"Content-Type":e}:{},"Accept-Encoding":"gzip, deflate, br",Charset:"utf-8",...t?.headers}}export async function fetchData(o,i){const n=i||{},s=n.queryParameters?`?${t(n.queryParameters)}`:null;let h,l,u=null;if(o.length<1)throw new Error("`url` is required");if(n.body)switch(n.bodyType){case"x-www-form-urlencoded":u=t(n.body);break;case"form-data":u=n.body;break;default:u=JSON.stringify(n.body)}if(n.method&&(n.get||n.post||n.put||n.delete||n.patch))throw new Error("`method` and `get|post|put|delete|patch` cannot be used together");if(h=n.get?"GET":n.post?"POST":n.put?"PUT":n.delete?"DELETE":n.patch?"PATCH":n.method||"GET",!n.host&&!o.startsWith("/"))throw new Error("`url` must begin with `/`.");if(n.host&&n.host.length>0){if(o.startsWith("http")||o.includes("://"))throw new Error("If `host` is specified, `url` must begin with `/`.");l=e(n.host,o)}else l=o;try{const t=await fetch(e(l,s),{...n.auth?{credentials:"include"}:{},...n.timeout?{signal:AbortSignal.timeout(n.timeout)}:{},method:h,body:u,headers:a(n)});if(!t.ok||!t.body)return null;const o=t.headers.get("content-type")||"",i=function(t,e){if(/attachment|filename=/i.test(e))return!0;const r=t.split(";")?.[0]?.trim()?.toLowerCase()||"";return!["text/html","text/css","text/javascript","application/json","application/ld+json","application/xml","text/xml","text/plain"].some(t=>r===t)&&!r.startsWith("text/")&&(r.startsWith("application/")||r.startsWith("image/")||r.startsWith("video/")||r.startsWith("audio/")||r.startsWith("font/"))}(o,t.headers.get("content-disposition")||"");return n.toStream?r.fromWeb(t.body):i?Buffer.from(await t.arrayBuffer()):o.length<1?await t.text():o.includes("application/json")?await t.json():await t.text()}catch(t){return n.onError&&n.onError(t),null}}
@@ -0,0 +1,2 @@
1
+ import { GetUptimeOption } from '../../_types/global';
2
+ export declare function getUptime(opt?: GetUptimeOption): number | string;
@@ -0,0 +1 @@
1
+ import{numberFormat as o}from"../../format/numberFormat.js";export function getUptime(r){let t=process?.uptime();return t?(r?.floor&&(t=Math.floor(t)),r?.format?o(t):t):0}
@@ -3,4 +3,5 @@ export { getHostname } from './getHostname.js';
3
3
  export { getMachineId } from './getMachineId.js';
4
4
  export { getRamSize } from './getRamSize.js';
5
5
  export { getSid } from './getSid.js';
6
+ export { getUptime } from './getUptime.js';
6
7
  export { runCommand } from './runCommand.js';
@@ -1 +1 @@
1
- export{getCpu}from"./getCpu.js";export{getHostname}from"./getHostname.js";export{getMachineId}from"./getMachineId.js";export{getRamSize}from"./getRamSize.js";export{getSid}from"./getSid.js";export{runCommand}from"./runCommand.js";
1
+ export{getCpu}from"./getCpu.js";export{getHostname}from"./getHostname.js";export{getMachineId}from"./getMachineId.js";export{getRamSize}from"./getRamSize.js";export{getSid}from"./getSid.js";export{getUptime}from"./getUptime.js";export{runCommand}from"./runCommand.js";
@@ -1 +1 @@
1
- import{contains as t}from"../verify/contains.js";import{capitalizeFirst as r}from"./capitalizeFirst.js";export function capitalizeEachWords(o,i){if(!o)return"";const a=o.trim().toLowerCase().split(" ");for(let o=0,e=a.length;o<e;o+=1)i&&t(a[o],["in","on","the","at","and","or","of","for","to","that","a","by","it","is","as","are","were","was","nor","an"],!0)||(a[o]=r(a[o]));return r(a.join(" "))}
1
+ import{contains as t}from"../verify/contains.js";import{capitalizeFirst as r}from"./capitalizeFirst.js";export function capitalizeEachWords(o,i){if(!o)return"";let a=o.trim();i&&(a=a.toLowerCase());const e=a.split(" ");for(let o=0,a=e.length;o<a;o+=1)i&&t(e[o],["in","on","the","at","and","or","of","for","to","that","a","by","it","is","as","are","were","was","nor","an"],!0)||(e[o]=r(e[o]));return r(e.join(" "))}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qsu",
3
- "version": "1.11.6",
3
+ "version": "1.12.1",
4
4
  "description": "qsu is a utility library that contains useful and frequently used functions. Start with your preferred language and the modern development environment.",
5
5
  "author": "CDGet <jooy2.contact@gmail.com>",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "types": "dist/index.d.ts",
17
17
  "scripts": {
18
18
  "build": "tsc --project tsconfig.prod.json && npm run minify",
19
- "test": "npm run build && glob-bin -c \"tsx --test\" \"./test/**/*.test.ts\"",
19
+ "test": "npm run build && node --import tsx --test \"./test/**/*.test.ts\"",
20
20
  "lint": "eslint . --ext .js,.ts .",
21
21
  "lint:fix": "eslint . --ext .js,.ts --fix .",
22
22
  "minify": "terser-glob 'dist/**/*.js' --config-file terser.config.json",
@@ -73,19 +73,18 @@
73
73
  ],
74
74
  "devDependencies": {
75
75
  "@eslint/js": "^9.39.2",
76
- "@types/node": "^25.6.0",
77
- "@typescript-eslint/parser": "^8.58.1",
76
+ "@types/node": "^25.9.1",
77
+ "@typescript-eslint/parser": "^8.59.4",
78
78
  "dayjs": "^1.11.20",
79
79
  "eslint": "^9.39.2",
80
80
  "eslint-config-prettier": "^10.1.8",
81
- "eslint-plugin-n": "^17.24.0",
82
- "glob-bin": "^1.1.0",
83
- "globals": "^17.4.0",
84
- "jiti": "^2.6.1",
85
- "prettier": "^3.8.2",
81
+ "eslint-plugin-n": "^18.0.1",
82
+ "globals": "^17.6.0",
83
+ "jiti": "^2.7.0",
84
+ "prettier": "^3.8.3",
86
85
  "terser-glob": "^1.2.1",
87
- "tsx": "^4.21.0",
88
- "typescript": "6.0.2",
89
- "typescript-eslint": "^8.58.1"
86
+ "tsx": "^4.22.3",
87
+ "typescript": "6.0.3",
88
+ "typescript-eslint": "^8.59.4"
90
89
  }
91
90
  }
@@ -1 +0,0 @@
1
- export declare function strToNumberHash(str: string): number;
@@ -1 +0,0 @@
1
- export function strToNumberHash(r){if(!r)return 0;let t=0;for(let e=0;e<r.length;e+=1)t=(t<<5)-t+r.charCodeAt(e),t|=0;return t}