codeschmiede-toolkit v1.2.0
codeSchmiede A/B Testing Toolkit
Getting started
This toolkit is designed to help you creating A/B tests. Have fun using it!
Questions or feedback? team@codeschmiede.de
Install
$ npm install codeschmiede-toolkit$ yarn add codeschmiede-toolkitUsage Example
import { waitFor } from 'codeschmiede-toolkit';
waitFor('#example', (example) => {
// do something...
});Helper
waitFor
The waitFor function is using document.querySelector() internally.
waitFor('.example', (example) => {
// do something...
});waitFor is also working with a function as a selector.
waitFor(
() => return window.example === true,
() => {
// do something...
}
);waitForSync
(async () => {
const body = await waitForSync("body");
// do something...
})();ready
The ready function is using the DOMContentLoaded Event.
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.
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.
const nodeList = qsa('.example');
// do something...
[...nodeList].forEach(item => { ... });addClass
The addClass function is just a wrapper for element.classList.add.
addClass(element, 'classNameToAdd');removeClass
The removeClass function is just a wrapper for element.classList.remove.
removeClass(element, 'classNameToAdd');Utils
isMobile
const isMobileDevice = isMobile();
if(isMobileDevice){
// do something for mobile traffic...
} else {
// do something for desktop traffic...
}getWidth
const browserWidth = getWidth();
// do something...getCookie
const myCookkie = getCookie('myCookie');
// do something...setCookie
setCookie ('myCookie', 'myValue', 90);
// do something...License
Copyright (c) 2024 codeSchmiede GmbH & Co. KG.
Licensed under The MIT License (MIT).