npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

codeschmiede-toolkit

v1.1.0

Published

A/B Test Development Toolkit

Downloads

54

Readme

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? [email protected]

Install

$ npm install codeschmiede-toolkit
$ yarn add codeschmiede-toolkit

Usage 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...
})();

share

If you want to share JavaScript code between multiple files, you can use the share function.

// file: global.js
share("globalFunc", () => {
    console.log("da");
});
// file: variation.js
window.CS_TOOLKIT.globalFunc();

The share function returns window.CS_TOOLKIT, if you want to use it directly.

exec

// file: variation.js
exec('globalFunc', ['param_a', 'param_b']);

ready

The ready function is using the DOMContentLoaded Event.

ready(() => {
    // do something...
});

punshout

The punshout function executes your callback function, if the breakpoint is lower as specified, in the example 1024px.

punshout(1024, () => {
    // do something... 
    // ...exclude visitor from your experiment
});

pushHistory

pushHistory('myStep');

persistElem

The persistElem function automatically checks if your new element still exists each 50 ms. If not, your callback function is executed again. After 2.5 seconds the function terminates itself.

/**
 * persistElem
 * 
 * @param {string} selector 
 * @param {function} callback 
 * @param {number} runs [optional]
 * @param {number} speed  [optional]
 */
persistElem('my-new-element', async (resolve, reject) => {

    try {

        const target = await waitForSync('header');
        target.insertAdjacentHTML('afterbegin', 
            '<my-new-element>example</my-new-element>'
        );
        resolve();
    } catch(err) {
        reject();
    }
});

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 => { ... });

Utils

scrollTo

const scrollToPosition = 2000;
const scrollSpeed = 500;

scrollTo(scrollToPosition, scrollSpeed);

isMobile

const isMobileDevice = isMobile();

if(isMobileDevice){
    // do something for mobile traffic...
} else {
    // do something for desktop traffic...
}

getWidth

const browserWidth = getWidth();
// do something...

getCookie

JavaScript Cookies

const myCookkie = getCookie('myCookie');
// do something...

getStore

getStore('csExampleObject');
getStore('csExampleObject', 'csExampleKey');

setStore

setStore('csExampleObject', 'csExampleKey', 'csExampleValue');

License

Copyright (c) 2022 codeSchmiede GmbH & Co. KG.

Licensed under The MIT License (MIT).

codeSchmiede GmbH & Co. KG

codeSchmiede Logo