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

cookify

v3.1.0

Published

Simple, customizable open source cookie consent banner for GDPR law

Downloads

15

Readme

NPM Downloads NPM Github Code Size GitHub License

Cookify

General info

This is a simple full customizable cookie consent banner for gdpr law. This library is build on pure javascript for easy customization. You can choose your own CSS Framework, your own styles and only need to define query selectors.

Live preview

View the test file live on GitHub Pages with clicking here.

Documentation

Get started

To start with that project you can simple install Cookify with npm.

npm install cookify

After that you need to import the npm module correctly. How you need to import the npm correctly to your project depends on you. I will give an simple example for importing a npm module and how to initialize it in ordner to use the functions correctly.

import Cookify from Cookify

var cookify = new Cookify

For customization you can inicialize Cookify with the following variables or functions described below. Every variable and function has a default value that you don't need to set it. But you need to watch on the described sheme in order to inicialize correctly.

var cookify = new Cookify(
    dataName,
    actionCallback,
    trackingCallback,
    saveWithChange,
    saveByDefault,
    cookieDefault,
    initCallback
)

dataName -> string (default: cookify)
actionCallback -> function (default: () => {})
trackingCallback -> function (default: () => {})
saveWithChange -> boolean (default: false)
saveByDefault -> boolean (default: false)
cookieDefault -> string (default: necessary)
initCallback -> function (default: () => {})

To explain the initialization better i will give a simple example with all variables and functions and how to use them. dataName is for the name that will show in the data storage for Cookify. The actionCallback is called after the user clicked on the following data-c-action fields. With that function you can close the cookie consent field as an example. Then you have the function trackingCallback for tracking user activity. This function needs a data variable where the data[0] stores all types and the viewed state and data[1] stores the actual date. saveWithChange can be set if you want to change the user selection when clicking on the input fields. The saveByDefault variable is for saving the selection when loading the first time. Then we have the cookieDefault variable where you can set the default cookie type name. At last we have the initCallback function that can for example be used to determine if the consent dialog should be shown after Cookify did its initialization.

var cookify = new Cookify('cookie_consent', function () {
    document.getElementById('element').style.display = 'none'
  }, function (data) {
    console.log(data)
  }, false, false, 'necessary',
    function(cookify) {
        //show the cookie popup as long as the user has not seen it
        if (cookify.getDataState(cookify.viewedName)) {
            document.getElementById('element').style.display = 'none';
        } else {
            document.getElementById('element').style.display = 'block';
        }
    }
)

Query Names

The query names are necessary for using Cookify. There are different checkboxes for controlling the cookie activity and you can handle the cookies with a few different actions. Below are all usable query names and how to use them properly.

You can only use the data-c-check on input fields. As an example for type checkbox.

data-c-check="{string}"

<input data-c-check="necessary" type="checkbox">

You are able to set a preset value of the field. When you don't set this default value it is false.

data-c-check-default="{boolean}" (default: false)

<input data-c-check="necessary" data-c-check-default="true" type="checkbox">

You have 3 ways to for saving. Use accept when you want the user to save the selected fields, all will select all fields and save them and necessary is for selecting only the necessary field.

data-c-action="{string}"

  • necessary (Save only the required cookies)
<div data-c-action="necessary">Necessary</div>
  • all (Save the selected cookies)
<div data-c-action="all">All</div>
  • accept (Save all cookies)
<div data-c-action="necessary">Necessary</div>

Enabling or disabling content

Scripts

That you are able to handle the scripts for the user selected types you need to set data-c-script where it is necessary. It is only possible to use the types that are used in the query names data-c-check. This will either work for scripts with import src or with inline scripts.

data-c-script="{string}"

<script type="text/plain" src="example.js" data-c-script="necessary"></script>

<script type="text/plain" data-c-script="necessary">
  console.log(example)
</script>

Iframes and Images

Instead of changing the type Cookify will switch the src element of iframe or img tags depending on the consent given. For that data-c-fallback (used if no consent was given) and data-c-src (used if consent was given) need to be set. The data-c-script attribute will be used to determine the category as for scripts. It is recommended to set the src already to the fallback to avoid connections before cookify is initialized.

<img data-c-script="necessary" src="/path/to/fallback.jpg" data-c-fallback="/path/to/fallback.jpg" data-c-src="/example.jpg"/>

<iframe data-c-script="necessary" src="about:blank" data-c-fallback="about:blank" data-c-src="https://example.org"></iframe>

Helpers

When you want to know the exact state of a type or if the user viewed and agreed the consent already then use the getDataState() function. The output is a boolean value (true or false).

cookify.getDataState('type')

cookify.getDataState(cookify.viewedName)

Changelog

Please see CHANGELOG for more information what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.