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.10.5 to 0.11.0

6

declaration/color.d.ts
export declare function cutHex(hex: string): string;
export declare function hexToRGBA(hex: string): number[];
export declare function hexToRGBA(hex: string): [number, number, number, number];
export declare function toFullHex(h: string): string;
export declare function hslToRGBA(hsl: number[]): number[];
export declare function stringToRGBA(color: string): number[];
export declare function hslToRGBA(hsl: readonly [number, number, number, number?]): [number, number, number, number];
export declare function stringToRGBA(color: string): [number, number, number, number];

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

export declare const cancelAnimationFrame: (handle: number) => void;
export declare function getKeys(obj: IObject<any>): string[];

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

repository: https://github.com/daybrush/utils
@version 0.10.5
@version 0.11.0
*/

@@ -156,3 +156,3 @@ /**

var doc = typeof document !== UNDEFINED && document;
var doc = typeof document !== UNDEFINED && document; // FIXME: this type maybe false
var prefixes = ["webkit", "ms", "moz", "o"];

@@ -691,3 +691,16 @@ /**

}();
function getKeys(obj) {
if (Object.keys) {
return Object.keys(obj);
}
var keys = [];
for (var name in keys) {
keys.push(name);
}
return keys;
}
/**

@@ -772,2 +785,4 @@ * @namespace

function hslToRGBA(hsl) {
var _a;
var h = hsl[0];

@@ -799,6 +814,7 @@ var s = hsl[1];

rgb = [c, 0, x];
} else {
rgb = [0, 0, 0];
}
var result = [Math.round((rgb[0] + m) * 255), Math.round((rgb[1] + m) * 255), Math.round((rgb[2] + m) * 255), hsl.length > 3 ? hsl[3] : 1];
return result;
return [Math.round((rgb[0] + m) * 255), Math.round((rgb[1] + m) * 255), Math.round((rgb[2] + m) * 255), (_a = hsl[3]) !== null && _a !== void 0 ? _a : 1];
}

@@ -832,7 +848,7 @@ /**

if (!prefix || !value) {
return;
return undefined;
}
var arr = splitComma(value);
var colorArr = [];
var colorArr = [0, 0, 0, 1];
var length = arr.length;

@@ -864,3 +880,3 @@

return;
return undefined;
}

@@ -1018,3 +1034,3 @@

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, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isFunction, splitText, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, findIndex, find, 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, OPEN_CLOSED_CHARACTER, cutHex, hexToRGBA, toFullHex, hslToRGBA, stringToRGBA, dot, isUndefined, isObject, isArray, isString, isFunction, splitText, splitSpace, splitComma, splitBracket, splitUnit, camelize, decamelize, toArray, now, findIndex, find, requestAnimationFrame, cancelAnimationFrame, getKeys, $, hasClass, addClass, removeClass, fromCSS, addEvent, removeEvent };
//# sourceMappingURL=utils.esm.js.map

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

repository: https://github.com/daybrush/utils
@version 0.10.5
@version 0.11.0
*/

@@ -162,3 +162,3 @@ (function (global, factory) {

var doc = typeof document !== UNDEFINED && document;
var doc = typeof document !== UNDEFINED && document; // FIXME: this type maybe false
var prefixes = ["webkit", "ms", "moz", "o"];

@@ -697,3 +697,16 @@ /**

}();
function getKeys(obj) {
if (Object.keys) {
return Object.keys(obj);
}
var keys = [];
for (var name in keys) {
keys.push(name);
}
return keys;
}
/**

@@ -778,2 +791,4 @@ * @namespace

function hslToRGBA(hsl) {
var _a;
var h = hsl[0];

@@ -805,6 +820,7 @@ var s = hsl[1];

rgb = [c, 0, x];
} else {
rgb = [0, 0, 0];
}
var result = [Math.round((rgb[0] + m) * 255), Math.round((rgb[1] + m) * 255), Math.round((rgb[2] + m) * 255), hsl.length > 3 ? hsl[3] : 1];
return result;
return [Math.round((rgb[0] + m) * 255), Math.round((rgb[1] + m) * 255), Math.round((rgb[2] + m) * 255), (_a = hsl[3]) !== null && _a !== void 0 ? _a : 1];
}

@@ -838,7 +854,7 @@ /**

if (!prefix || !value) {
return;
return undefined;
}
var arr = splitComma(value);
var colorArr = [];
var colorArr = [0, 0, 0, 1];
var length = arr.length;

@@ -870,3 +886,3 @@

return;
return undefined;
}

@@ -1071,2 +1087,3 @@

cancelAnimationFrame: cancelAnimationFrame,
getKeys: getKeys,
$: $,

@@ -1073,0 +1090,0 @@ hasClass: hasClass,

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

repository: https://github.com/daybrush/utils
@version 0.10.5
@version 0.11.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";var s="rgb",f="rgba",c="hsl",l="hsla",n=[s,f,c,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"),h=['"',"'",'\\"',"\\'"];function A(n,e,t,r){for(var i=t;i<r;++i){var a=e[i].trim();if(a===n)return i;var o=i;if("("===a?o=A(")",e,i+1,r):-1<h.indexOf(a)&&(o=A(a,e,i+1,r)),-1===o)break;i=o}return-1}function g(n,e){for(var t=new RegExp("(\\s*"+(e||",")+"\\s*|\\(|\\)|\"|'|\\\\\"|\\\\'|\\s+)","g"),r=n.split(t).filter(Boolean),i=r.length,a=[],o=[],u=0;u<i;++u){var s=r[u].trim(),f=u;if("("===s)f=A(")",r,u+1,i);else{if(")"===s)throw new Error("invalid format");if(-1<h.indexOf(s))f=A(s,r,u+1,i);else if(s===e){o.length&&(a.push(o.join("")),o=[]);continue}}-1===f&&(f=i-1),o.push(r.slice(u,f+1).join("")),u=f}return o.length&&a.push(o.join("")),a}function y(n){return g(n,",")}function R(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 E(){return Date.now?Date.now():(new Date).getTime()}function x(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=E(),n=i&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame);return n?n.bind(window):function(n){var e=E();return window.setTimeout(function(){n(e-t)},1e3/60)}}();function b(n){return n.replace("#","")}function N(n){var e=b(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 C(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:f,HSL:c,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,OPEN_CLOSED_CHARACTER:h,cutHex:b,hexToRGBA:N,toFullHex:C,hslToRGBA:S,stringToRGBA:function(n){if("#"===n.charAt(0))return 4===n.length||5===n.length?N(C(n)):N(n);if(-1!==n.indexOf("(")){var e=R(n),t=e.prefix,r=e.value;if(!t||!r)return;var i=y(r),a=[],o=i.length;switch(t){case s:case f:for(var u=0;u<o;++u)a[u]=parseFloat(i[u]);return a;case c: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},splitText:g,splitSpace:function(n){return g(n,"")},splitComma:y,splitBracket:R,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:E,findIndex:x,find:function(n,e,t){var r=x(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)}}});
!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",f="rgba",c="hsl",l="hsla",e=[s,f,c,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"),v=m("animation"),w=v.replace("animation","keyframes"),h=['"',"'",'\\"',"\\'"];function A(e,n,t,r){for(var i=t;i<r;++i){var a=n[i].trim();if(a===e)return i;var o=i;if("("===a?o=A(")",n,i+1,r):-1<h.indexOf(a)&&(o=A(a,n,i+1,r)),-1===o)break;i=o}return-1}function g(e,n){for(var t=new RegExp("(\\s*"+(n||",")+"\\s*|\\(|\\)|\"|'|\\\\\"|\\\\'|\\s+)","g"),r=e.split(t).filter(Boolean),i=r.length,a=[],o=[],u=0;u<i;++u){var s=r[u].trim(),f=u;if("("===s)f=A(")",r,u+1,i);else{if(")"===s)throw new Error("invalid format");if(-1<h.indexOf(s))f=A(s,r,u+1,i);else if(s===n){o.length&&(a.push(o.join("")),o=[]);continue}}-1===f&&(f=i-1),o.push(r.slice(u,f+1).join("")),u=f}return o.length&&a.push(o.join("")),a}function y(e){return g(e,",")}function R(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 b(){return Date.now?Date.now():(new Date).getTime()}function E(e,n,t){void 0===t&&(t=-1);for(var r=e.length,i=0;i<r;++i)if(n(e[i],i,e))return i;return t}var x=function(){var t=b(),e=i&&(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame);return e?e.bind(window):function(e){var n=b();return window.setTimeout(function(){e(n-t)},1e3/60)}}();function F(e){return e.replace("#","")}function N(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 C(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 O(e){var n,t=e[0],r=e[1],i=e[2];t<0&&(t+=360*Math.floor((Math.abs(t)+360)/360)),t%=360;var a,o=(1-Math.abs(2*i-1))*r,u=o*(1-Math.abs(t/60%2-1)),s=i-o/2;return a=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],[Math.round(255*(a[0]+s)),Math.round(255*(a[1]+s)),Math.round(255*(a[2]+s)),null!==(n=e[3])&&void 0!==n?n:1]}return{RGB:s,RGBA:f,HSL:c,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:v,KEYFRAMES:w,OPEN_CLOSED_CHARACTER:h,cutHex:F,hexToRGBA:N,toFullHex:C,hslToRGBA:O,stringToRGBA:function(e){if("#"===e.charAt(0))return 4===e.length||5===e.length?N(C(e)):N(e);if(-1!==e.indexOf("(")){var n=R(e),t=n.prefix,r=n.value;if(!t||!r)return;var i=y(r),a=[0,0,0,1],o=i.length;switch(t){case s:case f:for(var u=0;u<o;++u)a[u]=parseFloat(i[u]);return a;case c:case l:for(u=0;u<o;++u)-1!==i[u].indexOf("%")?a[u]=parseFloat(i[u])/100:a[u]=parseFloat(i[u]);return O(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},splitText:g,splitSpace:function(e){return g(e,"")},splitComma:y,splitBracket:R,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:b,findIndex:E,find:function(e,n,t){var r=E(e,n);return-1<r?e[r]:t},requestAnimationFrame:x,cancelAnimationFrame:function(){var e=i&&(window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.msCancelAnimationFrame);return e?e.bind(window):function(e){clearTimeout(e)}}(),getKeys:function(e){if(Object.keys)return Object.keys(e);var n=[];for(var t in n)n.push(t);return n},$: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)}}});
//# sourceMappingURL=utils.min.js.map
{
"name": "@daybrush/utils",
"version": "0.10.5",
"version": "0.11.0",
"description": "utils for daybrush",

@@ -65,2 +65,3 @@ "main": "dist/utils.js",

"@types/mocha": "^7.0.2",
"@types/node": "^14.0.27",
"@types/sinon": "^9.0.0",

@@ -88,4 +89,3 @@ "chai": "^4.2.0",

"typescript": "^3.9.5"
},
"dependencies": {}
}
}

@@ -35,3 +35,3 @@ import { RGB, RGBA, HSL, HSLA } from "./consts";

*/
export function hexToRGBA(hex: string): number[] {
export function hexToRGBA(hex: string): [number, number, number, number] {
const h = cutHex(hex);

@@ -80,3 +80,3 @@ const r = parseInt(h.substring(0, 2), 16);

*/
export function hslToRGBA(hsl: number[]): number[] {
export function hslToRGBA(hsl: readonly [number, number, number, number?]): [number, number, number, number] {
let h = hsl[0];

@@ -94,3 +94,3 @@ const s = hsl[1];

const m = l - c / 2;
let rgb;
let rgb: [number, number, number];

@@ -109,11 +109,12 @@ if (h < 60) {

rgb = [c, 0, x];
} else {
rgb = [0, 0, 0];
}
const result = [
return [
Math.round((rgb[0] + m) * 255),
Math.round((rgb[1] + m) * 255),
Math.round((rgb[2] + m) * 255),
hsl.length > 3 ? hsl[3] : 1,
hsl[3] ?? 1,
];
return result;
}

@@ -132,3 +133,3 @@ /**

*/
export function stringToRGBA(color: string): number[] {
export function stringToRGBA(color: string): [number, number, number, number] {
if (color.charAt(0) === "#") {

@@ -145,6 +146,6 @@ if (color.length === 4 || color.length === 5) {

if (!prefix || !value) {
return;
return undefined as never;
}
const arr = splitComma(value);
const colorArr: number[] = [];
const colorArr: [number, number, number, number] = [0, 0, 0, 1];
const length = arr.length;

@@ -172,3 +173,3 @@

}
return;
return undefined as never;
}

@@ -137,3 +137,3 @@ /**

*/
const doc = typeof document !== UNDEFINED && document;
const doc = (typeof document !== UNDEFINED && document) as Document; // FIXME: this type maybe false

@@ -140,0 +140,0 @@ export {doc as document};

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

*/
export function $<E extends Element = Element>(selectors: string, multi?: boolean): E | NodeListOf<E> {
export function $<E extends Element = Element>(selectors: string, multi?: boolean): E | NodeListOf<E> | null {
return multi ? document.querySelectorAll<E>(selectors) : document.querySelector<E>(selectors);

@@ -35,0 +35,0 @@ }

@@ -411,1 +411,12 @@ import { UNDEFINED, STRING, OBJECT, FUNCTION, IS_WINDOW, OPEN_CLOSED_CHARACTER } from "./consts";

})();
export function getKeys(obj: IObject<any>): string[] {
if (Object.keys) {
return Object.keys(obj);
}
const keys: string[] = [];
for (const name in keys) {
keys.push(name);
}
return keys;
}

@@ -13,3 +13,4 @@ {

"noUnusedLocals": true,
"skipLibCheck": true,
"skipLibCheck": false,
"strict": true,
"moduleResolution": "node",

@@ -16,0 +17,0 @@ "lib": [

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