Socket
Socket
Sign inDemoInstall

@daybrush/utils

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@daybrush/utils - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

LICENSE

2

declaration/dom.d.ts

@@ -13,2 +13,2 @@ import { IObject, IEventMap } from "./types";

export declare function addEvent<K extends keyof IEventMap>(el: EventTarget, type: K, listener: (e: IEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
export declare function removeEvent<K extends keyof IEventMap>(el: EventTarget, type: K, listener: (e: IEventMap[K]) => void): void;
export declare function removeEvent<K extends keyof IEventMap>(el: EventTarget, type: K, listener: (e: IEventMap[K]) => void, options?: boolean | EventListenerOptions): void;

@@ -38,3 +38,2 @@ import { IArrayFormat, IObject } from "./types";

export declare function between(value: number, min: number, max: number): number;
export declare function throttle(num: number, unit?: number): number;
export declare function checkBoundSize(targetSize: number[], compareSize: number[], isMax: boolean): number[];

@@ -48,1 +47,3 @@ export declare function calculateBoundSize(size: number[], minSize: number[], maxSize: number[], keepRatio?: boolean): number[];

export declare function getDist(a: number[], b?: number[]): number;
export declare function throttle(num: number, unit?: number): number;
export declare function throttleArray(nums: number[], unit?: number): number[];

@@ -7,3 +7,3 @@ /*

repository: https://github.com/daybrush/utils
@version 1.4.0
@version 1.5.0
*/

@@ -815,15 +815,2 @@ /**

}
/**
* throttle number
* @function
* @memberof Utils
*/
function throttle(num, unit) {
if (!unit) {
return num;
}
return Math.round(num / unit) * unit;
}
function checkBoundSize(targetSize, compareSize, isMax) {

@@ -948,4 +935,29 @@ return [[throttle(compareSize[0], TINY_NUM), throttle(compareSize[0] * targetSize[1] / targetSize[0], TINY_NUM)], [throttle(compareSize[1] * targetSize[0] / targetSize[1], TINY_NUM), throttle(compareSize[1], TINY_NUM)]].filter(function (size) {

}
/**
* throttle number depending on the unit.
* @function
* @memberof Utils
*/
function throttle(num, unit) {
if (!unit) {
return num;
}
return Math.round(num / unit) * unit;
}
/**
* throttle number array depending on the unit.
* @function
* @memberof Utils
*/
function throttleArray(nums, unit) {
nums.forEach(function (_, i) {
nums[i] = throttle(nums[i], unit);
});
return nums;
}
/**
* @namespace

@@ -1243,3 +1255,3 @@ * @name Color

* @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs
* @param - An options object that specifies characteristics about the event listener. The available options are:
* @param - An options object that specifies characteristics about the event listener.
* @example

@@ -1262,2 +1274,3 @@ import {addEvent} from "@daybrush/utils";

* @param - The EventListener function of the event handler to remove from the event target.
* @param - An options object that specifies characteristics about the event listener.
* @example

@@ -1272,7 +1285,7 @@ import {addEvent, removeEvent} from "@daybrush/utils";

function removeEvent(el, type, listener) {
el.removeEventListener(type, listener);
function removeEvent(el, type, listener, options) {
el.removeEventListener(type, listener, options);
}
export { RGB, RGBA, HSL, HSLA, COLOR_MODELS, FUNCTION, PROPERTY, ARRAY, OBJECT, STRING, NUMBER, UNDEFINED, IS_WINDOW, doc as document, getCrossBrowserProperty, TRANSFORM, FILTER, ANIMATION, KEYFRAMES, OPEN_CLOSED_CHARACTER, TINY_NUM, DEFAULT_UNIT_PRESETS, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isNumber, isFunction, splitText, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, findIndex, find, requestAnimationFrame, cancelAnimationFrame, getKeys, sortOrders, convertUnitSize, between, throttle, checkBoundSize, calculateBoundSize, sum, average, getRad, getCenterPoint, getShapeDirection, getDist, $, hasClass, addClass, removeClass, fromCSS, addEvent, removeEvent };
export { RGB, RGBA, HSL, HSLA, COLOR_MODELS, FUNCTION, PROPERTY, ARRAY, OBJECT, STRING, NUMBER, UNDEFINED, IS_WINDOW, doc as document, getCrossBrowserProperty, TRANSFORM, FILTER, ANIMATION, KEYFRAMES, OPEN_CLOSED_CHARACTER, TINY_NUM, DEFAULT_UNIT_PRESETS, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isNumber, isFunction, splitText, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, findIndex, find, requestAnimationFrame, cancelAnimationFrame, getKeys, sortOrders, convertUnitSize, between, checkBoundSize, calculateBoundSize, sum, average, getRad, getCenterPoint, getShapeDirection, getDist, throttle, throttleArray, $, hasClass, addClass, removeClass, fromCSS, addEvent, removeEvent };
//# sourceMappingURL=utils.esm.js.map

@@ -7,3 +7,3 @@ /*

repository: https://github.com/daybrush/utils
@version 1.4.0
@version 1.5.0
*/

@@ -821,15 +821,2 @@ (function (global, factory) {

}
/**
* throttle number
* @function
* @memberof Utils
*/
function throttle(num, unit) {
if (!unit) {
return num;
}
return Math.round(num / unit) * unit;
}
function checkBoundSize(targetSize, compareSize, isMax) {

@@ -954,4 +941,29 @@ return [[throttle(compareSize[0], TINY_NUM), throttle(compareSize[0] * targetSize[1] / targetSize[0], TINY_NUM)], [throttle(compareSize[1] * targetSize[0] / targetSize[1], TINY_NUM), throttle(compareSize[1], TINY_NUM)]].filter(function (size) {

}
/**
* throttle number depending on the unit.
* @function
* @memberof Utils
*/
function throttle(num, unit) {
if (!unit) {
return num;
}
return Math.round(num / unit) * unit;
}
/**
* throttle number array depending on the unit.
* @function
* @memberof Utils
*/
function throttleArray(nums, unit) {
nums.forEach(function (_, i) {
nums[i] = throttle(nums[i], unit);
});
return nums;
}
/**
* @namespace

@@ -1249,3 +1261,3 @@ * @name Color

* @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs
* @param - An options object that specifies characteristics about the event listener. The available options are:
* @param - An options object that specifies characteristics about the event listener.
* @example

@@ -1268,2 +1280,3 @@ import {addEvent} from "@daybrush/utils";

* @param - The EventListener function of the event handler to remove from the event target.
* @param - An options object that specifies characteristics about the event listener.
* @example

@@ -1278,4 +1291,4 @@ import {addEvent, removeEvent} from "@daybrush/utils";

function removeEvent(el, type, listener) {
el.removeEventListener(type, listener);
function removeEvent(el, type, listener, options) {
el.removeEventListener(type, listener, options);
}

@@ -1337,3 +1350,2 @@

between: between,
throttle: throttle,
checkBoundSize: checkBoundSize,

@@ -1347,2 +1359,4 @@ calculateBoundSize: calculateBoundSize,

getDist: getDist,
throttle: throttle,
throttleArray: throttleArray,
$: $,

@@ -1349,0 +1363,0 @@ hasClass: hasClass,

@@ -7,5 +7,5 @@ /*

repository: https://github.com/daybrush/utils
@version 1.4.0
@version 1.5.0
*/
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.utils=t()}(this,function(){"use strict";function n(n){if(!d)return"";var t=(d.body||d.documentElement).style,e=m.length;if(typeof t[n]!=u)return n;for(var r=0;r<e;++r){var i="-"+m[r]+"-"+n;if(typeof t[i]!=u)return i}return""}var f="rgb",c="rgba",s="hsl",l="hsla",t=[f,c,s,l],e="function",r="object",i="string",o="number",u="undefined",a=typeof window!=u,d=typeof document!=u&&document,m=["webkit","ms","moz","o"],v=n("transform"),h=n("filter"),p=n("animation"),w=p.replace("animation","keyframes"),g=['"',"'",'\\"',"\\'"],A=1e-7,y={cm:function(n){return 96*n/2.54},mm:function(n){return 96*n/254},in:function(n){return 96*n},pt:function(n){return 96*n/72},pc:function(n){return 96*n/6},"%":function(n,t){return n*t/100},vw:function(n,t){return void 0===t&&(t=window.innerWidth),n/100*t},vh:function(n,t){return void 0===t&&(t=window.innerHeight),n/100*t},vmax:function(n,t){return void 0===t&&(t=Math.max(window.innerWidth,window.innerHeight)),n/100*t},vmin:function(n,t){return void 0===t&&(t=Math.min(window.innerWidth,window.innerHeight)),n/100*t}};function x(n){return n&&typeof n===r}function R(n){return typeof n===e}function E(n,t,e,r){for(var i=e;i<r;++i){var o=t[i].trim();if(o===n)return i;var u=i;if("("===o?u=E(")",t,i+1,r):-1<g.indexOf(o)&&(u=E(o,t,i+1,r)),-1===u)break;i=u}return-1}function M(n,t){for(var e=new RegExp("(\\s*"+(t||",")+"\\s*|\\(|\\)|\"|'|\\\\\"|\\\\'|\\s+)","g"),r=n.split(e).filter(Boolean),i=r.length,o=[],u=[],a=0;a<i;++a){var f=r[a].trim(),c=a;if("("===f)c=E(")",r,a+1,i);else{if(")"===f)throw new Error("invalid format");if(-1<g.indexOf(f))c=E(f,r,a+1,i);else if(f===t){u.length&&(o.push(u.join("")),u=[]);continue}}-1===c&&(c=i-1),u.push(r.slice(a,c+1).join("")),a=c}return u.length&&o.push(u.join("")),o}function b(n){return M(n,",")}function S(n){var t=/([^(]*)\(([\s\S]*)\)([\s\S]*)/g.exec(n);return!t||t.length<4?{}:{prefix:t[1],value:t[2],suffix:t[3]}}function N(n){var t=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(n);if(!t)return{prefix:"",unit:"",value:NaN};var e=t[1],r=t[2];return{prefix:e,unit:t[3],value:parseFloat(r)}}function F(){return Date.now?Date.now():(new Date).getTime()}function O(n,t,e){void 0===e&&(e=-1);for(var r=n.length,i=0;i<r;++i)if(t(n[i],i,n))return i;return e}var C=function(){var e=F(),n=a&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame);return n?n.bind(window):function(n){var t=F();return window.setTimeout(function(){n(t-e)},1e3/60)}}();function T(n,t,e){return Math.max(t,Math.min(n,e))}function I(n,t){return t?Math.round(n/t)*t:n}function L(n,e,r){return[[I(e[0],A),I(e[0]*n[1]/n[0],A)],[I(e[1]*n[0]/n[1],A),I(e[1],A)]].filter(function(n){return n.every(function(n,t){return r?n<=e[t]:n>=e[t]})})[0]||n}function B(n){for(var t=n.length,e=0,r=t-1;0<=r;--r)e+=n[r];return t?e/t:0}function D(n,t){var e=t[0]-n[0],r=t[1]-n[1],i=Math.atan2(r,e);return 0<=i?i:i+2*Math.PI}function z(n){return[0,1].map(function(t){return B(n.map(function(n){return n[t]}))})}function U(n){return n.replace("#","")}function j(n){var t=U(n),e=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16),o=parseInt(t.substring(6,8),16)/255;return isNaN(o)&&(o=1),[e,r,i,o]}function k(n){var t=n.charAt(1),e=n.charAt(2),r=n.charAt(3),i=n.charAt(4);return["#",t,t,e,e,r,r,i,i].join("")}function P(n){var t,e=n[0],r=n[1],i=n[2];e<0&&(e+=360*Math.floor((Math.abs(e)+360)/360)),e%=360;var o=(1-Math.abs(2*i-1))*r,u=o*(1-Math.abs(e/60%2-1)),a=i-o/2,f=e<60?[o,u,0]:e<120?[u,o,0]:e<180?[0,o,u]:e<240?[0,u,o]:e<300?[u,0,o]:e<360?[o,0,u]:[0,0,0];return[Math.round(255*(f[0]+a)),Math.round(255*(f[1]+a)),Math.round(255*(f[2]+a)),null!==(t=n[3])&&void 0!==t?t:1]}return{RGB:f,RGBA:c,HSL:s,HSLA:l,COLOR_MODELS:t,FUNCTION:e,PROPERTY:"property",ARRAY:"array",OBJECT:r,STRING:i,NUMBER:o,UNDEFINED:u,IS_WINDOW:a,document:d,getCrossBrowserProperty:n,TRANSFORM:v,FILTER:h,ANIMATION:p,KEYFRAMES:w,OPEN_CLOSED_CHARACTER:g,TINY_NUM:A,DEFAULT_UNIT_PRESETS:y,cutHex:U,hexToRGBA:j,toFullHex:k,hslToRGBA:P,stringToRGBA:function(n){if("#"===n.charAt(0))return 4===n.length||5===n.length?j(k(n)):j(n);if(-1!==n.indexOf("(")){var t=S(n),e=t.prefix,r=t.value;if(!e||!r)return;var i=b(r),o=[0,0,0,1],u=i.length;switch(e){case f:case c:for(var a=0;a<u;++a)o[a]=parseFloat(i[a]);return o;case s:case l:for(a=0;a<u;++a)-1!==i[a].indexOf("%")?o[a]=parseFloat(i[a])/100:o[a]=parseFloat(i[a]);return P(o)}}},dot:function(n,t,e,r){return(n*r+t*e)/(e+r)},isUndefined:function(n){return typeof n==u},isObject:x,isArray:function(n){return Array.isArray(n)},isString:function(n){return typeof n==i},isNumber:function(n){return typeof n==o},isFunction:R,splitText:M,splitSpace:function(n){return M(n,"")},splitComma:b,splitBracket:S,splitUnit:N,camelize:function(n){return n.replace(/[\s-_]([a-z])/g,function(n,t){return t.toUpperCase()})},decamelize:function(n,r){return void 0===r&&(r="-"),n.replace(/([a-z])([A-Z])/g,function(n,t,e){return""+t+r+e.toLowerCase()})},toArray:function(n){return[].slice.call(n)},now:F,findIndex:O,find:function(n,t,e){var r=O(n,t);return-1<r?n[r]:e},requestAnimationFrame:C,cancelAnimationFrame:function(){var n=a&&(window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame);return n?n.bind(window):function(n){clearTimeout(n)}}(),getKeys:function(n){if(Object.keys)return Object.keys(n);var t=[];for(var e in t)t.push(e);return t},sortOrders:function(n,i){void 0===i&&(i=[]),n.sort(function(n,t){var e=i.indexOf(n),r=i.indexOf(t);return-1===r&&-1===e?0:-1===e?1:-1===r?-1:e-r})},convertUnitSize:function(n,t){var e=N(n),r=e.value,i=e.unit;if(x(t)){var o=t[i];if(o){if(R(o))return o(r);if(y[i])return y[i](r,o)}}else if("%"===i)return r*t/100;return y[i]?y[i](r):r},between:T,throttle:I,checkBoundSize:L,calculateBoundSize:function(n,e,r,t){if(!t)return n.map(function(n,t){return T(n,e[t],r[t])});var i=n[0],o=n[1],u=L(n,e,!1),a=u[0],f=u[1],c=L(n,r,!0),s=c[0],l=c[1];return i<a||o<f?(i=a,o=f):(s<i||l<o)&&(i=s,o=l),[i,o]},sum:function(n){for(var t=0,e=n.length-1;0<=e;--e)t+=n[e];return t},average:B,getRad:D,getCenterPoint:z,getShapeDirection:function(n){var t=z(n),e=D(t,n[0]),r=D(t,n[1]);return e<r&&r-e<Math.PI||r<e&&r-e<-Math.PI?1:-1},getDist:function(n,t){return Math.sqrt(Math.pow((t?t[0]:0)-n[0],2)+Math.pow((t?t[1]:0)-n[1],2))},$:function(n,t){return t?d.querySelectorAll(n):d.querySelector(n)},hasClass:function(n,t){return n.classList?n.classList.contains(t):!!n.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(n,t){n.classList?n.classList.add(t):n.className+=" "+t},removeClass:function(n,t){var e;n.classList?n.classList.remove(t):(e=new RegExp("(\\s|^)"+t+"(\\s|$)"),n.className=n.className.replace(e," "))},fromCSS:function(n,t){if(!n||!t||!t.length)return{};var e;if(n instanceof Element)e=n;else{if(!n.length)return{};e=n[0]}for(var r={},i=window.getComputedStyle(e),o=t.length,u=0;u<o;++u)r[t[u]]=i[t[u]];return r},addEvent:function(n,t,e,r){n.addEventListener(t,e,r)},removeEvent:function(n,t,e){n.removeEventListener(t,e)}}});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.utils=t()}(this,function(){"use strict";function n(n){if(!d)return"";var t=(d.body||d.documentElement).style,e=m.length;if(typeof t[n]!=u)return n;for(var r=0;r<e;++r){var i="-"+m[r]+"-"+n;if(typeof t[i]!=u)return i}return""}var f="rgb",c="rgba",s="hsl",l="hsla",t=[f,c,s,l],e="function",r="object",i="string",o="number",u="undefined",a=typeof window!=u,d=typeof document!=u&&document,m=["webkit","ms","moz","o"],v=n("transform"),h=n("filter"),p=n("animation"),w=p.replace("animation","keyframes"),g=['"',"'",'\\"',"\\'"],A=1e-7,y={cm:function(n){return 96*n/2.54},mm:function(n){return 96*n/254},in:function(n){return 96*n},pt:function(n){return 96*n/72},pc:function(n){return 96*n/6},"%":function(n,t){return n*t/100},vw:function(n,t){return void 0===t&&(t=window.innerWidth),n/100*t},vh:function(n,t){return void 0===t&&(t=window.innerHeight),n/100*t},vmax:function(n,t){return void 0===t&&(t=Math.max(window.innerWidth,window.innerHeight)),n/100*t},vmin:function(n,t){return void 0===t&&(t=Math.min(window.innerWidth,window.innerHeight)),n/100*t}};function x(n){return n&&typeof n===r}function E(n){return typeof n===e}function R(n,t,e,r){for(var i=e;i<r;++i){var o=t[i].trim();if(o===n)return i;var u=i;if("("===o?u=R(")",t,i+1,r):-1<g.indexOf(o)&&(u=R(o,t,i+1,r)),-1===u)break;i=u}return-1}function M(n,t){for(var e=new RegExp("(\\s*"+(t||",")+"\\s*|\\(|\\)|\"|'|\\\\\"|\\\\'|\\s+)","g"),r=n.split(e).filter(Boolean),i=r.length,o=[],u=[],a=0;a<i;++a){var f=r[a].trim(),c=a;if("("===f)c=R(")",r,a+1,i);else{if(")"===f)throw new Error("invalid format");if(-1<g.indexOf(f))c=R(f,r,a+1,i);else if(f===t){u.length&&(o.push(u.join("")),u=[]);continue}}-1===c&&(c=i-1),u.push(r.slice(a,c+1).join("")),a=c}return u.length&&o.push(u.join("")),o}function b(n){return M(n,",")}function S(n){var t=/([^(]*)\(([\s\S]*)\)([\s\S]*)/g.exec(n);return!t||t.length<4?{}:{prefix:t[1],value:t[2],suffix:t[3]}}function N(n){var t=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(n);if(!t)return{prefix:"",unit:"",value:NaN};var e=t[1],r=t[2];return{prefix:e,unit:t[3],value:parseFloat(r)}}function F(){return Date.now?Date.now():(new Date).getTime()}function O(n,t,e){void 0===e&&(e=-1);for(var r=n.length,i=0;i<r;++i)if(t(n[i],i,n))return i;return e}var C=function(){var e=F(),n=a&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame);return n?n.bind(window):function(n){var t=F();return window.setTimeout(function(){n(t-e)},1e3/60)}}();function T(n,t,e){return Math.max(t,Math.min(n,e))}function I(n,e,r){return[[z(e[0],A),z(e[0]*n[1]/n[0],A)],[z(e[1]*n[0]/n[1],A),z(e[1],A)]].filter(function(n){return n.every(function(n,t){return r?n<=e[t]:n>=e[t]})})[0]||n}function L(n){for(var t=n.length,e=0,r=t-1;0<=r;--r)e+=n[r];return t?e/t:0}function B(n,t){var e=t[0]-n[0],r=t[1]-n[1],i=Math.atan2(r,e);return 0<=i?i:i+2*Math.PI}function D(n){return[0,1].map(function(t){return L(n.map(function(n){return n[t]}))})}function z(n,t){return t?Math.round(n/t)*t:n}function U(n){return n.replace("#","")}function j(n){var t=U(n),e=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),i=parseInt(t.substring(4,6),16),o=parseInt(t.substring(6,8),16)/255;return isNaN(o)&&(o=1),[e,r,i,o]}function k(n){var t=n.charAt(1),e=n.charAt(2),r=n.charAt(3),i=n.charAt(4);return["#",t,t,e,e,r,r,i,i].join("")}function P(n){var t,e=n[0],r=n[1],i=n[2];e<0&&(e+=360*Math.floor((Math.abs(e)+360)/360)),e%=360;var o=(1-Math.abs(2*i-1))*r,u=o*(1-Math.abs(e/60%2-1)),a=i-o/2,f=e<60?[o,u,0]:e<120?[u,o,0]:e<180?[0,o,u]:e<240?[0,u,o]:e<300?[u,0,o]:e<360?[o,0,u]:[0,0,0];return[Math.round(255*(f[0]+a)),Math.round(255*(f[1]+a)),Math.round(255*(f[2]+a)),null!==(t=n[3])&&void 0!==t?t:1]}return{RGB:f,RGBA:c,HSL:s,HSLA:l,COLOR_MODELS:t,FUNCTION:e,PROPERTY:"property",ARRAY:"array",OBJECT:r,STRING:i,NUMBER:o,UNDEFINED:u,IS_WINDOW:a,document:d,getCrossBrowserProperty:n,TRANSFORM:v,FILTER:h,ANIMATION:p,KEYFRAMES:w,OPEN_CLOSED_CHARACTER:g,TINY_NUM:A,DEFAULT_UNIT_PRESETS:y,cutHex:U,hexToRGBA:j,toFullHex:k,hslToRGBA:P,stringToRGBA:function(n){if("#"===n.charAt(0))return 4===n.length||5===n.length?j(k(n)):j(n);if(-1!==n.indexOf("(")){var t=S(n),e=t.prefix,r=t.value;if(!e||!r)return;var i=b(r),o=[0,0,0,1],u=i.length;switch(e){case f:case c:for(var a=0;a<u;++a)o[a]=parseFloat(i[a]);return o;case s:case l:for(a=0;a<u;++a)-1!==i[a].indexOf("%")?o[a]=parseFloat(i[a])/100:o[a]=parseFloat(i[a]);return P(o)}}},dot:function(n,t,e,r){return(n*r+t*e)/(e+r)},isUndefined:function(n){return typeof n==u},isObject:x,isArray:function(n){return Array.isArray(n)},isString:function(n){return typeof n==i},isNumber:function(n){return typeof n==o},isFunction:E,splitText:M,splitSpace:function(n){return M(n,"")},splitComma:b,splitBracket:S,splitUnit:N,camelize:function(n){return n.replace(/[\s-_]([a-z])/g,function(n,t){return t.toUpperCase()})},decamelize:function(n,r){return void 0===r&&(r="-"),n.replace(/([a-z])([A-Z])/g,function(n,t,e){return""+t+r+e.toLowerCase()})},toArray:function(n){return[].slice.call(n)},now:F,findIndex:O,find:function(n,t,e){var r=O(n,t);return-1<r?n[r]:e},requestAnimationFrame:C,cancelAnimationFrame:function(){var n=a&&(window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame);return n?n.bind(window):function(n){clearTimeout(n)}}(),getKeys:function(n){if(Object.keys)return Object.keys(n);var t=[];for(var e in t)t.push(e);return t},sortOrders:function(n,i){void 0===i&&(i=[]),n.sort(function(n,t){var e=i.indexOf(n),r=i.indexOf(t);return-1===r&&-1===e?0:-1===e?1:-1===r?-1:e-r})},convertUnitSize:function(n,t){var e=N(n),r=e.value,i=e.unit;if(x(t)){var o=t[i];if(o){if(E(o))return o(r);if(y[i])return y[i](r,o)}}else if("%"===i)return r*t/100;return y[i]?y[i](r):r},between:T,checkBoundSize:I,calculateBoundSize:function(n,e,r,t){if(!t)return n.map(function(n,t){return T(n,e[t],r[t])});var i=n[0],o=n[1],u=I(n,e,!1),a=u[0],f=u[1],c=I(n,r,!0),s=c[0],l=c[1];return i<a||o<f?(i=a,o=f):(s<i||l<o)&&(i=s,o=l),[i,o]},sum:function(n){for(var t=0,e=n.length-1;0<=e;--e)t+=n[e];return t},average:L,getRad:B,getCenterPoint:D,getShapeDirection:function(n){var t=D(n),e=B(t,n[0]),r=B(t,n[1]);return e<r&&r-e<Math.PI||r<e&&r-e<-Math.PI?1:-1},getDist:function(n,t){return Math.sqrt(Math.pow((t?t[0]:0)-n[0],2)+Math.pow((t?t[1]:0)-n[1],2))},throttle:z,throttleArray:function(e,r){return e.forEach(function(n,t){e[t]=z(e[t],r)}),e},$:function(n,t){return t?d.querySelectorAll(n):d.querySelector(n)},hasClass:function(n,t){return n.classList?n.classList.contains(t):!!n.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(n,t){n.classList?n.classList.add(t):n.className+=" "+t},removeClass:function(n,t){var e;n.classList?n.classList.remove(t):(e=new RegExp("(\\s|^)"+t+"(\\s|$)"),n.className=n.className.replace(e," "))},fromCSS:function(n,t){if(!n||!t||!t.length)return{};var e;if(n instanceof Element)e=n;else{if(!n.length)return{};e=n[0]}for(var r={},i=window.getComputedStyle(e),o=t.length,u=0;u<o;++u)r[t[u]]=i[t[u]];return r},addEvent:function(n,t,e,r){n.addEventListener(t,e,r)},removeEvent:function(n,t,e,r){n.removeEventListener(t,e,r)}}});
//# sourceMappingURL=utils.min.js.map
{
"name": "@daybrush/utils",
"version": "1.4.0",
"version": "1.5.0",
"description": "utils for daybrush",

@@ -5,0 +5,0 @@ "main": "dist/utils.js",

@@ -135,3 +135,3 @@ import { document } from "./consts";

* @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs
* @param - An options object that specifies characteristics about the event listener. The available options are:
* @param - An options object that specifies characteristics about the event listener.
* @example

@@ -152,3 +152,3 @@ import {addEvent} from "@daybrush/utils";

export function removeEvent<K extends keyof IEventMap>(
el: EventTarget, type: K, listener: (e: IEventMap[K]) => void): void;
el: EventTarget, type: K, listener: (e: IEventMap[K]) => void, options?: boolean | EventListenerOptions): void;
/**

@@ -160,2 +160,3 @@ * removes from the EventTarget an event listener previously registered with EventTarget.addEventListener()

* @param - The EventListener function of the event handler to remove from the event target.
* @param - An options object that specifies characteristics about the event listener.
* @example

@@ -169,4 +170,8 @@ import {addEvent, removeEvent} from "@daybrush/utils";

*/
export function removeEvent(el: EventTarget, type: string, listener: (e: Event) => void) {
el.removeEventListener(type, listener);
export function removeEvent(
el: EventTarget, type: string,
listener: (e: Event) => void,
options?: boolean | EventListenerOptions,
) {
el.removeEventListener(type, listener, options);
}

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

import { UNDEFINED, STRING, OBJECT, FUNCTION, IS_WINDOW, OPEN_CLOSED_CHARACTER, NUMBER, DEFAULT_UNIT_PRESETS, TINY_NUM } from "./consts";
import {
UNDEFINED, STRING,
OBJECT, FUNCTION,
IS_WINDOW, OPEN_CLOSED_CHARACTER, NUMBER,
DEFAULT_UNIT_PRESETS,
TINY_NUM
} from "./consts";
import { IArrayFormat, IObject } from "./types";

@@ -488,13 +494,2 @@ /**

/**
* throttle number
* @function
* @memberof Utils
*/
export function throttle(num: number, unit?: number) {
if (!unit) {
return num;
}
return Math.round(num / unit) * unit;
}
export function checkBoundSize(targetSize: number[], compareSize: number[], isMax: boolean) {

@@ -608,1 +603,25 @@ return [

}
/**
* throttle number depending on the unit.
* @function
* @memberof Utils
*/
export function throttle(num: number, unit?: number) {
if (!unit) {
return num;
}
return Math.round(num / unit) * unit;
}
/**
* throttle number array depending on the unit.
* @function
* @memberof Utils
*/
export function throttleArray(nums: number[], unit?: number) {
nums.forEach((_, i) => {
nums[i] = throttle(nums[i], unit);
});
return nums;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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