@acrool/js-utils
Advanced tools
+13
-0
@@ -73,1 +73,14 @@ /** | ||
| }): FormData; | ||
| /** | ||
| * 將物件資料轉成 URLSearchParams (用於 x-www-form-urlencoded) | ||
| * ex: { | ||
| * account: 'xxxxx', | ||
| * password: '12345' | ||
| * } | ||
| * -> URLSearchParams with account=xxxxx&password=12345 | ||
| * | ||
| * @param data | ||
| */ | ||
| export declare function objToFormUrl(data: { | ||
| [key: string]: any; | ||
| }): URLSearchParams; |
@@ -1,1 +0,1 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function b(t){const n=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],e=function(r){return Number.isNaN(r)?"00":n[(r-r%16)/16]+n[r%16]},s=t.toLowerCase().match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);if(s!==null&&s.length>3)return["#",e(s[1])+e(s[2])+e(s[3])].join("")}function p(t,n=1){let e=t.replace("#","");const s=void 0;let r;if(/^[0-9A-F]{3}$|^[0-9A-F]{6}$/.test(e.toUpperCase())){if(e.length===3){if(r=e.match(/[0-9A-F]/g),!r)return s;e=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]}const a=parseInt(e.substr(0,2),16),o=parseInt(e.substr(2,2),16),l=parseInt(e.substr(4,2),16);if(n<1){const i=n.toString().replace("0.",".");return`rgba(${[a,o,l,i].join()})`}return`rgb(${[a,o,l].join()})`}return s}function y(t){return typeof t>"u"||["",0,null].includes(t)?null:t}function d(t,n=0){const e=Number(t);return isNaN(e)?n:e}function g(t,n=!0){return t==="true"||t===!0||t===1?!0:t==="false"||t===0||t===!1?!1:n?void 0:!1}function T(t){const n=new FileReader;return new Promise((e,s)=>{n.onload=r=>{var a;(a=r.target)!=null&&a.result&&e(r.target.result)},n.onerror=r=>s(r),n.readAsDataURL(t)})}function u(t,n){n=n||"";const e=atob(t),s=[];for(let a=0;a<e.length;a+=1024){const o=e.slice(a,a+1024),l=new Array(o.length);for(let c=0;c<o.length;c++)l[c]=o.charCodeAt(c);const i=new Uint8Array(l);s.push(i)}return new Blob(s,{type:n})}function m(t){const e=new RegExp(/data:(.+);base64,/).exec(t);if(e&&e[0]){const s=e[1],r=t.replace(e[0],"");return u(r,s)}return null}function h(t){const n=new FormData,e=(s,r="")=>{for(const[a,o]of Object.entries(s)){const l=r?`${r}[${a}]`:a;if(o instanceof File)n.append(l,o);else if(o instanceof Blob){const c=o.type.split("/")[1]||"bin",f=`${a}.${c}`;n.append(l,o,f)}else Array.isArray(o)?o.forEach((i,c)=>{typeof i=="object"&&i!==null?e(i,`${l}[${c}]`):n.append(`${l}[${c}]`,i)}):typeof o=="object"&&o!==null?e(o,l):o!=null&&n.append(l,o)}};return e(t),n}exports.anyToBoolean=g;exports.anyToNumber=d;exports.base64ToBlob=u;exports.base64ToBlobWithContentType=m;exports.emptyToNull=y;exports.fileToBase64=T;exports.hexToRGB=p;exports.objToFormData=h;exports.rgbToHex=b; | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function b(r){const n=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],e=function(o){return Number.isNaN(o)?"00":n[(o-o%16)/16]+n[o%16]},s=r.toLowerCase().match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);if(s!==null&&s.length>3)return["#",e(s[1])+e(s[2])+e(s[3])].join("")}function p(r,n=1){let e=r.replace("#","");const s=void 0;let o;if(/^[0-9A-F]{3}$|^[0-9A-F]{6}$/.test(e.toUpperCase())){if(e.length===3){if(o=e.match(/[0-9A-F]/g),!o)return s;e=o[0]+o[0]+o[1]+o[1]+o[2]+o[2]}const a=parseInt(e.substr(0,2),16),t=parseInt(e.substr(2,2),16),l=parseInt(e.substr(4,2),16);if(n<1){const c=n.toString().replace("0.",".");return`rgba(${[a,t,l,c].join()})`}return`rgb(${[a,t,l].join()})`}return s}function y(r){return typeof r>"u"||["",0,null].includes(r)?null:r}function d(r,n=0){const e=Number(r);return isNaN(e)?n:e}function g(r,n=!0){return r==="true"||r===!0||r===1?!0:r==="false"||r===0||r===!1?!1:n?void 0:!1}function T(r){const n=new FileReader;return new Promise((e,s)=>{n.onload=o=>{var a;(a=o.target)!=null&&a.result&&e(o.target.result)},n.onerror=o=>s(o),n.readAsDataURL(r)})}function f(r,n){n=n||"";const e=atob(r),s=[];for(let a=0;a<e.length;a+=1024){const t=e.slice(a,a+1024),l=new Array(t.length);for(let i=0;i<t.length;i++)l[i]=t.charCodeAt(i);const c=new Uint8Array(l);s.push(c)}return new Blob(s,{type:n})}function m(r){const e=new RegExp(/data:(.+);base64,/).exec(r);if(e&&e[0]){const s=e[1],o=r.replace(e[0],"");return f(o,s)}return null}function h(r){const n=new FormData,e=(s,o="")=>{for(const[a,t]of Object.entries(s)){const l=o?`${o}[${a}]`:a;if(t instanceof File)n.append(l,t);else if(t instanceof Blob){const i=t.type.split("/")[1]||"bin",u=`${a}.${i}`;n.append(l,t,u)}else Array.isArray(t)?t.forEach((c,i)=>{typeof c=="object"&&c!==null?e(c,`${l}[${i}]`):n.append(`${l}[${i}]`,c)}):typeof t=="object"&&t!==null?e(t,l):t!=null&&n.append(l,t)}};return e(r),n}function $(r){const n=new URLSearchParams,e=(s,o="")=>{for(const[a,t]of Object.entries(s)){const l=o?`${o}[${a}]`:a;Array.isArray(t)?t.forEach((c,i)=>{typeof c=="object"&&c!==null?e(c,`${l}[${i}]`):n.append(`${l}[${i}]`,String(c))}):typeof t=="object"&&t!==null?e(t,l):t!=null&&n.append(l,String(t))}};return e(r),n}exports.anyToBoolean=g;exports.anyToNumber=d;exports.base64ToBlob=f;exports.base64ToBlobWithContentType=m;exports.emptyToNull=y;exports.fileToBase64=T;exports.hexToRGB=p;exports.objToFormData=h;exports.objToFormUrl=$;exports.rgbToHex=b; |
+63
-51
@@ -1,92 +0,104 @@ | ||
| function b(t) { | ||
| const n = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"], e = function(r) { | ||
| return Number.isNaN(r) ? "00" : n[(r - r % 16) / 16] + n[r % 16]; | ||
| }, s = t.toLowerCase().match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); | ||
| function b(r) { | ||
| const n = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"], e = function(o) { | ||
| return Number.isNaN(o) ? "00" : n[(o - o % 16) / 16] + n[o % 16]; | ||
| }, s = r.toLowerCase().match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); | ||
| if (s !== null && s.length > 3) | ||
| return ["#", e(s[1]) + e(s[2]) + e(s[3])].join(""); | ||
| } | ||
| function p(t, n = 1) { | ||
| let e = t.replace("#", ""); | ||
| function p(r, n = 1) { | ||
| let e = r.replace("#", ""); | ||
| const s = void 0; | ||
| let r; | ||
| let o; | ||
| if (/^[0-9A-F]{3}$|^[0-9A-F]{6}$/.test(e.toUpperCase())) { | ||
| if (e.length === 3) { | ||
| if (r = e.match(/[0-9A-F]/g), !r) | ||
| if (o = e.match(/[0-9A-F]/g), !o) | ||
| return s; | ||
| e = r[0] + r[0] + r[1] + r[1] + r[2] + r[2]; | ||
| e = o[0] + o[0] + o[1] + o[1] + o[2] + o[2]; | ||
| } | ||
| const a = parseInt(e.substr(0, 2), 16), o = parseInt(e.substr(2, 2), 16), i = parseInt(e.substr(4, 2), 16); | ||
| const a = parseInt(e.substr(0, 2), 16), t = parseInt(e.substr(2, 2), 16), c = parseInt(e.substr(4, 2), 16); | ||
| if (n < 1) { | ||
| const c = n.toString().replace("0.", "."); | ||
| return `rgba(${[a, o, i, c].join()})`; | ||
| const l = n.toString().replace("0.", "."); | ||
| return `rgba(${[a, t, c, l].join()})`; | ||
| } | ||
| return `rgb(${[a, o, i].join()})`; | ||
| return `rgb(${[a, t, c].join()})`; | ||
| } | ||
| return s; | ||
| } | ||
| function d(t) { | ||
| return typeof t > "u" || ["", 0, null].includes(t) ? null : t; | ||
| function d(r) { | ||
| return typeof r > "u" || ["", 0, null].includes(r) ? null : r; | ||
| } | ||
| function y(t, n = 0) { | ||
| const e = Number(t); | ||
| function y(r, n = 0) { | ||
| const e = Number(r); | ||
| return isNaN(e) ? n : e; | ||
| } | ||
| function g(t, n = !0) { | ||
| return t === "true" || t === !0 || t === 1 ? !0 : t === "false" || t === 0 || t === !1 ? !1 : n ? void 0 : !1; | ||
| function g(r, n = !0) { | ||
| return r === "true" || r === !0 || r === 1 ? !0 : r === "false" || r === 0 || r === !1 ? !1 : n ? void 0 : !1; | ||
| } | ||
| function h(t) { | ||
| function $(r) { | ||
| const n = new FileReader(); | ||
| return new Promise((e, s) => { | ||
| n.onload = (r) => { | ||
| n.onload = (o) => { | ||
| var a; | ||
| (a = r.target) != null && a.result && e(r.target.result); | ||
| }, n.onerror = (r) => s(r), n.readAsDataURL(t); | ||
| (a = o.target) != null && a.result && e(o.target.result); | ||
| }, n.onerror = (o) => s(o), n.readAsDataURL(r); | ||
| }); | ||
| } | ||
| function f(t, n) { | ||
| function u(r, n) { | ||
| n = n || ""; | ||
| const e = atob(t), s = []; | ||
| const e = atob(r), s = []; | ||
| for (let a = 0; a < e.length; a += 1024) { | ||
| const o = e.slice(a, a + 1024), i = new Array(o.length); | ||
| for (let l = 0; l < o.length; l++) | ||
| i[l] = o.charCodeAt(l); | ||
| const c = new Uint8Array(i); | ||
| s.push(c); | ||
| const t = e.slice(a, a + 1024), c = new Array(t.length); | ||
| for (let i = 0; i < t.length; i++) | ||
| c[i] = t.charCodeAt(i); | ||
| const l = new Uint8Array(c); | ||
| s.push(l); | ||
| } | ||
| return new Blob(s, { type: n }); | ||
| } | ||
| function m(t) { | ||
| const e = new RegExp(/data:(.+);base64,/).exec(t); | ||
| function h(r) { | ||
| const e = new RegExp(/data:(.+);base64,/).exec(r); | ||
| if (e && e[0]) { | ||
| const s = e[1], r = t.replace(e[0], ""); | ||
| return f(r, s); | ||
| const s = e[1], o = r.replace(e[0], ""); | ||
| return u(o, s); | ||
| } | ||
| return null; | ||
| } | ||
| function $(t) { | ||
| const n = new FormData(), e = (s, r = "") => { | ||
| for (const [a, o] of Object.entries(s)) { | ||
| const i = r ? `${r}[${a}]` : a; | ||
| if (o instanceof File) | ||
| n.append(i, o); | ||
| else if (o instanceof Blob) { | ||
| const l = o.type.split("/")[1] || "bin", u = `${a}.${l}`; | ||
| n.append(i, o, u); | ||
| } else Array.isArray(o) ? o.forEach((c, l) => { | ||
| typeof c == "object" && c !== null ? e(c, `${i}[${l}]`) : n.append(`${i}[${l}]`, c); | ||
| }) : typeof o == "object" && o !== null ? e(o, i) : o != null && n.append(i, o); | ||
| function m(r) { | ||
| const n = new FormData(), e = (s, o = "") => { | ||
| for (const [a, t] of Object.entries(s)) { | ||
| const c = o ? `${o}[${a}]` : a; | ||
| if (t instanceof File) | ||
| n.append(c, t); | ||
| else if (t instanceof Blob) { | ||
| const i = t.type.split("/")[1] || "bin", f = `${a}.${i}`; | ||
| n.append(c, t, f); | ||
| } else Array.isArray(t) ? t.forEach((l, i) => { | ||
| typeof l == "object" && l !== null ? e(l, `${c}[${i}]`) : n.append(`${c}[${i}]`, l); | ||
| }) : typeof t == "object" && t !== null ? e(t, c) : t != null && n.append(c, t); | ||
| } | ||
| }; | ||
| return e(t), n; | ||
| return e(r), n; | ||
| } | ||
| function A(r) { | ||
| const n = new URLSearchParams(), e = (s, o = "") => { | ||
| for (const [a, t] of Object.entries(s)) { | ||
| const c = o ? `${o}[${a}]` : a; | ||
| Array.isArray(t) ? t.forEach((l, i) => { | ||
| typeof l == "object" && l !== null ? e(l, `${c}[${i}]`) : n.append(`${c}[${i}]`, String(l)); | ||
| }) : typeof t == "object" && t !== null ? e(t, c) : t != null && n.append(c, String(t)); | ||
| } | ||
| }; | ||
| return e(r), n; | ||
| } | ||
| export { | ||
| g as anyToBoolean, | ||
| y as anyToNumber, | ||
| f as base64ToBlob, | ||
| m as base64ToBlobWithContentType, | ||
| u as base64ToBlob, | ||
| h as base64ToBlobWithContentType, | ||
| d as emptyToNull, | ||
| h as fileToBase64, | ||
| $ as fileToBase64, | ||
| p as hexToRGB, | ||
| $ as objToFormData, | ||
| m as objToFormData, | ||
| A as objToFormUrl, | ||
| b as rgbToHex | ||
| }; |
+2
-1
| { | ||
| "name": "@acrool/js-utils", | ||
| "version": "3.2.26", | ||
| "version": "3.2.28", | ||
| "description": "Common javascript utils methods for project development", | ||
@@ -11,2 +11,3 @@ "keywords": [ | ||
| "license": "MIT", | ||
| "packageManager": "yarn@4.9.1", | ||
| "repository": { | ||
@@ -13,0 +14,0 @@ "type": "git", |
107443
1.06%2358
1.11%