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.1.1 to 1.2.0

5

declaration/utils.d.ts

@@ -40,1 +40,6 @@ import { IArrayFormat, IObject } from "./types";

export declare function calculateBoundSize(size: number[], minSize: number[], maxSize: number[], keepRatio?: boolean): number[];
export declare function sum(...nums: number[]): number;
export declare function average(...nums: number[]): number;
export declare function getRad(pos1: number[], pos2: number[]): number;
export declare function getCenterPoint(points: number[][]): number[];
export declare function getShapeDirection(points: number[][]): 1 | -1;

85

dist/utils.esm.js

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

repository: https://github.com/daybrush/utils
@version 1.1.1
@version 1.2.0
*/

@@ -855,4 +855,85 @@ /**

}
/**
* Add all the numbers.
* @function
* @memberof Utils
*/
function sum() {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var length = nums.length;
var total = 0;
for (var i = length - 1; i >= 0; --i) {
total += nums[i];
}
return total;
}
/**
* Average all numbers.
* @function
* @memberof Utils
*/
function average() {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var length = nums.length;
var total = 0;
for (var i = length - 1; i >= 0; --i) {
total += nums[i];
}
return length ? total / length : 0;
}
/**
* Get the angle of two points. (0 <= rad < 359)
* @function
* @memberof Utils
*/
function getRad(pos1, pos2) {
var distX = pos2[0] - pos1[0];
var distY = pos2[1] - pos1[1];
var rad = Math.atan2(distY, distX);
return rad >= 0 ? rad : rad + Math.PI * 2;
}
/**
* Get the average point of all points.
* @function
* @memberof Utils
*/
function getCenterPoint(points) {
return [0, 1].map(function (i) {
return average.apply(void 0, points.map(function (pos) {
return pos[i];
}));
});
}
/**
* Gets the direction of the shape.
* @function
* @memberof Utils
*/
function getShapeDirection(points) {
var center = getCenterPoint(points);
var pos1Rad = getRad(center, points[0]);
var pos2Rad = getRad(center, points[1]);
return pos1Rad < pos2Rad && pos2Rad - pos1Rad < Math.PI || pos1Rad > pos2Rad && pos2Rad - pos1Rad < -Math.PI ? 1 : -1;
}
/**
* @namespace

@@ -1181,3 +1262,3 @@ * @name Color

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, 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, $, 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, 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, $, hasClass, addClass, removeClass, fromCSS, addEvent, removeEvent };
//# sourceMappingURL=utils.esm.js.map

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

repository: https://github.com/daybrush/utils
@version 1.1.1
@version 1.2.0
*/

@@ -861,4 +861,85 @@ (function (global, factory) {

}
/**
* Add all the numbers.
* @function
* @memberof Utils
*/
function sum() {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var length = nums.length;
var total = 0;
for (var i = length - 1; i >= 0; --i) {
total += nums[i];
}
return total;
}
/**
* Average all numbers.
* @function
* @memberof Utils
*/
function average() {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var length = nums.length;
var total = 0;
for (var i = length - 1; i >= 0; --i) {
total += nums[i];
}
return length ? total / length : 0;
}
/**
* Get the angle of two points. (0 <= rad < 359)
* @function
* @memberof Utils
*/
function getRad(pos1, pos2) {
var distX = pos2[0] - pos1[0];
var distY = pos2[1] - pos1[1];
var rad = Math.atan2(distY, distX);
return rad >= 0 ? rad : rad + Math.PI * 2;
}
/**
* Get the average point of all points.
* @function
* @memberof Utils
*/
function getCenterPoint(points) {
return [0, 1].map(function (i) {
return average.apply(void 0, points.map(function (pos) {
return pos[i];
}));
});
}
/**
* Gets the direction of the shape.
* @function
* @memberof Utils
*/
function getShapeDirection(points) {
var center = getCenterPoint(points);
var pos1Rad = getRad(center, points[0]);
var pos2Rad = getRad(center, points[1]);
return pos1Rad < pos2Rad && pos2Rad - pos1Rad < Math.PI || pos1Rad > pos2Rad && pos2Rad - pos1Rad < -Math.PI ? 1 : -1;
}
/**
* @namespace

@@ -1242,2 +1323,7 @@ * @name Color

calculateBoundSize: calculateBoundSize,
sum: sum,
average: average,
getRad: getRad,
getCenterPoint: getCenterPoint,
getShapeDirection: getShapeDirection,
$: $,

@@ -1244,0 +1330,0 @@ hasClass: hasClass,

4

dist/utils.min.js

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

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

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

@@ -490,6 +490,6 @@ import { UNDEFINED, STRING, OBJECT, FUNCTION, IS_WINDOW, OPEN_CLOSED_CHARACTER, NUMBER, DEFAULT_UNIT_PRESETS } from "./consts";

return [
[compareSize[0], compareSize[0] * targetSize[1] / targetSize[0]],
[compareSize[1] * targetSize[0] / targetSize[1], compareSize[1]],
[compareSize[0], compareSize[0] * targetSize[1] / targetSize[0]],
[compareSize[1] * targetSize[0] / targetSize[1], compareSize[1]],
].filter(size => size.every((value, i) => {
return isMax ? value <= compareSize[i] : value >= compareSize[i];
return isMax ? value <= compareSize[i] : value >= compareSize[i];
}))[0] || targetSize;

@@ -508,3 +508,3 @@ }

if (!keepRatio) {
return size.map((value, i) => between(value, minSize[i], maxSize[i]));
return size.map((value, i) => between(value, minSize[i], maxSize[i]));
}

@@ -517,9 +517,73 @@ let [width, height] = size;

if (width < minWidth || height < minHeight) {
width = minWidth;
height = minHeight;
width = minWidth;
height = minHeight;
} else if (width > maxWidth || height > maxHeight) {
width = maxWidth;
height = maxHeight;
width = maxWidth;
height = maxHeight;
}
return [width, height];
}
/**
* Add all the numbers.
* @function
* @memberof Utils
*/
export function sum(...nums: number[]): number {
const length = nums.length;
let total = 0;
for (let i = length - 1; i >= 0; --i) {
total += nums[i];
}
return total;
}
/**
* Average all numbers.
* @function
* @memberof Utils
*/
export function average(...nums: number[]) {
const length = nums.length;
let total = 0;
for (let i = length - 1; i >= 0; --i) {
total += nums[i];
}
return length ? total / length : 0;
}
/**
* Get the angle of two points. (0 <= rad < 359)
* @function
* @memberof Utils
*/
export function getRad(pos1: number[], pos2: number[]): number {
const distX = pos2[0] - pos1[0];
const distY = pos2[1] - pos1[1];
const rad = Math.atan2(distY, distX);
return rad >= 0 ? rad : rad + Math.PI * 2;
}
/**
* Get the average point of all points.
* @function
* @memberof Utils
*/
export function getCenterPoint(points: number[][]): number[] {
return [0, 1].map(i => average(...points.map(pos => pos[i])));
}
/**
* Gets the direction of the shape.
* @function
* @memberof Utils
*/
export function getShapeDirection(points: number[][]): 1 | -1 {
const center = getCenterPoint(points);
const pos1Rad = getRad(center, points[0]);
const pos2Rad = getRad(center, points[1]);
return (pos1Rad < pos2Rad && pos2Rad - pos1Rad < Math.PI) || (pos1Rad > pos2Rad && pos2Rad - pos1Rad < -Math.PI)
? 1 : -1;
}

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