A/B Test Development Toolkit
sh
$ npm install codeschmiede-toolkit
`
`sh
$ yarn add codeschmiede-toolkit
`
Usage Example
`js
import { waitFor } from 'codeschmiede-toolkit';
waitFor('#example', (example) => {
// do something...
});
`
Helper
waitFor
The waitFor function is using document.querySelector() internally.
`js
waitFor('.example', (example) => {
// do something...
});
`
waitFor is also working with a function as a selector.
`js
waitFor(
() => return window.example === true,
() => {
// do something...
}
);
`
waitForSync
`js
(async () => {
const body = await waitForSync("body");
// do something...
})();
`
ready
The ready function is using the DOMContentLoaded Event.
`js
ready(() => {
// do something...
});
`
Wrapper
qs
The qs function is just a wrapper for document.querySelector().
> An Element object representing the first element in the document that matches the specified set of CSS selectors, or null is returned if there are no matches.
`js
const node = qs('#example');
// do something...
node.textContent = 'My new text...';
`
qsa
The qsa function is just a wrapper for document.querySelectorAll().
> A non-live NodeList containing one Element object for each element that matches at least one of the specified selectors or an empty NodeList in case of no matches.
`js
const nodeList = qsa('.example');
// do something...
[...nodeList].forEach(item => { ... });
`
addClass
The addClass function is just a wrapper for element.classList.add.
`js
addClass(element, 'classNameToAdd');
`
removeClass
The removeClass function is just a wrapper for element.classList.remove.
`js
removeClass(element, 'classNameToAdd');
`
Utils
isMobile
`js
const isMobileDevice = isMobile();
if(isMobileDevice){
// do something for mobile traffic...
} else {
// do something for desktop traffic...
}
`
getWidth
`js
const browserWidth = getWidth();
// do something...
`
getCookie
JavaScript Cookies
`js
const myCookkie = getCookie('myCookie');
// do something...
`
setCookie
JavaScript Cookies
`js
setCookie ('myCookie', 'myValue', 90);
// do something...
``