@mediacubeco/base 2.1.0 → 2.1.2
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/dist/index.cjs +1 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.mjs +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.ts +29 -1
- package/dist/utils/index.mjs +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),r=t=>"string"==typeof t,i=t=>"object"==typeof t,o=t=>{const e=[n,a,c,u,l,f,p,h,g,m,d].some(e=>e(t));return!!t&&"object"==typeof t&&!e},n=t=>Array.isArray(t),a=t=>t instanceof ArrayBuffer,c=t=>t instanceof Map,u=t=>t instanceof Set,l=t=>t instanceof Map,f=t=>t instanceof Set,p=t=>t instanceof Date,h=t=>t instanceof Error,g=t=>t instanceof RegExp,m=t=>t instanceof Promise,d=t=>t instanceof Function;const x=(t,...e)=>{if(d(t))return t(...e)};function y(t,e){return!(!i(e)||!(t in e))}function b(t,e){return t.filter(t=>e.includes(t))}const E=()=>{let t=0;return(e="")=>`${e}${++t}`},v=E();class w{isDefaultPrevented=!1;constructor(){this.preventDefault=this.preventDefault.bind(this),this.overrideDefault=this.overrideDefault.bind(this)}preventDefault(){this.isDefaultPrevented=!0}overrideDefault(){this.isDefaultPrevented=!1}}class D{subscriptions={};constructor(){this.emit=this.emit.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.clear=this.clear.bind(this)}emit(t,e,s){const r=this.subscriptions[t];if(r){const{event:t,listenerList:i}=r;i.forEach(s=>x(s,Object.assign(t,e))),t.isDefaultPrevented||x(s)}else x(s)}on(t,e){const s=this.subscriptions[t];return s?s.listenerList.push(e):this.subscriptions[t]={event:new w,listenerList:[e]},()=>this.off(t,e)}off(t,e){const s=this.subscriptions[t];if(s){const{event:r,listenerList:i}=s;this.subscriptions[t]={event:r,listenerList:i.filter(t=>t!==e)},r.overrideDefault()}}clear(t){delete this.subscriptions[t]}}const N=(t="?",...e)=>[`[${(t&&r(t)?t:"?").toUpperCase()}]`,...e.reduce((t,e,s,{length:r})=>{const i=s===r-1?[]:["|"];return t.push(e,...i),t},e.length?["-"]:[])];var k,S,L;!function(t){t.StartGroup="group",t.EndGroup="groupEnd",t.Default="log"}(k||(k={})),function(t){t.Info="[36m%s[0m",t.Success="[32m%s[0m",t.Warning="[33m%s[0m",t.Danger="[31m%s[0m"}(S||(S={}));class j{static formatted={info:(...t)=>j.info(...N(...t)),success:(...t)=>j.success(...N(...t)),warning:(...t)=>j.warning(...N(...t)),danger:(...t)=>j.danger(...N(...t))};static#t(t,...e){console[t](...e)}static startGroup(t,e,...s){j.#t(k.StartGroup,...((t,...e)=>["%c%s",t,...e])(`font-size: 16px;${e}`,...N(t,...s)))}static endGroup(){j.#t(k.EndGroup)}static info(...t){j.#t(k.Default,S.Info,...t)}static success(...t){j.#t(k.Default,S.Success,...t)}static warning(...t){j.#t(k.Default,S.Warning,...t)}static danger(...t){j.#t(k.Default,S.Danger,...t)}}exports.ErrorHandlerEventName=void 0,(L=exports.ErrorHandlerEventName||(exports.ErrorHandlerEventName={})).Capture="capture",L.Forward="forward";class O{static eventEmitter=new D;static caseList=[];static log(t,e={signal:"unknown"}){const{signal:s,message:r,payload:i,stack:o}=e,n=[r,h(t)?t.message:void 0].filter(Boolean);j.formatted.danger(s,...n,{error:t,payload:i,stack:o})}static get on(){return O.eventEmitter.on}static get off(){return O.eventEmitter.off}static get clear(){return O.eventEmitter.clear}static create(t,e){return new Error(t,{cause:e})}static throw(t,e){throw O.create(t,e)}static capture(t,e){O.log(t,e),O.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e})}static forward(t,e){throw O.log(t,e),O.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e}),t}static case(t){O.caseList.push(t)}static parse(t){const e={message:"Error!",status:0,errors:{},isExternal:!0};for(const{check:s,parse:r}of O.caseList)if(s(t,e))return r(t,e);return!0===h(t)?{message:t.message,status:e.status,errors:e.errors,isExternal:e.isExternal}:{message:e.message,status:e.status,errors:e.errors,isExternal:e.isExternal}}}class P{key;model;config;constructor(t,e,s){this.key=t,this.model=e,this.config=s}async get(t){const{defaultValue:e,withDebug:s}={...this.config,...t},r=await this.model.get(this.key),i=r&&JSON.parse(r)||e;return s&&j.formatted.info("get",this.key,i),i}async set(t,e){const{withDebug:s}={...this.config,...e};await this.model.set(this.key,JSON.stringify(t)),s&&j.formatted.info("set",this.key,t)}async delete(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});await this.model.delete(this.key),e&&j.formatted.info("delete",this.key,s)}async has(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});return e&&j.formatted.info("has",this.key,s),!!s}}exports.ErrorHandler=O,exports.EventEmitter=D,exports.Log=j,exports.Storage=class{model;config;constructor(t,e){this.model=t,this.config=e}async all(){O.throw("Not implemented")}async clear(){O.throw("Not implemented")}create(t){const e={[t]:new P(t,this.model,this.config)};return Object.assign(this,e)}},exports.chunkList=function(t,e){const s=[];for(let r=0;r<t.length;r+=e)s.push(t.slice(r,r+e));return s},exports.compose=function(t,e,r){const i=!o(t);return!s(r)&&{...e,...i?{[r]:t}:t}||!s(e)&&{...e,...t}||{...t}},exports.debounce=(t,e)=>{let s;return(...r)=>{s&&clearTimeout(s),s=setTimeout(()=>x(t,...r),e)}},exports.filterByKey=function(t,e="isVisible"){return t.filter(t=>!y(e,t)||t[e])},exports.filterDuplicateByKey=function(t,e){return t.reduce((t,s)=>t.some(t=>t[e]===s[e])?t:[...t,s],[])},exports.filterEqualValues=b,exports.filterNullableValues=function(t){return t.filter(t=>!s(t))},exports.forceList=function(t){return n(t)?t:[t]},exports.generateId=v,exports.generateIdFactory=E,exports.getValueByKey=function(t,e,r){return s(t)?r:2===arguments.length?e[t]:e[t]??r},exports.hasEqualValues=function(t,e){return!!b(t,e).length},exports.hasKey=y,exports.isAnyObject=i,exports.isArray=n,exports.isArrayBuffer=a,exports.isArrayEmpty=function(t){return 0===t.length},exports.isBigint=t=>"bigint"==typeof t,exports.isBoolean=t=>"boolean"==typeof t,exports.isDate=p,exports.isError=h,exports.isFunction=d,exports.isMap=c,exports.isNaN=t=>Number.isNaN(t),exports.isNull=e,exports.isNullable=s,exports.isNumber=t=>"number"==typeof t,exports.isObject=o,exports.isObjectEmpty=function(t){for(const e in t)return!1;return!0},exports.isPromise=m,exports.isProxy=t=>t instanceof Proxy,exports.isRegExp=g,exports.isSet=u,exports.isString=r,exports.isSymbol=t=>"symbol"==typeof t,exports.isUndefined=t,exports.isWeakMap=l,exports.isWeakSet=f,exports.mapRecord=(t,e)=>{const s=Object.entries(t);return Object.fromEntries(s.map(([t,s],r,i)=>[t,e(t,s,r,i)]))},exports.runCallback=x,exports.throttle=(t,e)=>{let s=!0;return(...r)=>{s&&(x(t,...r),s=!1),setTimeout(()=>s=!0,e)}},exports.wait=(t=0)=>new Promise(e=>setTimeout(e,t));
|
|
1
|
+
"use strict";const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),r=t=>"string"==typeof t,i=t=>"object"==typeof t,o=t=>{const e=[n,a,c,u,l,f,p,h,g,m,d].some(e=>e(t));return!!t&&"object"==typeof t&&!e},n=t=>Array.isArray(t),a=t=>t instanceof ArrayBuffer,c=t=>t instanceof Map,u=t=>t instanceof Set,l=t=>t instanceof Map,f=t=>t instanceof Set,p=t=>t instanceof Date,h=t=>t instanceof Error,g=t=>t instanceof RegExp,m=t=>t instanceof Promise,d=t=>t instanceof Function;const x=(t,...e)=>{if(d(t))return t(...e)};function y(t,e){return!(!i(e)||!(t in e))}function b(t,e){return t.filter(t=>e.includes(t))}const E=()=>{let t=0;return(e="")=>`${e}${++t}`},v=E();class w{isDefaultPrevented=!1;constructor(){this.preventDefault=this.preventDefault.bind(this),this.overrideDefault=this.overrideDefault.bind(this)}preventDefault(){this.isDefaultPrevented=!0}overrideDefault(){this.isDefaultPrevented=!1}}class D{subscriptions={};constructor(){this.emit=this.emit.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.clear=this.clear.bind(this)}emit(t,e,s){const r=this.subscriptions[t];if(r){const{event:t,listenerList:i}=r;i.forEach(s=>x(s,Object.assign(t,e))),t.isDefaultPrevented||x(s)}else x(s)}on(t,e){const s=this.subscriptions[t];return s?s.listenerList.push(e):this.subscriptions[t]={event:new w,listenerList:[e]},()=>this.off(t,e)}off(t,e){const s=this.subscriptions[t];if(s){const{event:r,listenerList:i}=s;this.subscriptions[t]={event:r,listenerList:i.filter(t=>t!==e)},r.overrideDefault()}}clear(t){delete this.subscriptions[t]}}const N=(t="?",...e)=>[`[${(t&&r(t)?t:"?").toUpperCase()}]`,...e.reduce((t,e,s,{length:r})=>{const i=s===r-1?[]:["|"];return t.push(e,...i),t},e.length?["-"]:[])];var k,S,L;!function(t){t.StartGroup="group",t.EndGroup="groupEnd",t.Default="log"}(k||(k={})),function(t){t.Info="[36m%s[0m",t.Success="[32m%s[0m",t.Warning="[33m%s[0m",t.Danger="[31m%s[0m"}(S||(S={}));class j{static formatted={info:(...t)=>j.info(...N(...t)),success:(...t)=>j.success(...N(...t)),warning:(...t)=>j.warning(...N(...t)),danger:(...t)=>j.danger(...N(...t))};static#t(t,...e){console[t](...e)}static startGroup(t,e,...s){j.#t(k.StartGroup,...((t,...e)=>["%c%s",t,...e])(`font-size: 16px;${e}`,...N(t,...s)))}static endGroup(){j.#t(k.EndGroup)}static info(...t){j.#t(k.Default,S.Info,...t)}static success(...t){j.#t(k.Default,S.Success,...t)}static warning(...t){j.#t(k.Default,S.Warning,...t)}static danger(...t){j.#t(k.Default,S.Danger,...t)}}exports.ErrorHandlerEventName=void 0,(L=exports.ErrorHandlerEventName||(exports.ErrorHandlerEventName={})).Capture="capture",L.Forward="forward";class O{static eventEmitter=new D;static caseList=[];static log(t,e={signal:"unknown"}){const{signal:s,message:r,payload:i,stack:o}=e,n=[r,h(t)?t.message:void 0].filter(Boolean);j.formatted.danger(s,...n,{error:t,payload:i,stack:o})}static get on(){return O.eventEmitter.on}static get off(){return O.eventEmitter.off}static get clear(){return O.eventEmitter.clear}static create(t,e){return new Error(t,{cause:e})}static throw(t,e){throw O.create(t,e)}static capture(t,e){O.log(t,e),O.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e})}static forward(t,e){throw O.log(t,e),O.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e}),t}static case(t){O.caseList.push(t)}static parse(t){const e={message:"Error!",status:0,errors:{},isExternal:!0};for(const{check:s,parse:r}of O.caseList)if(s(t,e))return r(t,e);return!0===h(t)?{message:t.message,status:e.status,errors:e.errors,isExternal:e.isExternal}:{message:e.message,status:e.status,errors:e.errors,isExternal:e.isExternal}}}class P{key;model;config;constructor(t,e,s){this.key=t,this.model=e,this.config=s}async get(t){const{defaultValue:e,withDebug:s}={...this.config,...t},r=await this.model.get(this.key),i=r&&JSON.parse(r)||e;return s&&j.formatted.info("get",this.key,i),i}async set(t,e){const{withDebug:s}={...this.config,...e};await this.model.set(this.key,JSON.stringify(t)),s&&j.formatted.info("set",this.key,t)}async delete(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});await this.model.delete(this.key),e&&j.formatted.info("delete",this.key,s)}async has(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});return e&&j.formatted.info("has",this.key,s),!!s}}exports.ErrorHandler=O,exports.EventEmitter=D,exports.Log=j,exports.Storage=class{model;config;constructor(t,e){this.model=t,this.config=e}async all(){O.throw("Not implemented")}async clear(){O.throw("Not implemented")}create(t){const e={[t]:new P(t,this.model,this.config)};return Object.assign(this,e)}},exports.chunkList=function(t,e){const s=[];for(let r=0;r<t.length;r+=e)s.push(t.slice(r,r+e));return s},exports.clamp=(t,e,s)=>Math.min(s,Math.max(e,t)),exports.compose=function(t,e,r){const i=!o(t);return!s(r)&&{...e,...i?{[r]:t}:t}||!s(e)&&{...e,...t}||{...t}},exports.debounce=(t,e)=>{let s;return(...r)=>{s&&clearTimeout(s),s=setTimeout(()=>x(t,...r),e)}},exports.filterByKey=function(t,e="isVisible"){return t.filter(t=>!y(e,t)||t[e])},exports.filterDuplicateByKey=function(t,e){return t.reduce((t,s)=>t.some(t=>t[e]===s[e])?t:[...t,s],[])},exports.filterEqualValues=b,exports.filterNullableValues=function(t){return t.filter(t=>!s(t))},exports.forceList=function(t){return n(t)?t:[t]},exports.generateId=v,exports.generateIdFactory=E,exports.getValueByKey=function(t,e,r){return s(t)?r:2===arguments.length?e[t]:e[t]??r},exports.hasEqualValues=function(t,e){return!!b(t,e).length},exports.hasKey=y,exports.isAnyObject=i,exports.isArray=n,exports.isArrayBuffer=a,exports.isArrayEmpty=function(t){return 0===t.length},exports.isBigint=t=>"bigint"==typeof t,exports.isBoolean=t=>"boolean"==typeof t,exports.isDate=p,exports.isError=h,exports.isFunction=d,exports.isMap=c,exports.isNaN=t=>Number.isNaN(t),exports.isNull=e,exports.isNullable=s,exports.isNumber=t=>"number"==typeof t,exports.isObject=o,exports.isObjectEmpty=function(t){for(const e in t)return!1;return!0},exports.isPromise=m,exports.isProxy=t=>t instanceof Proxy,exports.isRegExp=g,exports.isSet=u,exports.isString=r,exports.isSymbol=t=>"symbol"==typeof t,exports.isUndefined=t,exports.isWeakMap=l,exports.isWeakSet=f,exports.mapRecord=(t,e)=>{const s=Object.entries(t);return Object.fromEntries(s.map(([t,s],r,i)=>[t,e(t,s,r,i)]))},exports.runCallback=x,exports.sleep=(t=0)=>{},exports.throttle=(t,e)=>{let s=!0;return(...r)=>{s&&(x(t,...r),s=!1),setTimeout(()=>s=!0,e)}},exports.wait=(t=0)=>new Promise(e=>setTimeout(e,t));
|
package/dist/index.d.ts
CHANGED
|
@@ -763,6 +763,34 @@ declare class Storage {
|
|
|
763
763
|
* ```
|
|
764
764
|
*/
|
|
765
765
|
declare const wait: (delay?: number) => Promise<unknown>;
|
|
766
|
+
/**
|
|
767
|
+
* Засыпает на указанное количество миллисекунд.
|
|
768
|
+
*
|
|
769
|
+
* @param delay - Длительность ожидания в миллисекундах
|
|
770
|
+
* @returns void
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* ```typescript
|
|
774
|
+
* sleep(300)
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
declare const sleep: (delay?: number) => void;
|
|
778
|
+
/**
|
|
779
|
+
* Ограничивает значение числом в заданном диапазоне.
|
|
780
|
+
*
|
|
781
|
+
* @param value - Значение
|
|
782
|
+
* @param min - Минимальное значение
|
|
783
|
+
* @param max - Максимальное значение
|
|
784
|
+
* @returns Ограниченное значение
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```typescript
|
|
788
|
+
* clamp(10, 0, 100) // 10
|
|
789
|
+
* clamp(100, 0, 100) // 100
|
|
790
|
+
* clamp(50, 0, 100) // 50
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
declare const clamp: (value: number, min: number, max: number) => number;
|
|
766
794
|
/**
|
|
767
795
|
* Собирает объект из переданного значения и опционального исходного объекта.
|
|
768
796
|
* Поддерживает три сценария: вернуть объект как есть, слить два объекта или записать примитив по ключу.
|
|
@@ -1242,5 +1270,5 @@ declare const isPromise: (param: unknown) => param is Promise<typeof param>;
|
|
|
1242
1270
|
*/
|
|
1243
1271
|
declare const isFunction: <Callback = <ParamList extends BaseList, Result>(...paramList: ParamList) => Result>(param: unknown) => param is Callback;
|
|
1244
1272
|
|
|
1245
|
-
export { ErrorHandler, ErrorHandlerEventName, EventEmitter, Log, Storage, chunkList, compose, debounce, filterByKey, filterDuplicateByKey, filterEqualValues, filterNullableValues, forceList, generateId, generateIdFactory, getValueByKey, hasEqualValues, hasKey, isAnyObject, isArray, isArrayBuffer, isArrayEmpty, isBigint, isBoolean, isDate, isError, isFunction, isMap, isNaN, isNull, isNullable, isNumber, isObject, isObjectEmpty, isPromise, isProxy, isRegExp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, mapRecord, runCallback, throttle, wait };
|
|
1273
|
+
export { ErrorHandler, ErrorHandlerEventName, EventEmitter, Log, Storage, chunkList, clamp, compose, debounce, filterByKey, filterDuplicateByKey, filterEqualValues, filterNullableValues, forceList, generateId, generateIdFactory, getValueByKey, hasEqualValues, hasKey, isAnyObject, isArray, isArrayBuffer, isArrayEmpty, isBigint, isBoolean, isDate, isError, isFunction, isMap, isNaN, isNull, isNullable, isNumber, isObject, isObjectEmpty, isPromise, isProxy, isRegExp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, mapRecord, runCallback, sleep, throttle, wait };
|
|
1246
1274
|
export type { AnyAsyncCallback, AnyCallback, AsyncCallback, BaseKey, BaseList, BaseRecord, Callback, CallbackParamList, CallbackResult, Decrement, Divide, Entry, ErrorHandlerCaseConfig, ErrorHandlerConfig, ErrorHandlerError, ErrorHandlerErrors, ErrorHandlerEventParams, ErrorHandlerMessage, ErrorHandlerParseResult, Filled, Include, Increment, IterableOf, KeyOf, LevelRange, List, MaybeAsync, Noop, NotNullable, Nothing, Nullable, Numerable, Shared, SizeRange, StorageConfig, StorageInstance, StorageModel, ValueOf };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),n=t=>"string"==typeof t,i=t=>"number"==typeof t,r=t=>"bigint"==typeof t,o=t=>Number.isNaN(t),a=t=>"boolean"==typeof t,c=t=>"symbol"==typeof t,u=t=>"object"==typeof t,f=t=>{const e=[l,h,g,m,d,p,b,y,D,v,E].some(e=>e(t));return!!t&&"object"==typeof t&&!e},l=t=>Array.isArray(t),h=t=>t instanceof ArrayBuffer,g=t=>t instanceof Map,m=t=>t instanceof Set,d=t=>t instanceof Map,p=t=>t instanceof Set,b=t=>t instanceof Date,y=t=>t instanceof Error,w=t=>t instanceof Proxy,D=t=>t instanceof RegExp,v=t=>t instanceof Promise,E=t=>t instanceof Function,k=(t=0)=>new Promise(e=>setTimeout(e,t));function
|
|
1
|
+
const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),n=t=>"string"==typeof t,i=t=>"number"==typeof t,r=t=>"bigint"==typeof t,o=t=>Number.isNaN(t),a=t=>"boolean"==typeof t,c=t=>"symbol"==typeof t,u=t=>"object"==typeof t,f=t=>{const e=[l,h,g,m,d,p,b,y,D,v,E].some(e=>e(t));return!!t&&"object"==typeof t&&!e},l=t=>Array.isArray(t),h=t=>t instanceof ArrayBuffer,g=t=>t instanceof Map,m=t=>t instanceof Set,d=t=>t instanceof Map,p=t=>t instanceof Set,b=t=>t instanceof Date,y=t=>t instanceof Error,w=t=>t instanceof Proxy,D=t=>t instanceof RegExp,v=t=>t instanceof Promise,E=t=>t instanceof Function,k=(t=0)=>new Promise(e=>setTimeout(e,t)),x=(t=0)=>{},L=(t,e,s)=>Math.min(s,Math.max(e,t));function S(t,e,n){const i=!f(t);return!s(n)&&{...e,...i?{[n]:t}:t}||!s(e)&&{...e,...t}||{...t}}function N(t,e,n){return s(t)?n:2===arguments.length?e[t]:e[t]??n}const P=(t,e)=>{const s=Object.entries(t);return Object.fromEntries(s.map(([t,s],n,i)=>[t,e(t,s,n,i)]))},j=(t,...e)=>{if(E(t))return t(...e)},G=(t,e)=>{let s;return(...n)=>{s&&clearTimeout(s),s=setTimeout(()=>j(t,...n),e)}},O=(t,e)=>{let s=!0;return(...n)=>{s&&(j(t,...n),s=!1),setTimeout(()=>s=!0,e)}};function C(t){for(const e in t)return!1;return!0}function M(t){return 0===t.length}function T(t,e){return!(!u(e)||!(t in e))}function $(t,e){return!!F(t,e).length}function A(t,e="isVisible"){return t.filter(t=>!T(e,t)||t[e])}function B(t,e){return t.reduce((t,s)=>t.some(t=>t[e]===s[e])?t:[...t,s],[])}function F(t,e){return t.filter(t=>e.includes(t))}function I(t){return t.filter(t=>!s(t))}const J=()=>{let t=0;return(e="")=>`${e}${++t}`},V=J();function W(t){return l(t)?t:[t]}function z(t,e){const s=[];for(let n=0;n<t.length;n+=e)s.push(t.slice(n,n+e));return s}class R{isDefaultPrevented=!1;constructor(){this.preventDefault=this.preventDefault.bind(this),this.overrideDefault=this.overrideDefault.bind(this)}preventDefault(){this.isDefaultPrevented=!0}overrideDefault(){this.isDefaultPrevented=!1}}class U{subscriptions={};constructor(){this.emit=this.emit.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.clear=this.clear.bind(this)}emit(t,e,s){const n=this.subscriptions[t];if(n){const{event:t,listenerList:i}=n;i.forEach(s=>j(s,Object.assign(t,e))),t.isDefaultPrevented||j(s)}else j(s)}on(t,e){const s=this.subscriptions[t];return s?s.listenerList.push(e):this.subscriptions[t]={event:new R,listenerList:[e]},()=>this.off(t,e)}off(t,e){const s=this.subscriptions[t];if(s){const{event:n,listenerList:i}=s;this.subscriptions[t]={event:n,listenerList:i.filter(t=>t!==e)},n.overrideDefault()}}clear(t){delete this.subscriptions[t]}}const q=(t="?",...e)=>[`[${(t&&n(t)?t:"?").toUpperCase()}]`,...e.reduce((t,e,s,{length:n})=>{const i=s===n-1?[]:["|"];return t.push(e,...i),t},e.length?["-"]:[])];var H,K,Q;!function(t){t.StartGroup="group",t.EndGroup="groupEnd",t.Default="log"}(H||(H={})),function(t){t.Info="[36m%s[0m",t.Success="[32m%s[0m",t.Warning="[33m%s[0m",t.Danger="[31m%s[0m"}(K||(K={}));class X{static formatted={info:(...t)=>X.info(...q(...t)),success:(...t)=>X.success(...q(...t)),warning:(...t)=>X.warning(...q(...t)),danger:(...t)=>X.danger(...q(...t))};static#t(t,...e){console[t](...e)}static startGroup(t,e,...s){X.#t(H.StartGroup,...((t,...e)=>["%c%s",t,...e])(`font-size: 16px;${e}`,...q(t,...s)))}static endGroup(){X.#t(H.EndGroup)}static info(...t){X.#t(H.Default,K.Info,...t)}static success(...t){X.#t(H.Default,K.Success,...t)}static warning(...t){X.#t(H.Default,K.Warning,...t)}static danger(...t){X.#t(H.Default,K.Danger,...t)}}!function(t){t.Capture="capture",t.Forward="forward"}(Q||(Q={}));class Y{static eventEmitter=new U;static caseList=[];static log(t,e={signal:"unknown"}){const{signal:s,message:n,payload:i,stack:r}=e,o=[n,y(t)?t.message:void 0].filter(Boolean);X.formatted.danger(s,...o,{error:t,payload:i,stack:r})}static get on(){return Y.eventEmitter.on}static get off(){return Y.eventEmitter.off}static get clear(){return Y.eventEmitter.clear}static create(t,e){return new Error(t,{cause:e})}static throw(t,e){throw Y.create(t,e)}static capture(t,e){Y.log(t,e),Y.eventEmitter.emit(Q.Capture,{error:t,config:e})}static forward(t,e){throw Y.log(t,e),Y.eventEmitter.emit(Q.Capture,{error:t,config:e}),t}static case(t){Y.caseList.push(t)}static parse(t){const e={message:"Error!",status:0,errors:{},isExternal:!0};for(const{check:s,parse:n}of Y.caseList)if(s(t,e))return n(t,e);return!0===y(t)?{message:t.message,status:e.status,errors:e.errors,isExternal:e.isExternal}:{message:e.message,status:e.status,errors:e.errors,isExternal:e.isExternal}}}class Z{key;model;config;constructor(t,e,s){this.key=t,this.model=e,this.config=s}async get(t){const{defaultValue:e,withDebug:s}={...this.config,...t},n=await this.model.get(this.key),i=n&&JSON.parse(n)||e;return s&&X.formatted.info("get",this.key,i),i}async set(t,e){const{withDebug:s}={...this.config,...e};await this.model.set(this.key,JSON.stringify(t)),s&&X.formatted.info("set",this.key,t)}async delete(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});await this.model.delete(this.key),e&&X.formatted.info("delete",this.key,s)}async has(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});return e&&X.formatted.info("has",this.key,s),!!s}}class _{model;config;constructor(t,e){this.model=t,this.config=e}async all(){Y.throw("Not implemented")}async clear(){Y.throw("Not implemented")}create(t){const e={[t]:new Z(t,this.model,this.config)};return Object.assign(this,e)}}export{Y as ErrorHandler,Q as ErrorHandlerEventName,U as EventEmitter,X as Log,_ as Storage,z as chunkList,L as clamp,S as compose,G as debounce,A as filterByKey,B as filterDuplicateByKey,F as filterEqualValues,I as filterNullableValues,W as forceList,V as generateId,J as generateIdFactory,N as getValueByKey,$ as hasEqualValues,T as hasKey,u as isAnyObject,l as isArray,h as isArrayBuffer,M as isArrayEmpty,r as isBigint,a as isBoolean,b as isDate,y as isError,E as isFunction,g as isMap,o as isNaN,e as isNull,s as isNullable,i as isNumber,f as isObject,C as isObjectEmpty,v as isPromise,w as isProxy,D as isRegExp,m as isSet,n as isString,c as isSymbol,t as isUndefined,d as isWeakMap,p as isWeakSet,P as mapRecord,j as runCallback,x as sleep,O as throttle,k as wait};
|
package/dist/utils/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=e=>void 0===e,t=e=>null===e,r=r=>e(r)||t(r),s=e=>"object"==typeof e,o=e=>{const t=[n,i,p,u,c,a,f,
|
|
1
|
+
"use strict";const e=e=>void 0===e,t=e=>null===e,r=r=>e(r)||t(r),s=e=>"object"==typeof e,o=e=>{const t=[n,i,p,u,c,a,x,f,l,y,m].some(t=>t(e));return!!e&&"object"==typeof e&&!t},n=e=>Array.isArray(e),i=e=>e instanceof ArrayBuffer,p=e=>e instanceof Map,u=e=>e instanceof Set,c=e=>e instanceof Map,a=e=>e instanceof Set,x=e=>e instanceof Date,f=e=>e instanceof Error,l=e=>e instanceof RegExp,y=e=>e instanceof Promise,m=e=>e instanceof Function;const b=(e,...t)=>{if(m(e))return e(...t)};function g(e,t){return!(!s(t)||!(e in t))}function h(e,t){return e.filter(e=>t.includes(e))}const d=()=>{let e=0;return(t="")=>`${t}${++e}`},E=d();exports.chunkList=function(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r},exports.clamp=(e,t,r)=>Math.min(r,Math.max(t,e)),exports.compose=function(e,t,s){const n=!o(e);return!r(s)&&{...t,...n?{[s]:e}:e}||!r(t)&&{...t,...e}||{...e}},exports.debounce=(e,t)=>{let r;return(...s)=>{r&&clearTimeout(r),r=setTimeout(()=>b(e,...s),t)}},exports.filterByKey=function(e,t="isVisible"){return e.filter(e=>!g(t,e)||e[t])},exports.filterDuplicateByKey=function(e,t){return e.reduce((e,r)=>e.some(e=>e[t]===r[t])?e:[...e,r],[])},exports.filterEqualValues=h,exports.filterNullableValues=function(e){return e.filter(e=>!r(e))},exports.forceList=function(e){return n(e)?e:[e]},exports.generateId=E,exports.generateIdFactory=d,exports.getValueByKey=function(e,t,s){return r(e)?s:2===arguments.length?t[e]:t[e]??s},exports.hasEqualValues=function(e,t){return!!h(e,t).length},exports.hasKey=g,exports.isAnyObject=s,exports.isArray=n,exports.isArrayBuffer=i,exports.isArrayEmpty=function(e){return 0===e.length},exports.isBigint=e=>"bigint"==typeof e,exports.isBoolean=e=>"boolean"==typeof e,exports.isDate=x,exports.isError=f,exports.isFunction=m,exports.isMap=p,exports.isNaN=e=>Number.isNaN(e),exports.isNull=t,exports.isNullable=r,exports.isNumber=e=>"number"==typeof e,exports.isObject=o,exports.isObjectEmpty=function(e){for(const t in e)return!1;return!0},exports.isPromise=y,exports.isProxy=e=>e instanceof Proxy,exports.isRegExp=l,exports.isSet=u,exports.isString=e=>"string"==typeof e,exports.isSymbol=e=>"symbol"==typeof e,exports.isUndefined=e,exports.isWeakMap=c,exports.isWeakSet=a,exports.mapRecord=(e,t)=>{const r=Object.entries(e);return Object.fromEntries(r.map(([e,r],s,o)=>[e,t(e,r,s,o)]))},exports.runCallback=b,exports.sleep=(e=0)=>{},exports.throttle=(e,t)=>{let r=!0;return(...s)=>{r&&(b(e,...s),r=!1),setTimeout(()=>r=!0,t)}},exports.wait=(e=0)=>new Promise(t=>setTimeout(t,e));
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -108,6 +108,34 @@ type CallbackParamList<Callback> = Callback extends (...args: infer ParamList) =
|
|
|
108
108
|
* ```
|
|
109
109
|
*/
|
|
110
110
|
declare const wait: (delay?: number) => Promise<unknown>;
|
|
111
|
+
/**
|
|
112
|
+
* Засыпает на указанное количество миллисекунд.
|
|
113
|
+
*
|
|
114
|
+
* @param delay - Длительность ожидания в миллисекундах
|
|
115
|
+
* @returns void
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* sleep(300)
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
declare const sleep: (delay?: number) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Ограничивает значение числом в заданном диапазоне.
|
|
125
|
+
*
|
|
126
|
+
* @param value - Значение
|
|
127
|
+
* @param min - Минимальное значение
|
|
128
|
+
* @param max - Максимальное значение
|
|
129
|
+
* @returns Ограниченное значение
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* clamp(10, 0, 100) // 10
|
|
134
|
+
* clamp(100, 0, 100) // 100
|
|
135
|
+
* clamp(50, 0, 100) // 50
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare const clamp: (value: number, min: number, max: number) => number;
|
|
111
139
|
/**
|
|
112
140
|
* Собирает объект из переданного значения и опционального исходного объекта.
|
|
113
141
|
* Поддерживает три сценария: вернуть объект как есть, слить два объекта или записать примитив по ключу.
|
|
@@ -587,4 +615,4 @@ declare const isPromise: (param: unknown) => param is Promise<typeof param>;
|
|
|
587
615
|
*/
|
|
588
616
|
declare const isFunction: <Callback = <ParamList extends BaseList, Result>(...paramList: ParamList) => Result>(param: unknown) => param is Callback;
|
|
589
617
|
|
|
590
|
-
export { chunkList, compose, debounce, filterByKey, filterDuplicateByKey, filterEqualValues, filterNullableValues, forceList, generateId, generateIdFactory, getValueByKey, hasEqualValues, hasKey, isAnyObject, isArray, isArrayBuffer, isArrayEmpty, isBigint, isBoolean, isDate, isError, isFunction, isMap, isNaN, isNull, isNullable, isNumber, isObject, isObjectEmpty, isPromise, isProxy, isRegExp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, mapRecord, runCallback, throttle, wait };
|
|
618
|
+
export { chunkList, clamp, compose, debounce, filterByKey, filterDuplicateByKey, filterEqualValues, filterNullableValues, forceList, generateId, generateIdFactory, getValueByKey, hasEqualValues, hasKey, isAnyObject, isArray, isArrayBuffer, isArrayEmpty, isBigint, isBoolean, isDate, isError, isFunction, isMap, isNaN, isNull, isNullable, isNumber, isObject, isObjectEmpty, isPromise, isProxy, isRegExp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, mapRecord, runCallback, sleep, throttle, wait };
|
package/dist/utils/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const n=n=>void 0===n,t=n=>null===n,e=e=>n(e)||t(e),r=n=>"string"==typeof n,o=n=>"number"==typeof n,i=n=>"bigint"==typeof n,u=n=>Number.isNaN(n),c=n=>"boolean"==typeof n,f=n=>"symbol"==typeof n,s=n=>"object"==typeof n,a=n=>{const t=[l,m,p,y,b,g,h,j,
|
|
1
|
+
const n=n=>void 0===n,t=n=>null===n,e=e=>n(e)||t(e),r=n=>"string"==typeof n,o=n=>"number"==typeof n,i=n=>"bigint"==typeof n,u=n=>Number.isNaN(n),c=n=>"boolean"==typeof n,f=n=>"symbol"==typeof n,s=n=>"object"==typeof n,a=n=>{const t=[l,m,p,y,b,g,h,j,M,T,d].some(t=>t(n));return!!n&&"object"==typeof n&&!t},l=n=>Array.isArray(n),m=n=>n instanceof ArrayBuffer,p=n=>n instanceof Map,y=n=>n instanceof Set,b=n=>n instanceof Map,g=n=>n instanceof Set,h=n=>n instanceof Date,j=n=>n instanceof Error,x=n=>n instanceof Proxy,M=n=>n instanceof RegExp,T=n=>n instanceof Promise,d=n=>n instanceof Function,A=(n=0)=>new Promise(t=>setTimeout(t,n)),E=(n=0)=>{},N=(n,t,e)=>Math.min(e,Math.max(t,n));function P(n,t,r){const o=!a(n);return!e(r)&&{...t,...o?{[r]:n}:n}||!e(t)&&{...t,...n}||{...n}}function O(n,t,r){return e(n)?r:2===arguments.length?t[n]:t[n]??r}const S=(n,t)=>{const e=Object.entries(n);return Object.fromEntries(e.map(([n,e],r,o)=>[n,t(n,e,r,o)]))},$=(n,...t)=>{if(d(n))return n(...t)},v=(n,t)=>{let e;return(...r)=>{e&&clearTimeout(e),e=setTimeout(()=>$(n,...r),t)}},w=(n,t)=>{let e=!0;return(...r)=>{e&&($(n,...r),e=!1),setTimeout(()=>e=!0,t)}};function B(n){for(const t in n)return!1;return!0}function D(n){return 0===n.length}function F(n,t){return!(!s(t)||!(n in t))}function R(n,t){return!!q(n,t).length}function V(n,t="isVisible"){return n.filter(n=>!F(t,n)||n[t])}function k(n,t){return n.reduce((n,e)=>n.some(n=>n[t]===e[t])?n:[...n,e],[])}function q(n,t){return n.filter(n=>t.includes(n))}function z(n){return n.filter(n=>!e(n))}const C=()=>{let n=0;return(t="")=>`${t}${++n}`},G=C();function H(n){return l(n)?n:[n]}function I(n,t){const e=[];for(let r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e}export{I as chunkList,N as clamp,P as compose,v as debounce,V as filterByKey,k as filterDuplicateByKey,q as filterEqualValues,z as filterNullableValues,H as forceList,G as generateId,C as generateIdFactory,O as getValueByKey,R as hasEqualValues,F as hasKey,s as isAnyObject,l as isArray,m as isArrayBuffer,D as isArrayEmpty,i as isBigint,c as isBoolean,h as isDate,j as isError,d as isFunction,p as isMap,u as isNaN,t as isNull,e as isNullable,o as isNumber,a as isObject,B as isObjectEmpty,T as isPromise,x as isProxy,M as isRegExp,y as isSet,r as isString,f as isSymbol,n as isUndefined,b as isWeakMap,g as isWeakSet,S as mapRecord,$ as runCallback,E as sleep,w as throttle,A as wait};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"name": "@mediacubeco/base",
|
|
5
5
|
"description": "Base by Mediacube developers",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"eslint": "^9.39.1",
|
|
18
18
|
"prettier": "^3.8.1",
|
|
19
19
|
"typescript": "^6.0.3",
|
|
20
|
-
"@mediacubeco/eslint-config": "2.1.
|
|
21
|
-
"@mediacubeco/
|
|
22
|
-
"@mediacubeco/
|
|
20
|
+
"@mediacubeco/eslint-config": "2.1.1",
|
|
21
|
+
"@mediacubeco/typescript-config": "2.1.1",
|
|
22
|
+
"@mediacubeco/prettier-config": "2.1.1"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|