Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@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 0.9.0 to 0.10.0

2

declaration/utils.d.ts

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

export declare function now(): number;
export declare function findIndex<T>(arr: T[], callback: (element: T, index: number, arr: T[]) => any, defaultIndex?: number): number;
export declare function find<T>(arr: T[], callback: (element: T, index: number, arr: T[]) => any, defalutValue?: T): T | undefined;
export declare const requestAnimationFrame: (callback: FrameRequestCallback) => number;
export declare const cancelAnimationFrame: (handle: number) => void;

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

repository: https://github.com/daybrush/utils
@version 0.9.0
@version 0.10.0
*/

@@ -530,2 +530,47 @@ /**

/**
* Returns the index of the first element in the array that satisfies the provided testing function.
* @function
* @memberof CrossBrowser
* @param - The array `findIndex` was called upon.
* @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found.
* @param - Returns defaultIndex if not found by the function.
* @example
import { findIndex } from "@daybrush/utils";
findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1
*/
function findIndex(arr, callback, defaultIndex) {
if (defaultIndex === void 0) {
defaultIndex = -1;
}
var length = arr.length;
for (var i = 0; i < length; ++i) {
if (callback(arr[i], i, arr)) {
return i;
}
}
return defaultIndex;
}
/**
* Returns the value of the first element in the array that satisfies the provided testing function.
* @function
* @memberof CrossBrowser
* @param - The array `find` was called upon.
* @param - A function to execute on each value in the array,
* @param - Returns defalutValue if not found by the function.
* @example
import { find } from "@daybrush/utils";
find([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // {a: 2}
*/
function find(arr, callback, defalutValue) {
var index = findIndex(arr, callback);
return index > -1 ? arr[index] : defalutValue;
}
/**
* window.requestAnimationFrame() method with cross browser.

@@ -903,3 +948,3 @@ * @function

export { RGB, RGBA, HSL, HSLA, COLOR_MODELS, FUNCTION, PROPERTY, ARRAY, OBJECT, STRING, NUMBER, UNDEFINED, IS_WINDOW, doc as document, getCrossBrowserProperty, TRANSFORM, FILTER, ANIMATION, KEYFRAMES, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isFunction, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, requestAnimationFrame, cancelAnimationFrame, $, 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, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isFunction, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, findIndex, find, requestAnimationFrame, cancelAnimationFrame, $, hasClass, addClass, removeClass, fromCSS, addEvent, removeEvent };
//# sourceMappingURL=utils.esm.js.map

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

repository: https://github.com/daybrush/utils
@version 0.9.0
@version 0.10.0
*/

@@ -536,2 +536,47 @@ (function (global, factory) {

/**
* Returns the index of the first element in the array that satisfies the provided testing function.
* @function
* @memberof CrossBrowser
* @param - The array `findIndex` was called upon.
* @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found.
* @param - Returns defaultIndex if not found by the function.
* @example
import { findIndex } from "@daybrush/utils";
findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1
*/
function findIndex(arr, callback, defaultIndex) {
if (defaultIndex === void 0) {
defaultIndex = -1;
}
var length = arr.length;
for (var i = 0; i < length; ++i) {
if (callback(arr[i], i, arr)) {
return i;
}
}
return defaultIndex;
}
/**
* Returns the value of the first element in the array that satisfies the provided testing function.
* @function
* @memberof CrossBrowser
* @param - The array `find` was called upon.
* @param - A function to execute on each value in the array,
* @param - Returns defalutValue if not found by the function.
* @example
import { find } from "@daybrush/utils";
find([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // {a: 2}
*/
function find(arr, callback, defalutValue) {
var index = findIndex(arr, callback);
return index > -1 ? arr[index] : defalutValue;
}
/**
* window.requestAnimationFrame() method with cross browser.

@@ -950,2 +995,4 @@ * @function

now: now,
findIndex: findIndex,
find: find,
requestAnimationFrame: requestAnimationFrame,

@@ -952,0 +999,0 @@ cancelAnimationFrame: cancelAnimationFrame,

4

dist/utils.min.js

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

repository: https://github.com/daybrush/utils
@version 0.9.0
@version 0.10.0
*/
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.utils=n()}(this,function(){"use strict";var s="rgb",c="rgba",f="hsl",l="hsla",e=[s,c,f,l],n="function",t="object",r="string",a="undefined",i=typeof window!==a,o=typeof document!==a&&document,u=["webkit","ms","moz","o"],m=function(e){if(!o)return"";var n=(o.body||o.documentElement).style,t=u.length;if(typeof n[e]!==a)return e;for(var r=0;r<t;++r){var i="-"+u[r]+"-"+e;if(typeof n[i]!==a)return i}return""},d=m("transform"),p=m("filter"),w=m("animation"),v=w.replace("animation","keyframes");function A(e){var n=e.match(/("[^"]*"|'[^']*'|[^,\s()]*\((?:[^()]*|\([^()]*\))*\)[^,\s()]*|[^,])+/g);return n?n.map(function(e){return e.trim()}):[]}function h(e){var n=/([^(]*)\(([\s\S]*)\)([\s\S]*)/g.exec(e);return!n||n.length<4?{}:{prefix:n[1],value:n[2],suffix:n[3]}}function g(){return Date.now?Date.now():(new Date).getTime()}var y=function(){var t=g(),e=i&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame);return e?e.bind(window):function(e){var n=g();return window.setTimeout(function(){e(n-t)},1e3/60)}}();function F(e){return e.replace("#","")}function R(e){var n=F(e),t=parseInt(n.substring(0,2),16),r=parseInt(n.substring(2,4),16),i=parseInt(n.substring(4,6),16),a=parseInt(n.substring(6,8),16)/255;return isNaN(a)&&(a=1),[t,r,i,a]}function b(e){var n=e.charAt(1),t=e.charAt(2),r=e.charAt(3),i=e.charAt(4);return["#",n,n,t,t,r,r,i,i].join("")}function N(e){var n=e[0],t=e[1],r=e[2];n<0&&(n+=360*Math.floor((Math.abs(n)+360)/360)),n%=360;var i,a=(1-Math.abs(2*r-1))*t,o=a*(1-Math.abs(n/60%2-1)),u=r-a/2;return n<60?i=[a,o,0]:n<120?i=[o,a,0]:n<180?i=[0,a,o]:n<240?i=[0,o,a]:n<300?i=[o,0,a]:n<360&&(i=[a,0,o]),[Math.round(255*(i[0]+u)),Math.round(255*(i[1]+u)),Math.round(255*(i[2]+u)),3<e.length?e[3]:1]}return{RGB:s,RGBA:c,HSL:f,HSLA:l,COLOR_MODELS:e,FUNCTION:n,PROPERTY:"property",ARRAY:"array",OBJECT:t,STRING:r,NUMBER:"number",UNDEFINED:a,IS_WINDOW:i,document:o,getCrossBrowserProperty:m,TRANSFORM:d,FILTER:p,ANIMATION:w,KEYFRAMES:v,cutHex:F,hexToRGBA:R,toFullHex:b,hslToRGBA:N,stringToRGBA:function(e){if("#"===e.charAt(0))return 4===e.length||5===e.length?R(b(e)):R(e);if(-1!==e.indexOf("(")){var n=h(e),t=n.prefix,r=n.value;if(!t||!r)return;var i=A(r),a=[],o=i.length;switch(t){case s:case c:for(var u=0;u<o;++u)a[u]=parseFloat(i[u]);return a;case f:case l:for(u=0;u<o;++u)-1!==i[u].indexOf("%")?a[u]=parseFloat(i[u])/100:a[u]=parseFloat(i[u]);return N(a)}}},dot:function(e,n,t,r){return(e*r+n*t)/(t+r)},isUndefined:function(e){return typeof e===a},isObject:function(e){return e&&typeof e===t},isArray:function(e){return Array.isArray(e)},isString:function(e){return typeof e===r},isFunction:function(e){return typeof e===n},splitSpace:function(e){return e.match(/("[^"]*")|('[^']*')|([^\s()]*(?:\((?:[^()]*|\([^()]*\))*\))[^\s()]*)|\S+/g)||[]},splitComma:A,splitBracket:h,splitUnit:function(e){var n=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(e);if(!n)return{prefix:"",unit:"",value:NaN};var t=n[1],r=n[2];return{prefix:t,unit:n[3],value:parseFloat(r)}},camelize:function(e){return e.replace(/[\s-_]([a-z])/g,function(e,n){return n.toUpperCase()})},decamelize:function(e,r){return void 0===r&&(r="-"),e.replace(/([a-z])([A-Z])/g,function(e,n,t){return""+n+r+t.toLowerCase()})},toArray:function(e){return[].slice.call(e)},now:g,requestAnimationFrame:y,cancelAnimationFrame:function(){var e=i&&(window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame);return e?e.bind(window):function(e){clearTimeout(e)}}(),$:function(e,n){return n?o.querySelectorAll(e):o.querySelector(e)},hasClass:function(e,n){return e.classList?e.classList.contains(n):!!e.className.match(new RegExp("(\\s|^)"+n+"(\\s|$)"))},addClass:function(e,n){e.classList?e.classList.add(n):e.className+=" "+n},removeClass:function(e,n){if(e.classList)e.classList.remove(n);else{var t=new RegExp("(\\s|^)"+n+"(\\s|$)");e.className=e.className.replace(t," ")}},fromCSS:function(e,n){if(!e||!n||!n.length)return{};var t;if(e instanceof Element)t=e;else{if(!e.length)return{};t=e[0]}for(var r={},i=window.getComputedStyle(t),a=n.length,o=0;o<a;++o)r[n[o]]=i[n[o]];return r},addEvent:function(e,n,t,r){e.addEventListener(n,t,r)},removeEvent:function(e,n,t){e.removeEventListener(n,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";var s="rgb",c="rgba",f="hsl",l="hsla",n=[s,c,f,l],e="function",t="object",r="string",a="undefined",i=typeof window!==a,o=typeof document!==a&&document,u=["webkit","ms","moz","o"],m=function(n){if(!o)return"";var e=(o.body||o.documentElement).style,t=u.length;if(typeof e[n]!==a)return n;for(var r=0;r<t;++r){var i="-"+u[r]+"-"+n;if(typeof e[i]!==a)return i}return""},d=m("transform"),p=m("filter"),v=m("animation"),w=v.replace("animation","keyframes");function h(n){var e=n.match(/("[^"]*"|'[^']*'|[^,\s()]*\((?:[^()]*|\([^()]*\))*\)[^,\s()]*|[^,])+/g);return e?e.map(function(n){return n.trim()}):[]}function A(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 g(){return Date.now?Date.now():(new Date).getTime()}function y(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 F=function(){var t=g(),n=i&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame);return n?n.bind(window):function(n){var e=g();return window.setTimeout(function(){n(e-t)},1e3/60)}}();function R(n){return n.replace("#","")}function b(n){var e=R(n),t=parseInt(e.substring(0,2),16),r=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16),a=parseInt(e.substring(6,8),16)/255;return isNaN(a)&&(a=1),[t,r,i,a]}function N(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 S(n){var e=n[0],t=n[1],r=n[2];e<0&&(e+=360*Math.floor((Math.abs(e)+360)/360)),e%=360;var i,a=(1-Math.abs(2*r-1))*t,o=a*(1-Math.abs(e/60%2-1)),u=r-a/2;return e<60?i=[a,o,0]:e<120?i=[o,a,0]:e<180?i=[0,a,o]:e<240?i=[0,o,a]:e<300?i=[o,0,a]:e<360&&(i=[a,0,o]),[Math.round(255*(i[0]+u)),Math.round(255*(i[1]+u)),Math.round(255*(i[2]+u)),3<n.length?n[3]:1]}return{RGB:s,RGBA:c,HSL:f,HSLA:l,COLOR_MODELS:n,FUNCTION:e,PROPERTY:"property",ARRAY:"array",OBJECT:t,STRING:r,NUMBER:"number",UNDEFINED:a,IS_WINDOW:i,document:o,getCrossBrowserProperty:m,TRANSFORM:d,FILTER:p,ANIMATION:v,KEYFRAMES:w,cutHex:R,hexToRGBA:b,toFullHex:N,hslToRGBA:S,stringToRGBA:function(n){if("#"===n.charAt(0))return 4===n.length||5===n.length?b(N(n)):b(n);if(-1!==n.indexOf("(")){var e=A(n),t=e.prefix,r=e.value;if(!t||!r)return;var i=h(r),a=[],o=i.length;switch(t){case s:case c:for(var u=0;u<o;++u)a[u]=parseFloat(i[u]);return a;case f:case l:for(u=0;u<o;++u)-1!==i[u].indexOf("%")?a[u]=parseFloat(i[u])/100:a[u]=parseFloat(i[u]);return S(a)}}},dot:function(n,e,t,r){return(n*r+e*t)/(t+r)},isUndefined:function(n){return typeof n===a},isObject:function(n){return n&&typeof n===t},isArray:function(n){return Array.isArray(n)},isString:function(n){return typeof n===r},isFunction:function(n){return typeof n===e},splitSpace:function(n){return n.match(/("[^"]*")|('[^']*')|([^\s()]*(?:\((?:[^()]*|\([^()]*\))*\))[^\s()]*)|\S+/g)||[]},splitComma:h,splitBracket:A,splitUnit:function(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)}},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:g,findIndex:y,find:function(n,e,t){var r=y(n,e);return-1<r?n[r]:t},requestAnimationFrame:F,cancelAnimationFrame:function(){var n=i&&(window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame);return n?n.bind(window):function(n){clearTimeout(n)}}(),$:function(n,e){return e?o.querySelectorAll(n):o.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){if(n.classList)n.classList.remove(e);else{var 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),a=e.length,o=0;o<a;++o)r[e[o]]=i[e[o]];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": "0.9.0",
"version": "0.10.0",
"description": "utils for daybrush",

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

"isNumber",
"dot"
"dot",
"find",
"findIndx"
],

@@ -58,3 +60,3 @@ "scripts": {

"@daybrush/jsdoc": "^0.3.6",
"@daybrush/release": "^0.1.1",
"@daybrush/release": "^0.2.4",
"daybrush-jsdoc-template": "^1.5.0",

@@ -61,0 +63,0 @@ "gh-pages": "^2.0.1",

@@ -253,3 +253,53 @@ import { UNDEFINED, STRING, OBJECT, FUNCTION, IS_WINDOW } from "./consts";

}
/**
* Returns the index of the first element in the array that satisfies the provided testing function.
* @function
* @memberof CrossBrowser
* @param - The array `findIndex` was called upon.
* @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found.
* @param - Returns defaultIndex if not found by the function.
* @example
import { findIndex } from "@daybrush/utils";
findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1
*/
export function findIndex<T>(
arr: T[],
callback: (element: T, index: number, arr: T[]) => any,
defaultIndex: number = -1,
): number {
const length = arr.length;
for (let i = 0; i < length; ++i) {
if (callback(arr[i], i, arr)) {
return i;
}
}
return defaultIndex;
}
/**
* Returns the value of the first element in the array that satisfies the provided testing function.
* @function
* @memberof CrossBrowser
* @param - The array `find` was called upon.
* @param - A function to execute on each value in the array,
* @param - Returns defalutValue if not found by the function.
* @example
import { find } from "@daybrush/utils";
find([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // {a: 2}
*/
export function find<T>(
arr: T[],
callback: (element: T, index: number, arr: T[]) => any,
defalutValue?: T,
): T | undefined {
const index = findIndex(arr, callback);
return index > - 1 ? arr[index] : defalutValue;
}
/**
* window.requestAnimationFrame() method with cross browser.

@@ -256,0 +306,0 @@ * @function

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