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

tfwm-cookies

v1.1.0

Published

Logic to assist with users cookie preferences on Transport for West Midlands website and services.

Downloads

1

Readme

TfWM Cookies

Logic to assist with users cookie preferences on Transport for West Midlands website and services.

Installation

Install tfwm-cookies with npm

  npm install tfwm-cookies

Features

  • Contains 3 core libraries cookieBanner, manageCookies and cookiePolicyLogic
  • Contains 1 helper method getCookiePolicy
  • Automatically injects TfWM's Google Tag Manager and Hotjar code if user has correct cookie preferences
  • Allows for third-party libraries to be restricted unless a user has enabled a specific cookie preference

Umbraco header and footer

If you are using the Umbraco header and footer script:

<script src="//tfwm.org.uk/scripts/header-footer.min.js"></script>

Then you will not need to use this library for the cookieBanner and getCookiePolicy methods as it comes included.

cookieBanner method

Example

import { cookieBanner } from 'tfwm-cookies';

window.addEventListener('load', () => {
  cookieBanner();
});

About

You should use this method when you have TfWM's design system Cookie banner on your webpage or service.

  • Will show/hide the Cookie banner based on if the user has accepted cookies or not
  • If the user clicks (or uses accepted keyboard methods such as pressing enter or space) the Accept all cookies button within the Cookie banner:
    • It will mark all cookie preferences (essential, functional, performance) within the cookie cookie-policy as true
    • Sets a new cookie called cookies-preferences to true
    • Will then re-run the cookiePolicyLogic method
    • Finally, hide the Cookie banner

manageCookies method

Example

import { manageCookies } from 'tfwm-cookies';

window.addEventListener('load', () => {
  manageCookies();
});

About

This method should only be used on a page that has TfWM's design system Manage cookies form within it, such as TfWM's main manage cookie page.

  • Tracks if a checkbox is checked within Manage cookies form
  • When a user presses/clicks the Save preferences button:
    • It will then update the cookie preferences (essential, functional, performance) based on the checkboxes checked
    • If a user has unchecked the performance checkbox and then presses the Save preferences button then all cookies that start with _ (usually third party services such as Google Tag Manager and Hotjar) will be deleted
    • Will then re-run the cookiePolicyLogic method

cookiePolicyLogic method

Example

import { cookiePolicyLogic } from 'tfwm-cookies';

window.addEventListener('load', () => {
  cookiePolicyLogic();
});

About

This is the core cookie logic that assists with the cookieBanner and manageCookies methods. If you are not using TfWM's design system Cookie banner and Manage cookies, then this method can be used on its own.

  • Automatically injects TfWM's Google Tag Manager and Hotjar code if the cookie-policy cookie has the performance field set to true
  • By calling this method, it enables you to add third party or custom code but restrict it from running unless a certain cookie has been set
    • To use this on custom or third party code, you need to:
      • Change the type so it is plain/text (this stops the code running on page load)
      • Add the attribute data-cookiescript="accepted" (this is what is used to find your restricted scripts on the page)
      • Add the attribute data-cookiecategory which can be of three values "functional" | "essential" | "performance". This will map to the fields
    • An example of the API is...
    <script type="plain/text" data-cookiescript="accepted" data-cookiecategory="functional">
      console.log('test');
    </script>

Usage/Examples

import { cookieBanner, manageCookies, cookiePolicyLogic } from 'tfwm-cookies';

// Wait until everything is loaded
window.addEventListener('load', () => {
  cookieBanner();
  manageCookies();
  cookiePolicyLogic();
});

Available Scripts for contributing

npm start

Runs the app in the development mode. Open http://localhost:8080 to view it in the browser.

The page will reload if you make edits. You will also see any lint errors in the console.

npm run build

Builds a static copy of your site to the build/ folder. Your app is ready to be deployed!

For the best production performance: Add a build bundler plugin like @snowpack/plugin-webpack or snowpack-plugin-rollup-bundle to your snowpack.config.mjs config file.

Q: What about Eject?

No eject needed! Snowpack guarantees zero lock-in, and CSA strives for the same.