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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@oslokommune/cookie-consent

v2.0.1

Published

Cookie consent for Oslo kommune

Readme

Cookie Consent

Install

Run npm install @oslokommune/cookie-consent

Methods

import { CookieConsent } from '@oslokommune/cookie-consent'

const googleAnalyticsId = 123;
const hotjarId = 456;

const cookieConsentConfig = {
  cookies: {
    domain: 'localhost',
    secure: true,
    expiryDays: 90
  },
  services: {
    adapters: [
      {
        name: 'google-analytics',
        consentKey: 'statistics',
        data: {
          id: googleAnalyticsId,
          options: {
            anonymize_ip: true,
          }
        }
      },
      {
        name: 'hotjar',
        consentKey: 'survey',
        data: {
          id: hotjarId
        }
      },
      {
        name: 'functional',
        consentKey: 'functional'
      }
    ]
  },
  logging: {
    adapters: [
      {
        adapter: 'console' // for debug only
      },
      {
        adapter: 'http',
        config: {
          store: {
            endpoint: 'url_to_store_logging_endpoint'
          }
        }
      }
    ]
  }
};
const cookieConsent = new CookieConsent(cookieConsentConfig);

// Set a consentCookie
try {
  await cookieConsent.setConsentCookie([
    {
      "name": "survey",
      "consent": true
    },
    {
      "name": "statistics",
      "constent": true
    },
    {
      "name": "functional",
      "consent": true
    }
  ]);

  // Toggle services on/off based on consents
  cookieConsent.toggleServices(cookieConsent.getConsentCookie());
} catch (error) {
  // Handle error
}

// Get a consentCookie
const consent = cookieConsent.getConsentCookie();
console.log(consent)
// items: ConsentItem[]
// checksum: string
// uuid: string

// Delete a consentCookie
cookieConsent.deleteConsentCookie();

// Validate consentCookie, toggle services or init cookie banner for user
try {
  const validation = await cookieConsent.validateConsentCookie();
  if (validation) {
    cookieConsent.toggleServices(cookieConsent.getConsentCookie());
  } else {
    // Init cookie consent banner
  }
} catch (error) {
  // Handle error
}

cookieConsent.toggleServices(consentObject: ConsentObject);
cookieConsent.enableAllServices(consentObject: ConsentObject);
cookieConsent.disableAllServices(consentObject: ConsentObject);

Events

All events are emitted through the CookieEvents bus from CookieManager.

import { CookieEvents } from 'cookie-manager'

function toogleMyFunctionalCookies(payload) {
  if (payload.consent) {
    // 
  }
}

CookieEvents.on('CookieConsent.functionalCookies', toggleMyFunctionalCookies)
  • CookieConsent.set => ConsentObject
  • CookieConsent.get => ConsentObject
  • CookieConsent.delete => void
  • CookieConsent.validate => bool
  • CookieConsent.functionalCookies => { consent: bool }

Services

Any ConsentItem in ConsentObject whos name matches the consentKey in an adapter will be toggled if any change is made.

Adapters

Google analytics

// Pass google analytics id in as configuration to CookieConsent, if null or not set google analytics adapter will be disabled

const config = {
  services: {
    serviceIds: {
      adapters: [
      {
        name: 'google-analytics',
        consentKey: 'statistics',
        data: {
          id: googleAnalyticsId,
          options: {
            anonymize_ip: true,
          }
        }
      },
      ...

HotJar

// Pass hotjar id in as configuration to CookieConsent, if null or not set hotjar adapter will be disabled

const config = {
  services: {
    adapters: [
      {
        name: 'hotjar',
        consentKey: 'survey',
        data: {
          id: hotjarId
        }
      },

Functional

import { CookieEvents } from 'cookie-manager'

function toogleMyFunctionalCookies(payload) {
  if (payload.consent) {
    // Enable functional cookies here
  } else {
    // Disable functional cookies here
  }
}

// Emits event on enable / disable
CookieEvents.on('CookieConsent.functionalCookies', toggleMyFunctionalCookies)