@splidejs/utils
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -56,31 +56,11 @@ "use strict"; | ||
} | ||
function toggleClass(elm, classes, force) { | ||
if (elm) { | ||
forEach(isString(classes) ? classes.split(" ") : classes, (className) => { | ||
className && elm.classList.toggle(className, force); | ||
}); | ||
function assert(assertion, message) { | ||
if (!assertion) { | ||
throw new Error(message); | ||
} | ||
} | ||
function addClass(elm, classes) { | ||
toggleClass(elm, classes, true); | ||
const error = console.error; | ||
function abstractMethod() { | ||
assert(0, "Abstract!"); | ||
} | ||
function append(parent, ...children2) { | ||
parent && parent.append(...children2); | ||
} | ||
function before(ref, ...nodes) { | ||
ref && ref.before(...nodes); | ||
} | ||
function matches(elm, selector) { | ||
return isHTMLElement(elm) && elm.matches(selector); | ||
} | ||
function children(parent, selector) { | ||
const children2 = parent ? slice(parent.children) : []; | ||
return selector ? children2.filter((child2) => matches(child2, selector)) : children2; | ||
} | ||
function child(parent, selector) { | ||
return selector ? children(parent, selector)[0] : parent.firstElementChild; | ||
} | ||
function closest(from, selector) { | ||
return from.closest(selector); | ||
} | ||
const assign = Object.assign; | ||
@@ -115,2 +95,37 @@ const ownKeys = Object.keys; | ||
} | ||
function inherit(child2, parent) { | ||
return assign(Object.create(parent), child2); | ||
} | ||
function parseOption(option, defaults) { | ||
return option === false || option === null ? false : merge({}, defaults || {}, isObject(option) ? option : {}); | ||
} | ||
function toggleClass(elm, classes, force) { | ||
if (elm) { | ||
forEach(isString(classes) ? classes.split(" ") : classes, (className) => { | ||
className && elm.classList.toggle(className, force); | ||
}); | ||
} | ||
} | ||
function addClass(elm, classes) { | ||
toggleClass(elm, classes, true); | ||
} | ||
function append(parent, ...children2) { | ||
parent && parent.append(...children2); | ||
} | ||
function before(ref, ...nodes) { | ||
ref && ref.before(...nodes); | ||
} | ||
function matches(elm, selector) { | ||
return isHTMLElement(elm) && elm.matches(selector); | ||
} | ||
function children(parent, selector) { | ||
const children2 = parent ? slice(parent.children) : []; | ||
return selector ? children2.filter((child2) => matches(child2, selector)) : children2; | ||
} | ||
function child(parent, selector) { | ||
return selector ? children(parent, selector)[0] : parent.firstElementChild; | ||
} | ||
function closest(from, selector) { | ||
return from.closest(selector); | ||
} | ||
function removeAttribute(elms, attrs) { | ||
@@ -256,7 +271,2 @@ forEach(elms, (elm) => { | ||
} | ||
function assert(assertion) { | ||
if (!assertion) { | ||
throw new Error(); | ||
} | ||
} | ||
function EventBinder(removersRef) { | ||
@@ -419,2 +429,3 @@ const removers = removersRef || /* @__PURE__ */ new Set(); | ||
exports.abs = abs; | ||
exports.abstractMethod = abstractMethod; | ||
exports.addClass = addClass; | ||
@@ -424,2 +435,3 @@ exports.append = append; | ||
exports.approximatelyEqual = approximatelyEqual; | ||
exports.assert = assert; | ||
exports.assign = assign; | ||
@@ -440,2 +452,3 @@ exports.before = before; | ||
exports.empty = empty; | ||
exports.error = error; | ||
exports.find = find; | ||
@@ -450,2 +463,3 @@ exports.floor = floor; | ||
exports.includes = includes; | ||
exports.inherit = inherit; | ||
exports.isArray = isArray; | ||
@@ -470,2 +484,3 @@ exports.isBoolean = isBoolean; | ||
exports.parseHtml = parseHtml; | ||
exports.parseOption = parseOption; | ||
exports.prevent = prevent; | ||
@@ -472,0 +487,0 @@ exports.push = push; |
@@ -54,31 +54,11 @@ function empty(array) { | ||
} | ||
function toggleClass(elm, classes, force) { | ||
if (elm) { | ||
forEach(isString(classes) ? classes.split(" ") : classes, (className) => { | ||
className && elm.classList.toggle(className, force); | ||
}); | ||
function assert(assertion, message) { | ||
if (!assertion) { | ||
throw new Error(message); | ||
} | ||
} | ||
function addClass(elm, classes) { | ||
toggleClass(elm, classes, true); | ||
const error = console.error; | ||
function abstractMethod() { | ||
assert(0, "Abstract!"); | ||
} | ||
function append(parent, ...children2) { | ||
parent && parent.append(...children2); | ||
} | ||
function before(ref, ...nodes) { | ||
ref && ref.before(...nodes); | ||
} | ||
function matches(elm, selector) { | ||
return isHTMLElement(elm) && elm.matches(selector); | ||
} | ||
function children(parent, selector) { | ||
const children2 = parent ? slice(parent.children) : []; | ||
return selector ? children2.filter((child2) => matches(child2, selector)) : children2; | ||
} | ||
function child(parent, selector) { | ||
return selector ? children(parent, selector)[0] : parent.firstElementChild; | ||
} | ||
function closest(from, selector) { | ||
return from.closest(selector); | ||
} | ||
const assign = Object.assign; | ||
@@ -113,2 +93,37 @@ const ownKeys = Object.keys; | ||
} | ||
function inherit(child2, parent) { | ||
return assign(Object.create(parent), child2); | ||
} | ||
function parseOption(option, defaults) { | ||
return option === false || option === null ? false : merge({}, defaults || {}, isObject(option) ? option : {}); | ||
} | ||
function toggleClass(elm, classes, force) { | ||
if (elm) { | ||
forEach(isString(classes) ? classes.split(" ") : classes, (className) => { | ||
className && elm.classList.toggle(className, force); | ||
}); | ||
} | ||
} | ||
function addClass(elm, classes) { | ||
toggleClass(elm, classes, true); | ||
} | ||
function append(parent, ...children2) { | ||
parent && parent.append(...children2); | ||
} | ||
function before(ref, ...nodes) { | ||
ref && ref.before(...nodes); | ||
} | ||
function matches(elm, selector) { | ||
return isHTMLElement(elm) && elm.matches(selector); | ||
} | ||
function children(parent, selector) { | ||
const children2 = parent ? slice(parent.children) : []; | ||
return selector ? children2.filter((child2) => matches(child2, selector)) : children2; | ||
} | ||
function child(parent, selector) { | ||
return selector ? children(parent, selector)[0] : parent.firstElementChild; | ||
} | ||
function closest(from, selector) { | ||
return from.closest(selector); | ||
} | ||
function removeAttribute(elms, attrs) { | ||
@@ -254,7 +269,2 @@ forEach(elms, (elm) => { | ||
} | ||
function assert(assertion) { | ||
if (!assertion) { | ||
throw new Error(); | ||
} | ||
} | ||
function EventBinder(removersRef) { | ||
@@ -418,2 +428,3 @@ const removers = removersRef || /* @__PURE__ */ new Set(); | ||
abs, | ||
abstractMethod, | ||
addClass, | ||
@@ -423,2 +434,3 @@ append, | ||
approximatelyEqual, | ||
assert, | ||
assign, | ||
@@ -439,2 +451,3 @@ before, | ||
empty, | ||
error, | ||
find, | ||
@@ -449,2 +462,3 @@ floor, | ||
includes, | ||
inherit, | ||
isArray, | ||
@@ -469,2 +483,3 @@ isBoolean, | ||
parseHtml, | ||
parseOption, | ||
prevent, | ||
@@ -471,0 +486,0 @@ push, |
@@ -8,7 +8,1 @@ /** | ||
export declare function forEachEvent(events: string | string[], iteratee: (event: string) => void): void; | ||
/** | ||
* Throws an error when `assertion` is falsy. | ||
* | ||
* @param assertion - Set a falsy value to throw an error. | ||
*/ | ||
export declare function assert(assertion: boolean): void; |
export * from './array'; | ||
export * from './arrayLike'; | ||
export * from './component'; | ||
export * from './dom'; | ||
export * from './error'; | ||
export * from './function'; | ||
@@ -5,0 +7,0 @@ export * from './html'; |
{ | ||
"name": "@splidejs/utils", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"main": "dist/splide-utils.cjs.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/splide-utils.esm.js", |
73975
89
1856