@minsize/utils 0.0.6 → 0.0.8

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,7 @@ 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). |
32
+ | `generateUniqueKey` | Generates a unique key for an arbitrary JavaScript object using hashing |
30
33
 
package/index.d.ts CHANGED
@@ -82,6 +82,39 @@ 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
+
110
+ /**
111
+ * Генерирует уникальный ключ для произвольного JavaScript объекта, используя хеширование (без внешних библиотек).
112
+ *
113
+ * @param {any} obj Произвольный JavaScript объект (string, number, array, object, итд.).
114
+ * @returns {string} Строка, представляющая собой уникальный ключ (хеш) для переданного объекта.
115
+ */
116
+ declare const generateUniqueKey: <VALUE extends unknown>(obj: VALUE) => string;
117
+
85
118
  /**
86
119
  * @returns [r,g,b]
87
120
  */
@@ -96,4 +129,4 @@ declare const RGBtoHSV: (r: number, g: number, b: number) => [number, number, nu
96
129
 
97
130
  declare const HEXtoRGB: (hex: string) => [number, number, number];
98
131
 
99
- export { HEXtoRGB, HSVtoRGB, RGBtoHEX, RGBtoHSV, alignTo, chunks, clamp, copyText, createLinksFromText, decWord, formatNumber, isType, omit, pick, random, shuffle, sleep, timeAgo, toShort };
132
+ export { HEXtoRGB, HSVtoRGB, RGBtoHEX, RGBtoHSV, alignTo, chunks, clamp, comparison, copyText, createLinksFromText, decWord, formatNumber, generateUniqueKey, 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.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),o=parseInt(e.substring(4,6),16);return isNaN(t)||isNaN(r)||isNaN(o)||t<0||t>255||r<0||r>255||o<0||o>255?[0,0,0]:[t,r,o]},exports.HSVtoRGB=(e,t,r)=>{var o,n,a,s,c,i,u,l;switch(i=r*(1-t),u=r*(1-(c=6*e-(s=Math.floor(6*e)))*t),l=r*(1-(1-c)*t),s%6){case 0:o=r,n=l,a=i;break;case 1:o=u,n=r,a=i;break;case 2:o=i,n=r,a=l;break;case 3:o=i,n=u,a=r;break;case 4:o=l,n=i,a=r;break;case 5:o=r,n=i,a=u}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,i=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,i]},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,i,c,u,l;switch(c=r*(1-t),u=r*(1-(i=6*e-(s=Math.floor(6*e)))*t),l=r*(1-(1-i)*t),s%6){case 0:n=r,o=l,a=c;break;case 1:n=u,o=r,a=c;break;case 2:n=c,o=r,a=l;break;case 3:n=c,o=u,a=r;break;case 4:n=l,o=c,a=r;break;case 5:n=r,o=c,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,i=0===n?0:a/n,c=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,i,c]},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.generateUniqueKey=e=>{const t=e=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(t).join(",")+"]";if("object"==typeof e){const r=Object.keys(e).sort();let n="{";for(let o=0;o<r.length;o++){const a=r[o];n+=JSON.stringify(a)+":"+t(e[a]),o<r.length-1&&(n+=",")}return n+="}",n}return String(e)},r=e=>{let t=0;if(0===e.length)return t;for(let r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t};try{const n=t(e);return r(n).toString(16)}catch(t){return console.warn(`Object could not be fully stringified. Using a simple string conversion. Error: ${t}`),r(String(e)).toString(16)}},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,i=a/10**(3*s);return parseFloat(`${o?"-":""}${i%1?(Math.floor(10*i)/10).toFixed(r):i}`)+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),s=Math.log10(o)/3|0,c=o/10**(3*s);return parseFloat(`${a?"-":""}${c%1?(Math.floor(10*c)/10).toFixed(r):c}`)+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,"."),c=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 p=async e=>await new Promise((t=>setTimeout(t,e))),d=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},m=(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,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: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},g=(e,t,r)=>"#"+y(e)+y(t)+y(r),M=(e,t,r)=>{var n=Math.max(e,t,r),a=Math.min(e,t,r),o=n-a,s=0,c=0===n?0:o/n,u=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,c,u]},k=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{k as HEXtoRGB,b as HSVtoRGB,g as RGBtoHEX,M as RGBtoHSV,n as alignTo,e as chunks,t as clamp,d as copyText,m as createLinksFromText,r as decWord,s as formatNumber,f as isType,l as omit,h as pick,u as random,c as shuffle,p 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 o=(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,i=a/10**(3*s);return parseFloat(`${o?"-":""}${i%1?(Math.floor(10*i)/10).toFixed(r):i}`)+n[s]},a=e=>{if(!e)return"только что";const t=new Date(e),n=Math.floor((Date.now()-t.getTime())/1e3),o=()=>new Intl.DateTimeFormat("RU-ru",{day:"numeric",month:"short"}).format(t).replace(".",""),a=()=>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(`сегодня в ${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()} ${t.getFullYear()} г.`,"",Math.floor(n/31536e3))}return"только что"},s=e=>(e||0).toString().replace(/\B(?=(\d{3})+(?!\d))/g,"."),i=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),u={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 l(e,t){for(const[r,n]of Object.entries(u))if(n(e))return void 0!==t?r===t:r;return void 0===t&&"unknown"}function f(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))),g=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 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)))},b=(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],o=t[n];if(Array.isArray(r)&&Array.isArray(o)){if(r.length!==o.length)return!1;for(let e=0;e<r.length;e++)if(!b(r[e],o[e]))return!1}else if(!b(r,o))return!1}return!0},d=e=>{const t=e=>{if("string"==typeof e||"number"==typeof e||"boolean"==typeof e||null===e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(t).join(",")+"]";if("object"==typeof e){const r=Object.keys(e).sort();let n="{";for(let o=0;o<r.length;o++){const a=r[o];n+=JSON.stringify(a)+":"+t(e[a]),o<r.length-1&&(n+=",")}return n+="}",n}return String(e)},r=e=>{let t=0;if(0===e.length)return t;for(let r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t|=0}return t};try{const n=t(e);return r(n).toString(16)}catch(t){return console.warn(`Object could not be fully stringified. Using a simple string conversion. Error: ${t}`),r(String(e)).toString(16)}},m=(e,t,r)=>{var n,o,a,s,i,c,u,l;switch(c=r*(1-t),u=r*(1-(i=6*e-(s=Math.floor(6*e)))*t),l=r*(1-(1-i)*t),s%6){case 0:n=r,o=l,a=c;break;case 1:n=u,o=r,a=c;break;case 2:n=c,o=r,a=l;break;case 3:n=c,o=u,a=r;break;case 4:n=l,o=c,a=r;break;case 5:n=r,o=c,a=u}return[Math.round(255*n),Math.round(255*o),Math.round(255*a)]},M=e=>{const t=e.toString(16);return 1==t.length?"0"+t:t},k=(e,t,r)=>"#"+M(e)+M(t)+M(r),w=(e,t,r)=>{var n=Math.max(e,t,r),o=Math.min(e,t,r),a=n-o,s=0,i=0===n?0:a/n,c=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,i,c]},$=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{$ as HEXtoRGB,m as HSVtoRGB,k as RGBtoHEX,w as RGBtoHSV,n as alignTo,e as chunks,t as clamp,b as comparison,g as copyText,p as createLinksFromText,r as decWord,s as formatNumber,d as generateUniqueKey,l as isType,f as omit,h as pick,c as random,i as shuffle,y as sleep,a as timeAgo,o as toShort};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minsize/utils",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Frequently used utilities",
5
5
  "license": "MIT",
6
6
  "types": "index.ts",