Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@acrool/js-utils

Package Overview
Dependencies
Maintainers
0
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@acrool/js-utils - npm Package Compare versions

Comparing version 3.2.9 to 3.2.10-alpha.0

6

array/array.d.ts

@@ -173,1 +173,7 @@ import { SortOrder, TSortByFn, TGroupTreeBy, TGroupByFn, TArrayOrEmpty } from './types';

export declare function generateSortByProperty<T>(selector: (row: T) => any, order?: SortOrder): (a: T, b: T) => number;
/**
* 生成 Array 數量
* @param count 生成多少個
* @param prefixKeyName 前綴 Key name
*/
export declare const generatorArray: (count: number, prefixKeyName?: string) => string[];

2

array/index.cjs.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(n,e){return n?[e].concat(n.slice(0)):[e]}function p(n,e){return n?n.slice(0).concat(e):[e]}function l(n,e,u){return n?[...n.slice(0,e),u,...n.slice(e)]:[u]}function g(n,e,u){if(!n||e===u)return n;const t=[...n],r=t[e];return t.splice(e,1),t.splice(u,0,r),t}function d(n,e){if(!n)return n;const u=n.findIndex(e);return u===-1?n:i(n,u)}function h(n,e){if(!n)return n;const u=n.findIndex(e.finder);return u===-1?n:c(n,u,e.updater)}function i(n,e){return!n||e===-1||e>n.length-1?n:[...n.slice(0,e),...n.slice(e+1)]}function c(n,e,u){if(e===-1||!n||e>n.length-1)return n;const t={...n[e]};u(t);const r=[...n];return r[e]=t,r}function m(n,e){if(!n)return n;const u=new Set,t=new Array;for(const r of n){const o=e?e(r):r;u.has(o)||(u.add(o),t.push(r))}return t}function B(n,e){return n?n.join(e):""}function A(n,e){if(!n)return n;const u=Math.ceil(n.length/e);return new Array(u).fill([]).map((r,o)=>n.slice(o*e,o*e+e))}function S(n,e){return n.reduce((u,t)=>{const r=e(t);return u[r]||(u[r]=[]),u[r].push(t),u},{})}function v(n,e){const u={};return n.forEach(t=>{const{groupKey:r,groupData:o,child:f}=e(t);u[r]||(u[r]={...o,children:[]}),u[r].children.push(f)}),Object.keys(u).map(t=>u[t])}function w(n,e){const u=[...n];return u.sort(e),u}function I(n,e="ASC"){return function(u,t){const r=n(u),o=n(t);return r<o?e==="ASC"?-1:1:r>o?e==="ASC"?1:-1:0}}exports.arrayJoin=B;exports.generateSortByProperty=I;exports.groupBy=S;exports.groupTreeBy=v;exports.insert=l;exports.move=g;exports.pull=s;exports.push=p;exports.removeByIndex=i;exports.removeFind=d;exports.sort=w;exports.splitArray=A;exports.unique=m;exports.updateByIndex=c;exports.updateFind=h;
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function s(n,e){return n?[e].concat(n.slice(0)):[e]}function p(n,e){return n?n.slice(0).concat(e):[e]}function l(n,e,r){return n?[...n.slice(0,e),r,...n.slice(e)]:[r]}function g(n,e,r){if(!n||e===r)return n;const t=[...n],u=t[e];return t.splice(e,1),t.splice(r,0,u),t}function d(n,e){if(!n)return n;const r=n.findIndex(e);return r===-1?n:i(n,r)}function h(n,e){if(!n)return n;const r=n.findIndex(e.finder);return r===-1?n:c(n,r,e.updater)}function i(n,e){return!n||e===-1||e>n.length-1?n:[...n.slice(0,e),...n.slice(e+1)]}function c(n,e,r){if(e===-1||!n||e>n.length-1)return n;const t={...n[e]};r(t);const u=[...n];return u[e]=t,u}function m(n,e){if(!n)return n;const r=new Set,t=new Array;for(const u of n){const o=e?e(u):u;r.has(o)||(r.add(o),t.push(u))}return t}function A(n,e){return n?n.join(e):""}function B(n,e){if(!n)return n;const r=Math.ceil(n.length/e);return new Array(r).fill([]).map((u,o)=>n.slice(o*e,o*e+e))}function w(n,e){return n.reduce((r,t)=>{const u=e(t);return r[u]||(r[u]=[]),r[u].push(t),r},{})}function S(n,e){const r={};return n.forEach(t=>{const{groupKey:u,groupData:o,child:f}=e(t);r[u]||(r[u]={...o,children:[]}),r[u].children.push(f)}),Object.keys(r).map(t=>r[t])}function v(n,e){const r=[...n];return r.sort(e),r}function I(n,e="ASC"){return function(r,t){const u=n(r),o=n(t);return u<o?e==="ASC"?-1:1:u>o?e==="ASC"?1:-1:0}}const b=(n,e="skeleton_")=>Array.from({length:n}).map((r,t)=>`${e}${t}`);exports.arrayJoin=A;exports.generateSortByProperty=I;exports.generatorArray=b;exports.groupBy=w;exports.groupTreeBy=S;exports.insert=l;exports.move=g;exports.pull=s;exports.push=p;exports.removeByIndex=i;exports.removeFind=d;exports.sort=v;exports.splitArray=B;exports.unique=m;exports.updateByIndex=c;exports.updateFind=h;

@@ -13,4 +13,4 @@ function s(n, e) {

return n;
const t = [...n], c = t[e];
return t.splice(e, 1), t.splice(u, 0, c), t;
const t = [...n], o = t[e];
return t.splice(e, 1), t.splice(u, 0, o), t;
}

@@ -21,3 +21,3 @@ function h(n, e) {

const u = n.findIndex(e);
return u === -1 ? n : r(n, u);
return u === -1 ? n : i(n, u);
}

@@ -30,3 +30,3 @@ function m(n, e) {

}
function r(n, e) {
function i(n, e) {
return !n || e === -1 || e > n.length - 1 ? n : [...n.slice(0, e), ...n.slice(e + 1)];

@@ -39,4 +39,4 @@ }

u(t);
const c = [...n];
return c[e] = t, c;
const o = [...n];
return o[e] = t, o;
}

@@ -47,5 +47,5 @@ function A(n, e) {

const u = /* @__PURE__ */ new Set(), t = new Array();
for (const c of n) {
const i = e ? e(c) : c;
u.has(i) || (u.add(i), t.push(c));
for (const o of n) {
const r = e ? e(o) : o;
u.has(r) || (u.add(r), t.push(o));
}

@@ -61,8 +61,8 @@ return t;

const u = Math.ceil(n.length / e);
return new Array(u).fill([]).map((c, i) => n.slice(i * e, i * e + e));
return new Array(u).fill([]).map((o, r) => n.slice(r * e, r * e + e));
}
function B(n, e) {
return n.reduce((u, t) => {
const c = e(t);
return u[c] || (u[c] = []), u[c].push(t), u;
const o = e(t);
return u[o] || (u[o] = []), u[o].push(t), u;
}, {});

@@ -73,22 +73,24 @@ }

return n.forEach((t) => {
const { groupKey: c, groupData: i, child: o } = e(t);
u[c] || (u[c] = {
...i,
const { groupKey: o, groupData: r, child: c } = e(t);
u[o] || (u[o] = {
...r,
children: []
}), u[c].children.push(o);
}), u[o].children.push(c);
}), Object.keys(u).map((t) => u[t]);
}
function I(n, e) {
function k(n, e) {
const u = [...n];
return u.sort(e), u;
}
function k(n, e = "ASC") {
function I(n, e = "ASC") {
return function(u, t) {
const c = n(u), i = n(t);
return c < i ? e === "ASC" ? -1 : 1 : c > i ? e === "ASC" ? 1 : -1 : 0;
const o = n(u), r = n(t);
return o < r ? e === "ASC" ? -1 : 1 : o > r ? e === "ASC" ? 1 : -1 : 0;
};
}
const v = (n, e = "skeleton_") => Array.from({ length: n }).map((u, t) => `${e}${t}`);
export {
w as arrayJoin,
k as generateSortByProperty,
I as generateSortByProperty,
v as generatorArray,
B as groupBy,

@@ -100,5 +102,5 @@ S as groupTreeBy,

l as push,
r as removeByIndex,
i as removeByIndex,
h as removeFind,
I as sort,
k as sort,
d as splitArray,

@@ -105,0 +107,0 @@ A as unique,

@@ -62,1 +62,12 @@ /**

export declare function base64ToBlobWithContentType(base64Str: string): Blob | null;
/**
* 將物件資料轉成 FormData
* ex: {
* profile: {name: 'jack'}
* }
*
* @param data
*/
export declare function objToFormData(data: {
[key: string]: any;
}): FormData;

@@ -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]},o=t.toLowerCase().match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);if(o!==null&&o.length>3)return["#",e(o[1])+e(o[2])+e(o[3])].join("")}function f(t,n=1){let e=t.replace("#","");const o=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 o;e=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]}const s=parseInt(e.substr(0,2),16),u=parseInt(e.substr(2,2),16),a=parseInt(e.substr(4,2),16);if(n<1){const l=n.toString().replace("0.",".");return`rgba(${[s,u,a,l].join()})`}return`rgb(${[s,u,a].join()})`}return o}function g(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 y(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,o)=>{n.onload=r=>{var s;(s=r.target)!=null&&s.result&&e(r.target.result)},n.onerror=r=>o(r),n.readAsDataURL(t)})}function c(t,n){n=n||"";const e=atob(t),o=[];for(let s=0;s<e.length;s+=1024){const u=e.slice(s,s+1024),a=new Array(u.length);for(let i=0;i<u.length;i++)a[i]=u.charCodeAt(i);const l=new Uint8Array(a);o.push(l)}return new Blob(o,{type:n})}function h(t){const e=new RegExp(/data:(.+);base64,/).exec(t);if(e&&e[0]){const o=e[1],r=t.replace(e[0],"");return c(r,o)}return null}exports.anyToBoolean=y;exports.anyToNumber=d;exports.base64ToBlob=c;exports.base64ToBlobWithContentType=h;exports.emptyToNull=g;exports.fileToBase64=T;exports.hexToRGB=f;exports.rgbToHex=b;
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(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]},o=t.toLowerCase().match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);if(o!==null&&o.length>3)return["#",e(o[1])+e(o[2])+e(o[3])].join("")}function b(t,n=1){let e=t.replace("#","");const o=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 o;e=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]}const a=parseInt(e.substr(0,2),16),s=parseInt(e.substr(2,2),16),l=parseInt(e.substr(4,2),16);if(n<1){const u=n.toString().replace("0.",".");return`rgba(${[a,s,l,u].join()})`}return`rgb(${[a,s,l].join()})`}return o}function p(t){return typeof t>"u"||["",0,null].includes(t)?null:t}function y(t,n=0){const e=Number(t);return isNaN(e)?n:e}function d(t,n=!0){return t==="true"||t===!0||t===1?!0:t==="false"||t===0||t===!1?!1:n?void 0:!1}function g(t){const n=new FileReader;return new Promise((e,o)=>{n.onload=r=>{var a;(a=r.target)!=null&&a.result&&e(r.target.result)},n.onerror=r=>o(r),n.readAsDataURL(t)})}function i(t,n){n=n||"";const e=atob(t),o=[];for(let a=0;a<e.length;a+=1024){const s=e.slice(a,a+1024),l=new Array(s.length);for(let c=0;c<s.length;c++)l[c]=s.charCodeAt(c);const u=new Uint8Array(l);o.push(u)}return new Blob(o,{type:n})}function T(t){const e=new RegExp(/data:(.+);base64,/).exec(t);if(e&&e[0]){const o=e[1],r=t.replace(e[0],"");return i(r,o)}return null}function h(t){const n=new FormData,e=(o,r="")=>{for(const[a,s]of Object.entries(o)){const l=r?`${r}[${a}]`:a;Array.isArray(s)?s.forEach((u,c)=>{typeof u=="object"&&u!==null?e(u,`${l}[${c}]`):n.append(`${l}[${c}]`,u)}):typeof s=="object"&&s!==null?e(s,l):s!=null&&n.append(l,s)}};return e(t),n}exports.anyToBoolean=d;exports.anyToNumber=y;exports.base64ToBlob=i;exports.base64ToBlobWithContentType=T;exports.emptyToNull=p;exports.fileToBase64=g;exports.hexToRGB=b;exports.objToFormData=h;exports.rgbToHex=f;

@@ -1,2 +0,2 @@

function f(t) {
function i(t) {
const n = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"], e = function(r) {

@@ -18,12 +18,12 @@ return Number.isNaN(r) ? "00" : n[(r - r % 16) / 16] + n[r % 16];

}
const s = parseInt(e.substr(0, 2), 16), u = parseInt(e.substr(2, 2), 16), c = parseInt(e.substr(4, 2), 16);
const a = parseInt(e.substr(0, 2), 16), s = parseInt(e.substr(2, 2), 16), u = parseInt(e.substr(4, 2), 16);
if (n < 1) {
const a = n.toString().replace("0.", ".");
return `rgba(${[s, u, c, a].join()})`;
const c = n.toString().replace("0.", ".");
return `rgba(${[a, s, u, c].join()})`;
}
return `rgb(${[s, u, c].join()})`;
return `rgb(${[a, s, u].join()})`;
}
return o;
}
function g(t) {
function p(t) {
return typeof t > "u" || ["", 0, null].includes(t) ? null : t;

@@ -35,43 +35,55 @@ }

}
function h(t, n = !0) {
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 p(t) {
function y(t) {
const n = new FileReader();
return new Promise((e, o) => {
n.onload = (r) => {
var s;
(s = r.target) != null && s.result && e(r.target.result);
var a;
(a = r.target) != null && a.result && e(r.target.result);
}, n.onerror = (r) => o(r), n.readAsDataURL(t);
});
}
function l(t, n) {
function f(t, n) {
n = n || "";
const e = atob(t), o = [];
for (let s = 0; s < e.length; s += 1024) {
const u = e.slice(s, s + 1024), c = new Array(u.length);
for (let i = 0; i < u.length; i++)
c[i] = u.charCodeAt(i);
const a = new Uint8Array(c);
o.push(a);
for (let a = 0; a < e.length; a += 1024) {
const s = e.slice(a, a + 1024), u = new Array(s.length);
for (let l = 0; l < s.length; l++)
u[l] = s.charCodeAt(l);
const c = new Uint8Array(u);
o.push(c);
}
return new Blob(o, { type: n });
}
function y(t) {
function h(t) {
const e = new RegExp(/data:(.+);base64,/).exec(t);
if (e && e[0]) {
const o = e[1], r = t.replace(e[0], "");
return l(r, o);
return f(r, o);
}
return null;
}
function m(t) {
const n = new FormData(), e = (o, r = "") => {
for (const [a, s] of Object.entries(o)) {
const u = r ? `${r}[${a}]` : a;
Array.isArray(s) ? s.forEach((c, l) => {
typeof c == "object" && c !== null ? e(c, `${u}[${l}]`) : n.append(`${u}[${l}]`, c);
}) : typeof s == "object" && s !== null ? e(s, u) : s != null && n.append(u, s);
}
};
return e(t), n;
}
export {
h as anyToBoolean,
g as anyToBoolean,
d as anyToNumber,
l as base64ToBlob,
y as base64ToBlobWithContentType,
g as emptyToNull,
p as fileToBase64,
f as base64ToBlob,
h as base64ToBlobWithContentType,
p as emptyToNull,
y as fileToBase64,
b as hexToRGB,
f as rgbToHex
m as objToFormData,
i as rgbToHex
};

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function f(t){const e=[];for(const n in t)t[n]&&e.push(Number(n.replace("_","")));return e}function p(t){const e=new FormData;return(a=>{for(const[r,o]of Object.entries(a))if(Array.isArray(o)){let s=0;for(const c of o){if(typeof c=="object")for(const[u,i]of Object.entries(c))e.append(`${r}[${s}][${u}]`,i);else e.append(`${r}[${s}]`,c);s+=1}}else typeof o<"u"&&o!==null&&e.append(r,o)})(t),e}function b(t){const e={};return Object.entries(t).reduce((n,[a,r])=>({...n,[r]:a}),e)}function j(t,e){const n={};return Object.entries(t).reduce((a,[r,o])=>{const s=e[r]||r;return a[s]=o,a},n)}function l(t){return Object.keys(t)}exports.autoMapper=j;exports.filterIsTrue=f;exports.objToFormData=p;exports.objectKeys=l;exports.reverseObj=b;
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function c(e){const r=[];for(const t in e)e[t]&&r.push(Number(t.replace("_","")));return r}function i(e){const r={};return Object.entries(e).reduce((t,[n,u])=>({...t,[u]:n}),r)}function b(e,r){const t={};return Object.entries(e).reduce((n,[u,o])=>{const s=r[u]||u;return n[s]=o,n},t)}function f(e){return Object.keys(e)}exports.autoMapper=b;exports.filterIsTrue=c;exports.objectKeys=f;exports.reverseObj=i;

@@ -1,45 +0,26 @@

function i(t) {
const e = [];
for (const r in t)
t[r] && e.push(Number(r.replace("_", "")));
return e;
function s(e) {
const r = [];
for (const t in e)
e[t] && r.push(Number(t.replace("_", "")));
return r;
}
function p(t) {
const e = new FormData();
return ((c) => {
for (const [n, o] of Object.entries(c))
if (Array.isArray(o)) {
let s = 0;
for (const a of o) {
if (typeof a == "object")
for (const [f, u] of Object.entries(a))
e.append(`${n}[${s}][${f}]`, u);
else
e.append(`${n}[${s}]`, a);
s += 1;
}
} else
typeof o < "u" && o !== null && e.append(n, o);
})(t), e;
function i(e) {
const r = {};
return Object.entries(e).reduce((t, [n, u]) => ({ ...t, [u]: n }), r);
}
function b(t) {
const e = {};
return Object.entries(t).reduce((r, [c, n]) => ({ ...r, [n]: c }), e);
function f(e, r) {
const t = {};
return Object.entries(e).reduce((n, [u, c]) => {
const o = r[u] || u;
return n[o] = c, n;
}, t);
}
function j(t, e) {
const r = {};
return Object.entries(t).reduce((c, [n, o]) => {
const s = e[n] || n;
return c[s] = o, c;
}, r);
function b(e) {
return Object.keys(e);
}
function d(t) {
return Object.keys(t);
}
export {
j as autoMapper,
i as filterIsTrue,
p as objToFormData,
d as objectKeys,
b as reverseObj
f as autoMapper,
s as filterIsTrue,
b as objectKeys,
i as reverseObj
};

@@ -12,13 +12,2 @@ /**

/**
* 將物件資料轉成 FormData (最多兩層)
* ex: {
* profile: {name: 'jack'}
* }
*
* @param data
*/
export declare function objToFormData(data: {
[key: string]: any;
}): FormData;
/**
* 反轉物件

@@ -25,0 +14,0 @@ * ex: {'name': 'jack'} -> {jack: 'name'}

{
"name": "@acrool/js-utils",
"version": "3.2.9",
"version": "3.2.10-alpha.0",
"description": "Common javascript utils methods for project development",

@@ -13,3 +13,3 @@ "keywords": [

"type": "git",
"url": "https://github.com/acrool/js-utils.git"
"url": "https://github.com/acrool/acrool-js-utils.git"
},

@@ -16,0 +16,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc