-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(changelog): bumping version to 2.0.8
- Loading branch information
Showing
3 changed files
with
40 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
import isDom from 'is-dom'; | ||
|
||
const errorSelector = 'Selector does not exists in the DOM'; | ||
const queryType = { | ||
single: true, | ||
multiple: false, | ||
single: true, | ||
multiple: false, | ||
}; | ||
const isNanOrInfinite = (el, selector) => { | ||
const result = [ | ||
Number.isNaN(el), | ||
Number.isNaN(selector), | ||
Number.isFinite(el), | ||
Number.isFinite(selector), | ||
]; | ||
return result.some(x => x); | ||
const result = [ | ||
Number.isNaN(el), | ||
Number.isNaN(selector), | ||
Number.isFinite(el), | ||
Number.isFinite(selector), | ||
]; | ||
return result.some(x => x); | ||
}; | ||
const errorHanler = (isSingle, { el, selector }) => { | ||
const root = document.querySelector(el); | ||
const isNan = isNanOrInfinite(el, selector); | ||
if (isNan && isNan.toString().length !== 0) { | ||
throw new Error(errorSelector); | ||
} else if (isSingle) { | ||
const root = document.querySelector(el); | ||
const isNan = isNanOrInfinite(el, selector); | ||
if (isNan && isNan.toString().length !== 0) { | ||
throw new Error(errorSelector); | ||
} | ||
else if (isSingle) { | ||
return selector ? | ||
isDom(root.querySelector(selector)) : | ||
isDom(root); | ||
} | ||
return selector ? | ||
isDom(root.querySelector(selector)) : | ||
isDom(root); | ||
} | ||
return selector ? | ||
isDom(...root.querySelectorAll(selector)) : | ||
isDom(...Array.from(document.querySelectorAll(el))); | ||
isDom(...root.querySelectorAll(selector)) : | ||
isDom(...Array.from(document.querySelectorAll(el))); | ||
}; | ||
const core = (type, ...args) => { | ||
const isSingle = type === queryType.single; | ||
const [el, selector] = args; | ||
const root = document.querySelector(el); | ||
if (errorHanler(isSingle, { el, selector })) { | ||
if (selector) { | ||
return isSingle ? root.querySelector(selector) : [...root.querySelectorAll(selector)]; | ||
const isSingle = type === queryType.single; | ||
const [el, selector] = args; | ||
const root = document.querySelector(el); | ||
if (errorHanler(isSingle, { el, selector })) { | ||
if (selector) { | ||
return isSingle ? root.querySelector(selector) : [...root.querySelectorAll(selector)]; | ||
} | ||
return isSingle ? root : Array.from(document.querySelectorAll(el)); | ||
} | ||
return isSingle ? root : Array.from(document.querySelectorAll(el)); | ||
} | ||
throw new Error(errorSelector); | ||
throw new Error(errorSelector); | ||
}; | ||
const $ = (el, selector) => core(queryType.single, el, selector); | ||
const $$ = (el, selector) => core(queryType.multiple, el, selector); | ||
export { $, $$ }; | ||
export { $, $$, }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters