matt-utils
Advanced tools
Comparing version 1.4.3 to 1.4.6
@@ -5,19 +5,19 @@ declare module "matt-utils" { | ||
*/ | ||
export type foreachCB = (value: Element, index?: number | undefined) => any; | ||
export type foreachCB = (value: Element | HTMLElement, index?: number | undefined) => any; | ||
/** | ||
* Shorthand for `element.classList.add`, works with multiple nodes | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to add | ||
*/ | ||
export function addClass(el: Element | HTMLCollection | NodeList, ...classes: string[]): void; | ||
export function addClass(el: Element | HTMLElement | HTMLCollection | NodeList, ...classes: string[]): void; | ||
/** | ||
* Shorthand for `element.addEventListener` | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|Window|Document|MediaQueryList} el - A list of elements | ||
* @param {String} ev - Event's name | ||
* @param {Function} fn - Event's function | ||
* @param {EventListenerOrEventListenerObject} fn - Event's function | ||
* @param {Object} [opts] - Optional event options | ||
*/ | ||
export function addEvent(el: Element | HTMLCollection | NodeList, ev: string, fn: Function, opts?: Object | undefined): void; | ||
export function addEvent(el: Element | HTMLElement | Window | Document | MediaQueryList, ev: string, fn: EventListenerOrEventListenerObject, opts?: Object | undefined): void; | ||
/** | ||
@@ -27,7 +27,7 @@ * Shorthand for `document.getElementsByClassName` | ||
* @param {String} selClass - The selector's class | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
* @returns {HTMLCollection} - The selected elements | ||
* @returns {HTMLCollectionOf<Element>} - The selected elements | ||
*/ | ||
export function byClass(selClass: string, parent?: Element | undefined): HTMLCollection; | ||
export function byClass(selClass: string, parent?: Element | Document | HTMLElement | undefined): HTMLCollectionOf<Element>; | ||
/** | ||
@@ -38,5 +38,5 @@ * Shorthand for `document.getElementById` | ||
* | ||
* @returns {Element|null} - The selected element | ||
* @returns {Element|HTMLElement|null} - The selected element | ||
*/ | ||
export function byId(id: string): Element | null; | ||
export function byId(id: string): Element | HTMLElement | null; | ||
/** | ||
@@ -46,16 +46,16 @@ * Foreach polyfill for NodeList and HTMLCollection | ||
* | ||
* @param {Array|NodeList|HTMLCollection} els - A list of elements | ||
* @param {Array<any>|NodeList|HTMLCollection} els - A list of elements | ||
* @param {foreachCB} fn - Callback containing ( value, index ) as arguments | ||
* @param {Scope} [scope] - Scope | ||
* @param {Function} [scope] - Scope | ||
*/ | ||
export function forEachHTML(els: any[] | NodeList | HTMLCollection, fn: foreachCB, scope?: any): void; | ||
export function forEachHTML(els: Array<any> | NodeList | HTMLCollection, fn: foreachCB, scope?: Function | undefined): void; | ||
/** | ||
* Shorthand for `element.getAttribute` | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to retrieve | ||
* | ||
* @returns {String} - The attribute's value | ||
* @returns {String|null} - The attribute's value | ||
*/ | ||
export function getAttr(el: Element, attr: string): string; | ||
export function getAttr(el: Element | HTMLElement, attr: string): string | null; | ||
/** | ||
@@ -65,29 +65,29 @@ * Similar to jQuery `$( el ).index()` | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* | ||
* @returns {Number} - The element's index | ||
*/ | ||
export function getElementIndex(el: Element): number; | ||
export function getElementIndex(el: Element | HTMLElement): number; | ||
/** | ||
* Gets an element left position | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element} [topEl=document.body] - Wrapping element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {Element|HTMLElement} [topEl=document.body] - Wrapping element | ||
* | ||
* @returns {Number} Element's left position | ||
*/ | ||
export function getLeftPos(el: Element, topEl?: Element | undefined): number; | ||
export function getLeftPos(el: Element | HTMLElement, topEl?: Element | HTMLElement | undefined): number; | ||
/** | ||
* Gets an element top position | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element} [topEl=document.body] - Wrapping element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {Element|HTMLElement} [topEl=document.body] - Wrapping element | ||
* | ||
* @returns {Number} Element's top position | ||
*/ | ||
export function getTopPos(el: Element, topEl?: Element | undefined): number; | ||
export function getTopPos(el: Element | HTMLElement, topEl?: Element | HTMLElement | undefined): number; | ||
/** | ||
* Shorthand for `element.hasAttribute` | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to check the existance of | ||
@@ -97,3 +97,3 @@ * | ||
*/ | ||
export function hasAttr(el: Element, attr: string): boolean; | ||
export function hasAttr(el: Element | HTMLElement, attr: string): boolean; | ||
/** | ||
@@ -104,3 +104,3 @@ * Checks if an element has a class or not. | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to check the presence of | ||
@@ -110,3 +110,3 @@ * | ||
*/ | ||
export function hasClass(el: Element | HTMLCollection | NodeList, ...classes: string[]): boolean; | ||
export function hasClass(el: Element | HTMLElement | HTMLCollection | NodeList, ...classes: string[]): boolean; | ||
/** | ||
@@ -116,3 +116,3 @@ * Foreach callback | ||
* @callback foreachCB | ||
* @param {Element} value - The element | ||
* @param {Element|HTMLElement} value - The element | ||
* @param {Number} [index] - The index of the element | ||
@@ -131,47 +131,47 @@ */ | ||
* @param {String} selector - Selector | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
* @returns {Element|null} - The selected element | ||
* @returns {Element|HTMLElementTagNameMap|SVGElementTagNameMap|null} - The selected element | ||
*/ | ||
export function query(selector: string, parent?: Element | undefined): Element | null; | ||
export function query(selector: string, parent?: Element | Document | HTMLElement | undefined): Element | HTMLElementTagNameMap | SVGElementTagNameMap | null; | ||
/** | ||
* Shorthand per `document.querySelectorAll` | ||
* Shorthand for `document.querySelectorAll` | ||
* | ||
* @param {String} selector - Selector | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
* @returns {NodeList} - The selected element | ||
*/ | ||
export function queryAll(selector: string, parent?: Element | undefined): NodeList; | ||
export function queryAll(selector: string, parent?: Element | Document | HTMLElement | undefined): NodeList; | ||
/** | ||
* Shorthand for `element.removeAttribute` | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to remove | ||
*/ | ||
export function remAttr(el: Element, attr: string): void; | ||
export function remAttr(el: Element | HTMLElement, attr: string): void; | ||
/** | ||
* Shorthand for `element.classList.remove`, works with multiple nodes | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to remove | ||
*/ | ||
export function removeClass(el: Element | HTMLCollection | NodeList, ...classes: string[]): void; | ||
export function removeClass(el: Element | HTMLElement | HTMLCollection | NodeList, ...classes: string[]): void; | ||
/** | ||
* Shorthand for `element.removeEventListener` | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|Window|Document|MediaQueryList} el - A list of elements | ||
* @param {String} ev - Event's name | ||
* @param {Function} fn - Event's function | ||
* @param {EventListenerOrEventListenerObject} fn - Event's function | ||
* @param {Object} [opts] - Optional event options | ||
*/ | ||
export function removeEvent(el: Element | HTMLCollection | NodeList, ev: string, fn: Function, opts?: Object | undefined): void; | ||
export function removeEvent(el: Element | HTMLElement | Window | Document | MediaQueryList, ev: string, fn: EventListenerOrEventListenerObject, opts?: Object | undefined): void; | ||
/** | ||
* Shorthand for `element.setAttribute` | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to retrieve | ||
* @param {String} val - The value to set to the attribute | ||
*/ | ||
export function setAttr(el: Element, attr: string, val: string): void; | ||
export function setAttr(el: Element | HTMLElement, attr: string, val: string): void; | ||
} |
@@ -0,1 +1,3 @@ | ||
// @ts-check | ||
/** | ||
@@ -6,3 +8,3 @@ * Shorthand for `document.getElementById` | ||
* | ||
* @returns {Element|null} - The selected element | ||
* @returns {Element|HTMLElement|null} - The selected element | ||
*/ | ||
@@ -16,5 +18,5 @@ function byId(id) { | ||
* @param {String} selClass - The selector's class | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
* @returns {HTMLCollection} - The selected elements | ||
* @returns {HTMLCollectionOf<Element>} - The selected elements | ||
*/ | ||
@@ -29,5 +31,5 @@ | ||
* @param {String} selector - Selector | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
* @returns {Element|null} - The selected element | ||
* @returns {Element|HTMLElementTagNameMap|SVGElementTagNameMap|null} - The selected element | ||
*/ | ||
@@ -39,6 +41,6 @@ | ||
/** | ||
* Shorthand per `document.querySelectorAll` | ||
* Shorthand for `document.querySelectorAll` | ||
* | ||
* @param {String} selector - Selector | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
@@ -52,2 +54,4 @@ * @returns {NodeList} - The selected element | ||
// @ts-check | ||
/** | ||
@@ -57,5 +61,5 @@ * Foreach polyfill for NodeList and HTMLCollection | ||
* | ||
* @param {Array|NodeList|HTMLCollection} els - A list of elements | ||
* @param {Array<any>|NodeList|HTMLCollection} els - A list of elements | ||
* @param {foreachCB} fn - Callback containing ( value, index ) as arguments | ||
* @param {Scope} [scope] - Scope | ||
* @param {Function} [scope] - Scope | ||
*/ | ||
@@ -69,3 +73,3 @@ function forEachHTML(els, fn, scope) { | ||
* @callback foreachCB | ||
* @param {Element} value - The element | ||
* @param {Element|HTMLElement} value - The element | ||
* @param {Number} [index] - The index of the element | ||
@@ -84,2 +88,3 @@ */ | ||
requestAnimationFrame(() => { | ||
// @ts-ignore | ||
fn.call(); | ||
@@ -92,4 +97,4 @@ }); | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element} [topEl=document.body] - Wrapping element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {Element|HTMLElement} [topEl=document.body] - Wrapping element | ||
* | ||
@@ -105,4 +110,4 @@ * @returns {Number} Element's top position | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element} [topEl=document.body] - Wrapping element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {Element|HTMLElement} [topEl=document.body] - Wrapping element | ||
* | ||
@@ -119,3 +124,3 @@ * @returns {Number} Element's left position | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* | ||
@@ -126,3 +131,3 @@ * @returns {Number} - The element's index | ||
function getElementIndex(el) { | ||
let index = 0; | ||
let index = 0; // @ts-ignore | ||
@@ -134,6 +139,7 @@ while (el = el.previousElementSibling) index++; | ||
// @ts-check | ||
/** | ||
* Shorthand for `element.classList.add`, works with multiple nodes | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to add | ||
@@ -143,3 +149,8 @@ */ | ||
function addClass(el, ...classes) { | ||
if (el.length === undefined) addClassEl(el, ...classes);else { | ||
// @ts-ignore | ||
if (el.length === undefined) { | ||
// @ts-ignore | ||
addClassEl(el, ...classes); | ||
} else { | ||
// @ts-ignore | ||
forEachHTML(el, currEl => { | ||
@@ -152,6 +163,7 @@ addClassEl(currEl, ...classes); | ||
* | ||
* @param {Element} elem - An HTML element | ||
* @param {Element|HTMLElement} elem - An HTML element | ||
* @param {...String} remClass - Classes to add | ||
*/ | ||
function addClassEl(elem, ...remClass) { | ||
@@ -166,3 +178,3 @@ remClass.forEach(singleClass => { | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to remove | ||
@@ -172,3 +184,8 @@ */ | ||
function removeClass(el, ...classes) { | ||
if (el.length === undefined) removeClassEl(el, ...classes);else { | ||
// @ts-ignore | ||
if (el.length === undefined) { | ||
// @ts-ignore | ||
removeClassEl(el, ...classes); | ||
} else { | ||
// @ts-ignore | ||
forEachHTML(el, currEl => { | ||
@@ -181,6 +198,7 @@ removeClassEl(currEl, ...classes); | ||
* | ||
* @param {Element} elem - An HTML element | ||
* @param {Element|HTMLElement} elem - An HTML element | ||
* @param {...String} remClass - Classes to remove | ||
*/ | ||
function removeClassEl(elem, ...remClass) { | ||
@@ -197,3 +215,3 @@ remClass.forEach(singleClass => { | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to check the presence of | ||
@@ -205,10 +223,17 @@ * | ||
function hasClass(el, ...classes) { | ||
let hasCls = false; | ||
if (el.length === undefined) hasCls = hasClassEl(el, ...classes);else { | ||
let numClasses = 0; | ||
let hasCls = false; // @ts-ignore | ||
if (el.length === undefined) { | ||
// @ts-ignore | ||
hasCls = hasClassEl(el, ...classes); | ||
} else { | ||
let numClasses = 0; // @ts-ignore | ||
forEachHTML(el, currEl => { | ||
if (hasClassEl(currEl, ...classes)) numClasses++; | ||
}); | ||
}); // @ts-ignore | ||
hasCls = numClasses === el.length; | ||
} | ||
return hasCls; | ||
@@ -218,3 +243,3 @@ /** | ||
* | ||
* @param {Element} elem - An HTML element | ||
* @param {Element|HTMLElement} elem - An HTML element | ||
* @param {...String} hasClasses - Classes to check the presence of | ||
@@ -234,8 +259,10 @@ * | ||
// @ts-check | ||
/** | ||
* Shorthand for `element.addEventListener` | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|Window|Document|MediaQueryList} el - A list of elements | ||
* @param {String} ev - Event's name | ||
* @param {Function} fn - Event's function | ||
* @param {EventListenerOrEventListenerObject} fn - Event's function | ||
* @param {Object} [opts] - Optional event options | ||
@@ -249,5 +276,5 @@ */ | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|Window|Document|MediaQueryList} el - A list of elements | ||
* @param {String} ev - Event's name | ||
* @param {Function} fn - Event's function | ||
* @param {EventListenerOrEventListenerObject} fn - Event's function | ||
* @param {Object} [opts] - Optional event options | ||
@@ -260,9 +287,11 @@ */ | ||
// @ts-check | ||
/** | ||
* Shorthand for `element.getAttribute` | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to retrieve | ||
* | ||
* @returns {String} - The attribute's value | ||
* @returns {String|null} - The attribute's value | ||
*/ | ||
@@ -275,3 +304,3 @@ function getAttr(el, attr) { | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to retrieve | ||
@@ -287,3 +316,3 @@ * @param {String} val - The value to set to the attribute | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to remove | ||
@@ -298,3 +327,3 @@ */ | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to check the existance of | ||
@@ -301,0 +330,0 @@ * |
{ | ||
"name": "matt-utils", | ||
"version": "1.4.3", | ||
"version": "1.4.6", | ||
"description": "Some simple shothands for some js functions and methods", | ||
"main": "./dist/matt-utils.js", | ||
"exports": "./dist/matt-utils.js", | ||
"type": "module", | ||
"jest": { | ||
"verbose": true, | ||
"testEnvironment": "jsdom" | ||
}, | ||
"scripts": { | ||
@@ -32,19 +37,23 @@ "rl": "rollup -cw", | ||
"devDependencies": { | ||
"@babel/core": "^7.13.8", | ||
"@babel/eslint-parser": "^7.13.8", | ||
"@babel/preset-env": "^7.13.9", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"browserslist": "^4.16.3", | ||
"core-js": "^3.9.1", | ||
"eslint": "^7.21.0", | ||
"glob": "^7.1.6", | ||
"jest": "^26.6.3", | ||
"jsdoc-to-markdown": "^7.0.0", | ||
"rollup": "^2.40.0", | ||
"rollup-plugin-eslint": "^7.0.0", | ||
"@babel/core": "^7.17.9", | ||
"@babel/eslint-parser": "^7.17.0", | ||
"@babel/preset-env": "^7.16.11", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-commonjs": "^22.0.0", | ||
"@rollup/plugin-eslint": "^8.0.2", | ||
"@rollup/plugin-node-resolve": "^13.2.1", | ||
"@types/jest": "^27.4.1", | ||
"browserslist": "^4.20.3", | ||
"core-js": "^3.22.2", | ||
"eslint": "^8.14.0", | ||
"glob": "^8.0.1", | ||
"jest": "^28.0.2", | ||
"jsdoc-to-markdown": "^7.1.1", | ||
"rollup": "^2.70.2", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"typescript": "^4.2.3" | ||
"typescript": "^4.6.3" | ||
}, | ||
"dependencies": { | ||
"jest-environment-jsdom": "^28.0.2" | ||
} | ||
} |
@@ -0,8 +1,9 @@ | ||
// @ts-check | ||
/** | ||
* Shorthand for `element.getAttribute` | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to retrieve | ||
* | ||
* @returns {String} - The attribute's value | ||
* @returns {String|null} - The attribute's value | ||
*/ | ||
@@ -16,3 +17,3 @@ export function getAttr( el, attr ) { | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to retrieve | ||
@@ -28,3 +29,3 @@ * @param {String} val - The value to set to the attribute | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to remove | ||
@@ -39,3 +40,3 @@ */ | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {String} attr - The attribute to check the existance of | ||
@@ -42,0 +43,0 @@ * |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
import { byId, query, getAttr, setAttr, remAttr, hasAttr } from '../../dist/matt-utils.min'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
import { forEachHTML } from '../misc/misc'; | ||
@@ -6,3 +7,3 @@ | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to add | ||
@@ -12,5 +13,8 @@ */ | ||
if ( el.length === undefined ) | ||
// @ts-ignore | ||
if ( el.length === undefined ) { | ||
// @ts-ignore | ||
addClassEl( el, ...classes ); | ||
else { | ||
} else { | ||
// @ts-ignore | ||
forEachHTML( el, ( currEl ) => { | ||
@@ -24,3 +28,3 @@ addClassEl( currEl, ...classes ); | ||
* | ||
* @param {Element} elem - An HTML element | ||
* @param {Element|HTMLElement} elem - An HTML element | ||
* @param {...String} remClass - Classes to add | ||
@@ -38,3 +42,3 @@ */ | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to remove | ||
@@ -44,5 +48,8 @@ */ | ||
if ( el.length === undefined ) | ||
// @ts-ignore | ||
if ( el.length === undefined ) { | ||
// @ts-ignore | ||
removeClassEl( el, ...classes ); | ||
else { | ||
} else { | ||
// @ts-ignore | ||
forEachHTML( el, ( currEl ) => { | ||
@@ -56,3 +63,3 @@ removeClassEl( currEl, ...classes ); | ||
* | ||
* @param {Element} elem - An HTML element | ||
* @param {Element|HTMLElement} elem - An HTML element | ||
* @param {...String} remClass - Classes to remove | ||
@@ -74,3 +81,3 @@ */ | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|HTMLCollection|NodeList} el - A list of elements | ||
* @param {...String} classes - Classes to check the presence of | ||
@@ -84,8 +91,11 @@ * | ||
if ( el.length === undefined ) | ||
// @ts-ignore | ||
if ( el.length === undefined ) { | ||
// @ts-ignore | ||
hasCls = hasClassEl( el, ...classes ); | ||
else { | ||
} else { | ||
let numClasses = 0; | ||
// @ts-ignore | ||
forEachHTML( el, ( currEl ) => { | ||
@@ -96,2 +106,3 @@ if ( hasClassEl( currEl, ...classes ) ) | ||
// @ts-ignore | ||
hasCls = numClasses === el.length; | ||
@@ -106,3 +117,3 @@ | ||
* | ||
* @param {Element} elem - An HTML element | ||
* @param {Element|HTMLElement} elem - An HTML element | ||
* @param {...String} hasClasses - Classes to check the presence of | ||
@@ -109,0 +120,0 @@ * |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
import { byId, byClass, query, queryAll, addClass, removeClass, hasClass } from '../../dist/matt-utils.min'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,7 +1,9 @@ | ||
// @ts-check | ||
/** | ||
* Shorthand for `element.addEventListener` | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|Window|Document|MediaQueryList} el - A list of elements | ||
* @param {String} ev - Event's name | ||
* @param {Function} fn - Event's function | ||
* @param {EventListenerOrEventListenerObject} fn - Event's function | ||
* @param {Object} [opts] - Optional event options | ||
@@ -18,5 +20,5 @@ */ | ||
* | ||
* @param {Element|HTMLCollection|NodeList} el - A list of elements | ||
* @param {Element|HTMLElement|Window|Document|MediaQueryList} el - A list of elements | ||
* @param {String} ev - Event's name | ||
* @param {Function} fn - Event's function | ||
* @param {EventListenerOrEventListenerObject} fn - Event's function | ||
* @param {Object} [opts] - Optional event options | ||
@@ -23,0 +25,0 @@ */ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
import { byId, addEvent, removeEvent } from '../../dist/matt-utils.min'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,3 @@ | ||
// @ts-check | ||
/** | ||
@@ -5,5 +7,5 @@ * Foreach polyfill for NodeList and HTMLCollection | ||
* | ||
* @param {Array|NodeList|HTMLCollection} els - A list of elements | ||
* @param {Array<any>|NodeList|HTMLCollection} els - A list of elements | ||
* @param {foreachCB} fn - Callback containing ( value, index ) as arguments | ||
* @param {Scope} [scope] - Scope | ||
* @param {Function} [scope] - Scope | ||
*/ | ||
@@ -19,3 +21,3 @@ export function forEachHTML( els, fn, scope ) { | ||
* @callback foreachCB | ||
* @param {Element} value - The element | ||
* @param {Element|HTMLElement} value - The element | ||
* @param {Number} [index] - The index of the element | ||
@@ -34,2 +36,3 @@ */ | ||
requestAnimationFrame( () => { | ||
// @ts-ignore | ||
fn.call(); | ||
@@ -44,4 +47,4 @@ }); | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element} [topEl=document.body] - Wrapping element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {Element|HTMLElement} [topEl=document.body] - Wrapping element | ||
* | ||
@@ -57,4 +60,4 @@ * @returns {Number} Element's top position | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element} [topEl=document.body] - Wrapping element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* @param {Element|HTMLElement} [topEl=document.body] - Wrapping element | ||
* | ||
@@ -72,3 +75,3 @@ * @returns {Number} Element's left position | ||
* | ||
* @param {Element} el - An HTML element | ||
* @param {Element|HTMLElement} el - An HTML element | ||
* | ||
@@ -81,2 +84,3 @@ * @returns {Number} - The element's index | ||
// @ts-ignore | ||
while ( ( el = el.previousElementSibling ) ) | ||
@@ -83,0 +87,0 @@ index++; |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
import { byId, getElementIndex } from '../../dist/matt-utils.min'; | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
/** | ||
@@ -6,3 +7,3 @@ * Shorthand for `document.getElementById` | ||
* | ||
* @returns {Element|null} - The selected element | ||
* @returns {Element|HTMLElement|null} - The selected element | ||
*/ | ||
@@ -17,5 +18,5 @@ export function byId( id ) { | ||
* @param {String} selClass - The selector's class | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
* @returns {HTMLCollection} - The selected elements | ||
* @returns {HTMLCollectionOf<Element>} - The selected elements | ||
*/ | ||
@@ -31,5 +32,5 @@ export function byClass( selClass, parent = document ) { | ||
* @param {String} selector - Selector | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
* @returns {Element|null} - The selected element | ||
* @returns {Element|HTMLElementTagNameMap|SVGElementTagNameMap|null} - The selected element | ||
*/ | ||
@@ -42,6 +43,6 @@ export function query( selector, parent = document ) { | ||
/** | ||
* Shorthand per `document.querySelectorAll` | ||
* Shorthand for `document.querySelectorAll` | ||
* | ||
* @param {String} selector - Selector | ||
* @param {Element} [parent=document] - Parent element | ||
* @param {Element|HTMLElement|Document} [parent=document] - Parent element | ||
* | ||
@@ -48,0 +49,0 @@ * @returns {NodeList} - The selected element |
@@ -0,1 +1,2 @@ | ||
// @ts-check | ||
import { byId, byClass, query, queryAll } from '../../dist/matt-utils.min'; | ||
@@ -2,0 +3,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53312
18
1336
Yes
1
17
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@jest/environment@28.1.3(transitive)
+ Added@jest/fake-timers@28.1.3(transitive)
+ Added@jest/schemas@28.1.3(transitive)
+ Added@jest/types@28.1.3(transitive)
+ Added@sinclair/typebox@0.24.51(transitive)
+ Added@sinonjs/commons@1.8.6(transitive)
+ Added@sinonjs/fake-timers@9.1.2(transitive)
+ Added@tootallnate/once@2.0.0(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Added@types/istanbul-lib-report@3.0.3(transitive)
+ Added@types/istanbul-reports@3.0.4(transitive)
+ Added@types/jsdom@16.2.15(transitive)
+ Added@types/node@22.9.0(transitive)
+ Added@types/parse5@6.0.3(transitive)
+ Added@types/stack-utils@2.0.3(transitive)
+ Added@types/tough-cookie@4.0.5(transitive)
+ Added@types/yargs@17.0.33(transitive)
+ Added@types/yargs-parser@21.0.3(transitive)
+ Addedabab@2.0.6(transitive)
+ Addedacorn@7.4.18.14.0(transitive)
+ Addedacorn-globals@6.0.0(transitive)
+ Addedacorn-walk@7.2.0(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.05.2.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbrowser-process-hrtime@1.0.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcssom@0.3.80.5.0(transitive)
+ Addedcssstyle@2.3.0(transitive)
+ Addeddata-urls@3.0.2(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddecimal.js@10.4.3(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddomexception@4.0.0(transitive)
+ Addedescape-string-regexp@2.0.0(transitive)
+ Addedescodegen@2.1.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@5.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhtml-encoding-sniffer@3.0.0(transitive)
+ Addedhttp-proxy-agent@5.0.0(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-potential-custom-element-name@1.0.1(transitive)
+ Addedjest-environment-jsdom@28.1.3(transitive)
+ Addedjest-message-util@28.1.3(transitive)
+ Addedjest-mock@28.1.3(transitive)
+ Addedjest-util@28.1.3(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsdom@19.0.0(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.1.3(transitive)
+ Addednwsapi@2.2.13(transitive)
+ Addedparse5@6.0.1(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedpretty-format@28.1.3(transitive)
+ Addedpsl@1.10.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedquerystringify@2.2.0(transitive)
+ Addedreact-is@18.3.1(transitive)
+ Addedrequires-port@1.0.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsaxes@5.0.1(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedstack-utils@2.0.6(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedsymbol-tree@3.2.4(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedtough-cookie@4.1.4(transitive)
+ Addedtr46@3.0.0(transitive)
+ Addedtype-detect@4.0.8(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addeduniversalify@0.2.0(transitive)
+ Addedurl-parse@1.5.10(transitive)
+ Addedw3c-hr-time@1.0.2(transitive)
+ Addedw3c-xmlserializer@3.0.0(transitive)
+ Addedwebidl-conversions@7.0.0(transitive)
+ Addedwhatwg-encoding@2.0.0(transitive)
+ Addedwhatwg-mimetype@3.0.0(transitive)
+ Addedwhatwg-url@10.0.011.0.0(transitive)
+ Addedws@8.18.0(transitive)
+ Addedxml-name-validator@4.0.0(transitive)
+ Addedxmlchars@2.2.0(transitive)