@minsize/utils 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -27,4 +27,6 @@ yarn add @minsize/utils
27
27
  | `HSVtoRGB` | The function converts color from HSV color model (hue, saturation, brightness) to RGB color model (red, green, blue). |
28
28
  | `RGBtoHEX` | The function converts color from the RGB color model (red, green, blue) to hexadecimal format (HEX). |
29
29
  | `RGBtoHSV` | The function converts color from the RGB (red, green, blue) color model to the HSV (hue, saturation, brightness) color model. |
30
+ | `HEXtoRGB` | The function converts color from hexadecimal format (HEX) to the RGB color model (red, green, blue). |
31
+ | `comparison` | Compares two objects for deep equality, including arrays (order-sensitive). |
30
32
 
package/index.d.ts CHANGED
@@ -82,6 +82,31 @@ declare const copyText: (text?: string) => boolean;
82
82
 
83
83
  declare const createLinksFromText: <T extends string, R extends unknown>(text: string, callback: (key: T, value: string) => R) => (string | R)[];
84
84
 
85
+ /**
86
+ * Сравнивает два объекта на глубокое равенство, включая массивы (с учетом порядка).
87
+ *
88
+ * @example
89
+ * const obj1 = { a: 1, b: { c: 2 } };
90
+ * const obj2 = { a: 1, b: { c: 2 } };
91
+ * comparison(obj1, obj2); // return: true
92
+ *
93
+ * @example
94
+ * const obj3 = { a: 1, b: { c: 2 } };
95
+ * const obj4 = { a: 1, b: { c: 3 } };
96
+ * comparison(obj3, obj4); // return: false
97
+ *
98
+ * @example
99
+ * const arr1 = [1, 2, 3];
100
+ * const arr2 = [1, 2, 3];
101
+ * comparison({ arr: arr1 }, { arr: arr2 }); // return: true
102
+ *
103
+ * @example
104
+ * const arr3 = [1, 2, 3];
105
+ * const arr4 = [3, 2, 1];
106
+ * comparison({ arr: arr3 }, { arr: arr4 }); // return: false (порядок важен)
107
+ */
108
+ declare const comparison: <VALUE>(prev: VALUE, next: VALUE) => boolean;
109
+
85
110
  /**
86
111
  * @returns [r,g,b]
87
112
  */
@@ -94,4 +119,6 @@ declare const RGBtoHEX: (r: number, g: number, b: number) => string;
94
119
  */
95
120
  declare const RGBtoHSV: (r: number, g: number, b: number) => [number, number, number];
96
121
 
97
- export { HSVtoRGB, RGBtoHEX, RGBtoHSV, alignTo, chunks, clamp, copyText, createLinksFromText, decWord, formatNumber, isType, omit, pick, random, shuffle, sleep, timeAgo, toShort };
122
+ declare const HEXtoRGB: (hex: string) => [number, number, number];
123
+
124
+ export { HEXtoRGB, HSVtoRGB, RGBtoHEX, RGBtoHSV, alignTo, chunks, clamp, comparison, copyText, createLinksFromText, decWord, formatNumber, isType, omit, pick, random, shuffle, sleep, timeAgo, toShort };
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";const e=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];const t={date:e=>e instanceof Date,regexp:e=>e instanceof RegExp,error:e=>e instanceof Error,map:e=>e instanceof Map,set:e=>e instanceof Set,weakmap:e=>e instanceof WeakMap,weakset:e=>e instanceof WeakSet,promise:e=>e instanceof Promise,buffer:e=>e instanceof Buffer,undefined:e=>void 0===e,string:e=>"string"==typeof e,bigint:e=>"bigint"==typeof e,number:e=>"number"==typeof e&&!isNaN(e),nan:e=>"number"==typeof e&&isNaN(e),boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),object:e=>"object"==typeof e&&!Array.isArray(e)&&null!==e,function:e=>"function"==typeof e,null:e=>null===e,symbol:e=>"symbol"==typeof e,unknown:()=>!0};const r=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t};exports.HSVtoRGB=(e,t,r)=>{var o,n,a,s,c,u,i,f;switch(u=r*(1-t),i=r*(1-(c=6*e-(s=Math.floor(6*e)))*t),f=r*(1-(1-c)*t),s%6){case 0:o=r,n=f,a=u;break;case 1:o=i,n=r,a=u;break;case 2:o=u,n=r,a=f;break;case 3:o=u,n=i,a=r;break;case 4:o=f,n=u,a=r;break;case 5:o=r,n=u,a=i}return[Math.round(255*o),Math.round(255*n),Math.round(255*a)]},exports.RGBtoHEX=(e,t,o)=>"#"+r(e)+r(t)+r(o),exports.RGBtoHSV=(e,t,r)=>{var o=Math.max(e,t,r),n=Math.min(e,t,r),a=o-n,s=0,c=0===o?0:a/o,u=o/255;switch(o){case n:s=0;break;case e:s=t-r+a*(t<r?6:0),s/=6*a;break;case t:s=r-e+2*a,s/=6*a;break;case r:s=e-t+4*a,s/=6*a}return[s,c,u]},exports.alignTo=function(e,t){return e<=0?t:e+(t-e%t)%t},exports.chunks=(e,t)=>{const r=[];for(let o=0;o<t.length;o+=e)r.push(t.slice(o,o+e));return r},exports.clamp=(e,t,r)=>e>t?e<r?e:r:t,exports.copyText=e=>{if(!e)return!1;try{return navigator.clipboard?.writeText(e),!0}catch{}try{var t=document.createElement("input");return t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),!0}catch{}return!1},exports.createLinksFromText=(e,t)=>{const r=[],o=/{{([^}]+):([^}]+)}}/g;let n,a=0;for(;null!==(n=o.exec(e));)r.push(e.substring(a,n.index)),a=n.index+n[0].length,r.push({key:n[1],text:n[2]});return r.push(e.substring(a)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},exports.decWord=e,exports.formatNumber=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."),exports.isType=function(e,r){for(const[o,n]of Object.entries(t))if(n(e))return void 0!==r?o===r:o;return void 0===r&&"unknown"},exports.omit=function(e,t){return Object.keys(e).reduce(((r,o)=>(t.includes(o)||(r[o]=e[o]),r)),{})},exports.pick=function(e,t){return Object.keys(e).reduce(((r,o)=>(t.includes(o)&&(r[o]=e[o]),r)),{})},exports.random=(e,t)=>Math.floor(Math.random()*(t-e+1)+e),exports.shuffle=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},exports.sleep=async e=>await new Promise((t=>setTimeout(t,e))),exports.timeAgo=t=>{if(!t)return"только что";const r=new Date(t),o=Math.floor((Date.now()-r.getTime())/1e3),n=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(r).replace(".",""),a=()=>r.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),s=(t,r,o)=>Array.isArray(t)?`${o} ${e(o,t)} ${r}`:`${t} ${r}`;switch(!0){case o<0:return"скоро";case o<60:return s(["секунду","секунды","секунд"],"назад",o);case o<3600:return s(["минуту","минуты","минут"],"назад",Math.floor(o/60));case o<7200:return s("час","назад",Math.floor(o/3600));case o<10800:return s("два часа","назад",Math.floor(o/3600));case o<14400:return s("три часа","назад",Math.floor(o/3600));case o<86400:return s(`сегодня в ${a()}`,"",Math.floor(o/3600));case o<172800:return s(`вчера в ${a()}`,"",Math.floor(o/86400));case o<259200:return s("два дня","назад",Math.floor(o/86400));case o<345600:return s("три дня","назад",Math.floor(o/86400));case o<31536e3:return s(`${n()} в ${a()}`,"",Math.floor(o/86400));case o>=31536e3:return s(`${n()} ${r.getFullYear()} г.`,"",Math.floor(o/31536e3))}return"только что"},exports.toShort=(e,t,r=1)=>{const o=t||["","k","M","G","T","P"],n=e<0,a=Math.abs(e),s=Math.log10(a)/3|0,c=a/10**(3*s);return parseFloat(`${n?"-":""}${c%1?(Math.floor(10*c)/10).toFixed(r):c}`)+o[s]};
1
+ "use strict";const e=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];const t={date:e=>e instanceof Date,regexp:e=>e instanceof RegExp,error:e=>e instanceof Error,map:e=>e instanceof Map,set:e=>e instanceof Set,weakmap:e=>e instanceof WeakMap,weakset:e=>e instanceof WeakSet,promise:e=>e instanceof Promise,buffer:e=>e instanceof Buffer,undefined:e=>void 0===e,string:e=>"string"==typeof e,bigint:e=>"bigint"==typeof e,number:e=>"number"==typeof e&&!isNaN(e),nan:e=>"number"==typeof e&&isNaN(e),boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),object:e=>"object"==typeof e&&!Array.isArray(e)&&null!==e,function:e=>"function"==typeof e,null:e=>null===e,symbol:e=>"symbol"==typeof e,unknown:()=>!0};const r=(e,t)=>{if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return e===t;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o of n){if(!t.hasOwnProperty(o))return!1;const n=e[o],a=t[o];if(Array.isArray(n)&&Array.isArray(a)){if(n.length!==a.length)return!1;for(let e=0;e<n.length;e++)if(!r(n[e],a[e]))return!1}else if(!r(n,a))return!1}return!0},n=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t};exports.HEXtoRGB=e=>{if(3===(e=e.replace("#","")).length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return[0,0,0];const t=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return isNaN(t)||isNaN(r)||isNaN(n)||t<0||t>255||r<0||r>255||n<0||n>255?[0,0,0]:[t,r,n]},exports.HSVtoRGB=(e,t,r)=>{var n,o,a,s,c,i,u,f;switch(i=r*(1-t),u=r*(1-(c=6*e-(s=Math.floor(6*e)))*t),f=r*(1-(1-c)*t),s%6){case 0:n=r,o=f,a=i;break;case 1:n=u,o=r,a=i;break;case 2:n=i,o=r,a=f;break;case 3:n=i,o=u,a=r;break;case 4:n=f,o=i,a=r;break;case 5:n=r,o=i,a=u}return[Math.round(255*n),Math.round(255*o),Math.round(255*a)]},exports.RGBtoHEX=(e,t,r)=>"#"+n(e)+n(t)+n(r),exports.RGBtoHSV=(e,t,r)=>{var n=Math.max(e,t,r),o=Math.min(e,t,r),a=n-o,s=0,c=0===n?0:a/n,i=n/255;switch(n){case o:s=0;break;case e:s=t-r+a*(t<r?6:0),s/=6*a;break;case t:s=r-e+2*a,s/=6*a;break;case r:s=e-t+4*a,s/=6*a}return[s,c,i]},exports.alignTo=function(e,t){return e<=0?t:e+(t-e%t)%t},exports.chunks=(e,t)=>{const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},exports.clamp=(e,t,r)=>e>t?e<r?e:r:t,exports.comparison=r,exports.copyText=e=>{if(!e)return!1;try{return navigator.clipboard?.writeText(e),!0}catch{}try{var t=document.createElement("input");return t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),!0}catch{}return!1},exports.createLinksFromText=(e,t)=>{const r=[],n=/{{([^}]+):([^}]+)}}/g;let o,a=0;for(;null!==(o=n.exec(e));)r.push(e.substring(a,o.index)),a=o.index+o[0].length,r.push({key:o[1],text:o[2]});return r.push(e.substring(a)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},exports.decWord=e,exports.formatNumber=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."),exports.isType=function(e,r){for(const[n,o]of Object.entries(t))if(o(e))return void 0!==r?n===r:n;return void 0===r&&"unknown"},exports.omit=function(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)||(r[n]=e[n]),r)),{})},exports.pick=function(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)&&(r[n]=e[n]),r)),{})},exports.random=(e,t)=>Math.floor(Math.random()*(t-e+1)+e),exports.shuffle=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},exports.sleep=async e=>await new Promise((t=>setTimeout(t,e))),exports.timeAgo=t=>{if(!t)return"только что";const r=new Date(t),n=Math.floor((Date.now()-r.getTime())/1e3),o=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(r).replace(".",""),a=()=>r.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),s=(t,r,n)=>Array.isArray(t)?`${n} ${e(n,t)} ${r}`:`${t} ${r}`;switch(!0){case n<0:return"скоро";case n<60:return s(["секунду","секунды","секунд"],"назад",n);case n<3600:return s(["минуту","минуты","минут"],"назад",Math.floor(n/60));case n<7200:return s("час","назад",Math.floor(n/3600));case n<10800:return s("два часа","назад",Math.floor(n/3600));case n<14400:return s("три часа","назад",Math.floor(n/3600));case n<86400:return s(`сегодня в ${a()}`,"",Math.floor(n/3600));case n<172800:return s(`вчера в ${a()}`,"",Math.floor(n/86400));case n<259200:return s("два дня","назад",Math.floor(n/86400));case n<345600:return s("три дня","назад",Math.floor(n/86400));case n<31536e3:return s(`${o()} в ${a()}`,"",Math.floor(n/86400));case n>=31536e3:return s(`${o()} ${r.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},exports.toShort=(e,t,r=1)=>{const n=t||["","k","M","G","T","P"],o=e<0,a=Math.abs(e),s=Math.log10(a)/3|0,c=a/10**(3*s);return parseFloat(`${o?"-":""}${c%1?(Math.floor(10*c)/10).toFixed(r):c}`)+n[s]};
package/index.mjs CHANGED
@@ -1 +1 @@
1
- const e=(e,t)=>{const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},t=(e,t,r)=>e>t?e<r?e:r:t,r=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];function n(e,t){return e<=0?t:e+(t-e%t)%t}const a=(e,t,r=1)=>{const n=t||["","k","M","G","T","P"],a=e<0,o=Math.abs(e),c=Math.log10(o)/3|0,s=o/10**(3*c);return parseFloat(`${a?"-":""}${s%1?(Math.floor(10*s)/10).toFixed(r):s}`)+n[c]},o=e=>{if(!e)return"только что";const t=new Date(e),n=Math.floor((Date.now()-t.getTime())/1e3),a=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(t).replace(".",""),o=()=>t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),c=(e,t,n)=>Array.isArray(e)?`${n} ${r(n,e)} ${t}`:`${e} ${t}`;switch(!0){case n<0:return"скоро";case n<60:return c(["секунду","секунды","секунд"],"назад",n);case n<3600:return c(["минуту","минуты","минут"],"назад",Math.floor(n/60));case n<7200:return c("час","назад",Math.floor(n/3600));case n<10800:return c("два часа","назад",Math.floor(n/3600));case n<14400:return c("три часа","назад",Math.floor(n/3600));case n<86400:return c(`сегодня в ${o()}`,"",Math.floor(n/3600));case n<172800:return c(`вчера в ${o()}`,"",Math.floor(n/86400));case n<259200:return c("два дня","назад",Math.floor(n/86400));case n<345600:return c("три дня","назад",Math.floor(n/86400));case n<31536e3:return c(`${a()} в ${o()}`,"",Math.floor(n/86400));case n>=31536e3:return c(`${a()} ${t.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},c=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."),s=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},u=(e,t)=>Math.floor(Math.random()*(t-e+1)+e),i={date:e=>e instanceof Date,regexp:e=>e instanceof RegExp,error:e=>e instanceof Error,map:e=>e instanceof Map,set:e=>e instanceof Set,weakmap:e=>e instanceof WeakMap,weakset:e=>e instanceof WeakSet,promise:e=>e instanceof Promise,buffer:e=>e instanceof Buffer,undefined:e=>void 0===e,string:e=>"string"==typeof e,bigint:e=>"bigint"==typeof e,number:e=>"number"==typeof e&&!isNaN(e),nan:e=>"number"==typeof e&&isNaN(e),boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),object:e=>"object"==typeof e&&!Array.isArray(e)&&null!==e,function:e=>"function"==typeof e,null:e=>null===e,symbol:e=>"symbol"==typeof e,unknown:()=>!0};function f(e,t){for(const[r,n]of Object.entries(i))if(n(e))return void 0!==t?r===t:r;return void 0===t&&"unknown"}function l(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)||(r[n]=e[n]),r)),{})}function h(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)&&(r[n]=e[n]),r)),{})}const d=async e=>await new Promise((t=>setTimeout(t,e))),m=e=>{if(!e)return!1;try{return navigator.clipboard?.writeText(e),!0}catch{}try{var t=document.createElement("input");return t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),!0}catch{}return!1},p=(e,t)=>{const r=[],n=/{{([^}]+):([^}]+)}}/g;let a,o=0;for(;null!==(a=n.exec(e));)r.push(e.substring(o,a.index)),o=a.index+a[0].length,r.push({key:a[1],text:a[2]});return r.push(e.substring(o)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},b=(e,t,r)=>{var n,a,o,c,s,u,i,f;switch(u=r*(1-t),i=r*(1-(s=6*e-(c=Math.floor(6*e)))*t),f=r*(1-(1-s)*t),c%6){case 0:n=r,a=f,o=u;break;case 1:n=i,a=r,o=u;break;case 2:n=u,a=r,o=f;break;case 3:n=u,a=i,o=r;break;case 4:n=f,a=u,o=r;break;case 5:n=r,a=u,o=i}return[Math.round(255*n),Math.round(255*a),Math.round(255*o)]},y=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t},M=(e,t,r)=>"#"+y(e)+y(t)+y(r),g=(e,t,r)=>{var n=Math.max(e,t,r),a=Math.min(e,t,r),o=n-a,c=0,s=0===n?0:o/n,u=n/255;switch(n){case a:c=0;break;case e:c=t-r+o*(t<r?6:0),c/=6*o;break;case t:c=r-e+2*o,c/=6*o;break;case r:c=e-t+4*o,c/=6*o}return[c,s,u]};export{b as HSVtoRGB,M as RGBtoHEX,g as RGBtoHSV,n as alignTo,e as chunks,t as clamp,m as copyText,p as createLinksFromText,r as decWord,c as formatNumber,f as isType,l as omit,h as pick,u as random,s as shuffle,d as sleep,o as timeAgo,a as toShort};
1
+ const e=(e,t)=>{const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r},t=(e,t,r)=>e>t?e<r?e:r:t,r=(e,t)=>t[e%10==1&&e%100!=11?0:e%10>=2&&e%10<=4&&(e%100<10||e%100>=20)?1:2];function n(e,t){return e<=0?t:e+(t-e%t)%t}const a=(e,t,r=1)=>{const n=t||["","k","M","G","T","P"],a=e<0,o=Math.abs(e),s=Math.log10(o)/3|0,u=o/10**(3*s);return parseFloat(`${a?"-":""}${u%1?(Math.floor(10*u)/10).toFixed(r):u}`)+n[s]},o=e=>{if(!e)return"только что";const t=new Date(e),n=Math.floor((Date.now()-t.getTime())/1e3),a=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(t).replace(".",""),o=()=>t.toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}),s=(e,t,n)=>Array.isArray(e)?`${n} ${r(n,e)} ${t}`:`${e} ${t}`;switch(!0){case n<0:return"скоро";case n<60:return s(["секунду","секунды","секунд"],"назад",n);case n<3600:return s(["минуту","минуты","минут"],"назад",Math.floor(n/60));case n<7200:return s("час","назад",Math.floor(n/3600));case n<10800:return s("два часа","назад",Math.floor(n/3600));case n<14400:return s("три часа","назад",Math.floor(n/3600));case n<86400:return s(`сегодня в ${o()}`,"",Math.floor(n/3600));case n<172800:return s(`вчера в ${o()}`,"",Math.floor(n/86400));case n<259200:return s("два дня","назад",Math.floor(n/86400));case n<345600:return s("три дня","назад",Math.floor(n/86400));case n<31536e3:return s(`${a()} в ${o()}`,"",Math.floor(n/86400));case n>=31536e3:return s(`${a()} ${t.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},s=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."),u=e=>{for(let t=e.length-1;t>0;t--){const r=Math.floor(Math.random()*(t+1));[e[t],e[r]]=[e[r],e[t]]}return e},c=(e,t)=>Math.floor(Math.random()*(t-e+1)+e),i={date:e=>e instanceof Date,regexp:e=>e instanceof RegExp,error:e=>e instanceof Error,map:e=>e instanceof Map,set:e=>e instanceof Set,weakmap:e=>e instanceof WeakMap,weakset:e=>e instanceof WeakSet,promise:e=>e instanceof Promise,buffer:e=>e instanceof Buffer,undefined:e=>void 0===e,string:e=>"string"==typeof e,bigint:e=>"bigint"==typeof e,number:e=>"number"==typeof e&&!isNaN(e),nan:e=>"number"==typeof e&&isNaN(e),boolean:e=>"boolean"==typeof e,array:e=>Array.isArray(e),object:e=>"object"==typeof e&&!Array.isArray(e)&&null!==e,function:e=>"function"==typeof e,null:e=>null===e,symbol:e=>"symbol"==typeof e,unknown:()=>!0};function f(e,t){for(const[r,n]of Object.entries(i))if(n(e))return void 0!==t?r===t:r;return void 0===t&&"unknown"}function l(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)||(r[n]=e[n]),r)),{})}function h(e,t){return Object.keys(e).reduce(((r,n)=>(t.includes(n)&&(r[n]=e[n]),r)),{})}const y=async e=>await new Promise((t=>setTimeout(t,e))),p=e=>{if(!e)return!1;try{return navigator.clipboard?.writeText(e),!0}catch{}try{var t=document.createElement("input");return t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),!0}catch{}return!1},b=(e,t)=>{const r=[],n=/{{([^}]+):([^}]+)}}/g;let a,o=0;for(;null!==(a=n.exec(e));)r.push(e.substring(o,a.index)),o=a.index+a[0].length,r.push({key:a[1],text:a[2]});return r.push(e.substring(o)),r.map((e=>"string"==typeof e?e:t(e.key,e.text)))},d=(e,t)=>{if(e===t)return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return e===t;const r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let n of r){if(!t.hasOwnProperty(n))return!1;const r=e[n],a=t[n];if(Array.isArray(r)&&Array.isArray(a)){if(r.length!==a.length)return!1;for(let e=0;e<r.length;e++)if(!d(r[e],a[e]))return!1}else if(!d(r,a))return!1}return!0},g=(e,t,r)=>{var n,a,o,s,u,c,i,f;switch(c=r*(1-t),i=r*(1-(u=6*e-(s=Math.floor(6*e)))*t),f=r*(1-(1-u)*t),s%6){case 0:n=r,a=f,o=c;break;case 1:n=i,a=r,o=c;break;case 2:n=c,a=r,o=f;break;case 3:n=c,a=i,o=r;break;case 4:n=f,a=c,o=r;break;case 5:n=r,a=c,o=i}return[Math.round(255*n),Math.round(255*a),Math.round(255*o)]},m=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t},M=(e,t,r)=>"#"+m(e)+m(t)+m(r),k=(e,t,r)=>{var n=Math.max(e,t,r),a=Math.min(e,t,r),o=n-a,s=0,u=0===n?0:o/n,c=n/255;switch(n){case a:s=0;break;case e:s=t-r+o*(t<r?6:0),s/=6*o;break;case t:s=r-e+2*o,s/=6*o;break;case r:s=e-t+4*o,s/=6*o}return[s,u,c]},w=e=>{if(3===(e=e.replace("#","")).length&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),6!==e.length)return[0,0,0];const t=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),n=parseInt(e.substring(4,6),16);return isNaN(t)||isNaN(r)||isNaN(n)||t<0||t>255||r<0||r>255||n<0||n>255?[0,0,0]:[t,r,n]};export{w as HEXtoRGB,g as HSVtoRGB,M as RGBtoHEX,k as RGBtoHSV,n as alignTo,e as chunks,t as clamp,d as comparison,p as copyText,b as createLinksFromText,r as decWord,s as formatNumber,f as isType,l as omit,h as pick,c as random,u as shuffle,y as sleep,o as timeAgo,a as toShort};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minsize/utils",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Frequently used utilities",
5
5
  "license": "MIT",
6
6
  "types": "index.ts",