@minsize/utils 0.0.4 → 0.0.6
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/index.d.ts +5 -3
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -85,13 +85,15 @@ declare const createLinksFromText: <T extends string, R extends unknown>(text: s
|
|
|
85
85
|
/**
|
|
86
86
|
* @returns [r,g,b]
|
|
87
87
|
*/
|
|
88
|
-
declare const HSVtoRGB: (h: number, s: number, v: number) => number
|
|
88
|
+
declare const HSVtoRGB: (h: number, s: number, v: number) => [number, number, number];
|
|
89
89
|
|
|
90
90
|
declare const RGBtoHEX: (r: number, g: number, b: number) => string;
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* @returns [h,s,v]
|
|
94
94
|
*/
|
|
95
|
-
declare const RGBtoHSV: (r: number, g: number, b: number) => number
|
|
95
|
+
declare const RGBtoHSV: (r: number, g: number, b: number) => [number, number, number];
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
declare const HEXtoRGB: (hex: string) => [number, number, number];
|
|
98
|
+
|
|
99
|
+
export { HEXtoRGB, HSVtoRGB, RGBtoHEX, RGBtoHSV, alignTo, chunks, clamp, 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,
|
|
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]};
|
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),
|
|
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};
|