Socket
Socket
Sign inDemoInstall

@use-cookie-consent/core

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@use-cookie-consent/core - npm Package Compare versions

Comparing version 0.3.6 to 0.4.0-dev.0

2

build/cjs/index.js

@@ -15,3 +15,3 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)},r={exports:{}};

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */e=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function o(){}function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({path:"/"},o.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var c=JSON.stringify(n);/^[\{\[]/.test(c)&&(n=c)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var u in i)i[u]&&(s+="; "+u,!0!==i[u]&&(s+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+s}}function c(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],c=0;c<i.length;c++){var s=i[c].split("="),u=s.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var a=t(s[0]);if(u=(r.read||r)(u,a)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(o[a]=u,e===a)break}catch(e){}}return e?o[e]:o}}return o.set=i,o.get=function(e){return c(e,!1)},o.getJSON=function(e){return c(e,!0)},o.remove=function(t,n){i(t,"",e(n,{expires:-1}))},o.defaults={},o.withConverter=n,o}((function(){}))},r.exports=e();var o={necessary:!0},i=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}};exports.useCookieConsent=function(e){var c=r.exports.getJSON("USE_COOKIE_CONSENT_STATE")||(null==e?void 0:e.defaultConsent)||o,s=t.useState(c),u=s[0],a=s[1];t.useEffect((function(){(null==u?void 0:u.necessary)&&r.exports.set("USE_COOKIE_CONSENT_STATE",u,null==e?void 0:e.consentCookieAttributes)}),[u]);var p={set:function(e,t,n,o){if(function(e,t){return!!(t&&t[e.duration]&&t[e.provenance]&&t[e.purpose])}(n,u))return r.exports.set(e,t,o)},get:r.exports.get,getAll:r.exports.get,getJSON:r.exports.getJSON,getAllJSON:r.exports.getJSON,remove:r.exports.remove};return{consent:u,acceptCookies:function(e,t){(null==t?void 0:t.allowChangingNecessary)?a(e):a(n(n({},e),{necessary:!0}))},declineAllCookies:function(){a(i(!1))},acceptAllCookies:function(){a(i(!0))},didAcceptAll:function(){return Object.keys(u||{}).reduce((function(e,t){return e&&u&&u[t]||!1}),!0)},didDeclineAll:function(e){return Object.keys(u||{}).reduce((function(t,n){return(null==e?void 0:e.includingNecessary)||"necessary"!==n?t&&u&&!u[n]||!1:t}),!0)},cookies:p}};
***************************************************************************** */e=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function o(){}function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({path:"/"},o.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var c=JSON.stringify(n);/^[\{\[]/.test(c)&&(n=c)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var u in i)i[u]&&(s+="; "+u,!0!==i[u]&&(s+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+s}}function c(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],c=0;c<i.length;c++){var s=i[c].split("="),u=s.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var a=t(s[0]);if(u=(r.read||r)(u,a)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(o[a]=u,e===a)break}catch(e){}}return e?o[e]:o}}return o.set=i,o.get=function(e){return c(e,!1)},o.getJSON=function(e){return c(e,!0)},o.remove=function(t,n){i(t,"",e(n,{expires:-1}))},o.defaults={},o.withConverter=n,o}((function(){}))},r.exports=e();var o={necessary:!0},i=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}};exports.useCookieConsent=function(e){var c=void 0!==e&&"storage"in e,s=(c?JSON.parse(null==e?void 0:e.storage.getItem("USE_COOKIE_CONSENT_STATE")):r.exports.getJSON("USE_COOKIE_CONSENT_STATE"))||(null==e?void 0:e.defaultConsent)||o,u=t.useState(s),a=u[0],l=u[1];t.useEffect((function(){(null==a?void 0:a.necessary)&&((null==a?void 0:a.necessary)&&c?e.storage.setItem("USE_COOKIE_CONSENT_STATE",JSON.stringify(a)):r.exports.set("USE_COOKIE_CONSENT_STATE",a,null==e?void 0:e.consentCookieAttributes))}),[a]);var p=function(e,t){(null==t?void 0:t.allowChangingNecessary)?l(e):l(n(n({},e),{necessary:!0}))},f=function(){l(i(!1))},d=function(){l(i(!0))},g=function(){return Object.keys(a||{}).reduce((function(e,t){return e&&a&&a[t]||!1}),!0)},v=function(e){return Object.keys(a||{}).reduce((function(t,n){return(null==e?void 0:e.includingNecessary)||"necessary"!==n?t&&a&&!a[n]||!1:t}),!0)},C={set:function(e,t,n,o){if(function(e,t){return!!(t&&t[e.duration]&&t[e.provenance]&&t[e.purpose])}(n,a))return r.exports.set(e,t,o)},get:r.exports.get,getAll:r.exports.get,getJSON:r.exports.getJSON,getAllJSON:r.exports.getJSON,remove:r.exports.remove};return c?{consent:a,acceptCookies:p,declineAllCookies:f,acceptAllCookies:d,didAcceptAll:g,didDeclineAll:v,storage:e.storage}:{consent:a,acceptCookies:p,declineAllCookies:f,acceptAllCookies:d,didAcceptAll:g,didDeclineAll:v,cookies:C}};
//# sourceMappingURL=index.js.map

@@ -1,3 +0,3 @@

import { CookieConsent } from './types';
import { ConsentState } from './types';
export declare const COOKIE_CONSENT_KEY = "USE_COOKIE_CONSENT_STATE";
export declare const DEFAULT_CONSENT: CookieConsent;
export declare const DEFAULT_CONSENT: ConsentState;

@@ -15,3 +15,3 @@ import{useState as e,useEffect as t}from"react";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var n,r=function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)},o={exports:{}};n=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function o(){}function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({path:"/"},o.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var c=JSON.stringify(n);/^[\{\[]/.test(c)&&(n=c)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var u in i)i[u]&&(s+="; "+u,!0!==i[u]&&(s+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+s}}function c(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],c=0;c<i.length;c++){var s=i[c].split("="),u=s.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var a=t(s[0]);if(u=(r.read||r)(u,a)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(o[a]=u,e===a)break}catch(e){}}return e?o[e]:o}}return o.set=i,o.get=function(e){return c(e,!1)},o.getJSON=function(e){return c(e,!0)},o.remove=function(t,n){i(t,"",e(n,{expires:-1}))},o.defaults={},o.withConverter=n,o}((function(){}))},o.exports=n();var i={necessary:!0},c=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}},s=function(n){var s=o.exports.getJSON("USE_COOKIE_CONSENT_STATE")||(null==n?void 0:n.defaultConsent)||i,u=e(s),a=u[0],p=u[1];t((function(){(null==a?void 0:a.necessary)&&o.exports.set("USE_COOKIE_CONSENT_STATE",a,null==n?void 0:n.consentCookieAttributes)}),[a]);var f={set:function(e,t,n,r){if(function(e,t){return!!(t&&t[e.duration]&&t[e.provenance]&&t[e.purpose])}(n,a))return o.exports.set(e,t,r)},get:o.exports.get,getAll:o.exports.get,getJSON:o.exports.getJSON,getAllJSON:o.exports.getJSON,remove:o.exports.remove};return{consent:a,acceptCookies:function(e,t){(null==t?void 0:t.allowChangingNecessary)?p(e):p(r(r({},e),{necessary:!0}))},declineAllCookies:function(){p(c(!1))},acceptAllCookies:function(){p(c(!0))},didAcceptAll:function(){return Object.keys(a||{}).reduce((function(e,t){return e&&a&&a[t]||!1}),!0)},didDeclineAll:function(e){return Object.keys(a||{}).reduce((function(t,n){return(null==e?void 0:e.includingNecessary)||"necessary"!==n?t&&a&&!a[n]||!1:t}),!0)},cookies:f}};export{s as useCookieConsent};
***************************************************************************** */var n,r=function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)},o={exports:{}};n=function(){function e(){for(var e=0,t={};e<arguments.length;e++){var n=arguments[e];for(var r in n)t[r]=n[r]}return t}function t(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function n(r){function o(){}function i(t,n,i){if("undefined"!=typeof document){"number"==typeof(i=e({path:"/"},o.defaults,i)).expires&&(i.expires=new Date(1*new Date+864e5*i.expires)),i.expires=i.expires?i.expires.toUTCString():"";try{var c=JSON.stringify(n);/^[\{\[]/.test(c)&&(n=c)}catch(e){}n=r.write?r.write(n,t):encodeURIComponent(String(n)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var s="";for(var u in i)i[u]&&(s+="; "+u,!0!==i[u]&&(s+="="+i[u].split(";")[0]));return document.cookie=t+"="+n+s}}function c(e,n){if("undefined"!=typeof document){for(var o={},i=document.cookie?document.cookie.split("; "):[],c=0;c<i.length;c++){var s=i[c].split("="),u=s.slice(1).join("=");n||'"'!==u.charAt(0)||(u=u.slice(1,-1));try{var a=t(s[0]);if(u=(r.read||r)(u,a)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(o[a]=u,e===a)break}catch(e){}}return e?o[e]:o}}return o.set=i,o.get=function(e){return c(e,!1)},o.getJSON=function(e){return c(e,!0)},o.remove=function(t,n){i(t,"",e(n,{expires:-1}))},o.defaults={},o.withConverter=n,o}((function(){}))},o.exports=n();var i={necessary:!0},c=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}},s=function(n){var s=void 0!==n&&"storage"in n,u=(s?JSON.parse(null==n?void 0:n.storage.getItem("USE_COOKIE_CONSENT_STATE")):o.exports.getJSON("USE_COOKIE_CONSENT_STATE"))||(null==n?void 0:n.defaultConsent)||i,a=e(u),l=a[0],p=a[1];t((function(){(null==l?void 0:l.necessary)&&((null==l?void 0:l.necessary)&&s?n.storage.setItem("USE_COOKIE_CONSENT_STATE",JSON.stringify(l)):o.exports.set("USE_COOKIE_CONSENT_STATE",l,null==n?void 0:n.consentCookieAttributes))}),[l]);var f=function(e,t){(null==t?void 0:t.allowChangingNecessary)?p(e):p(r(r({},e),{necessary:!0}))},d=function(){p(c(!1))},g=function(){p(c(!0))},v=function(){return Object.keys(l||{}).reduce((function(e,t){return e&&l&&l[t]||!1}),!0)},C=function(e){return Object.keys(l||{}).reduce((function(t,n){return(null==e?void 0:e.includingNecessary)||"necessary"!==n?t&&l&&!l[n]||!1:t}),!0)},O={set:function(e,t,n,r){if(function(e,t){return!!(t&&t[e.duration]&&t[e.provenance]&&t[e.purpose])}(n,l))return o.exports.set(e,t,r)},get:o.exports.get,getAll:o.exports.get,getJSON:o.exports.getJSON,getAllJSON:o.exports.getJSON,remove:o.exports.remove};return s?{consent:l,acceptCookies:f,declineAllCookies:d,acceptAllCookies:g,didAcceptAll:v,didDeclineAll:C,storage:n.storage}:{consent:l,acceptCookies:f,declineAllCookies:d,acceptAllCookies:g,didAcceptAll:v,didDeclineAll:C,cookies:O}};export{s as useCookieConsent};
//# sourceMappingURL=index.js.map

@@ -37,3 +37,3 @@ import { CookieAttributes } from 'js-cookie';

}) => boolean;
export interface CookieConsentHookActions {
export interface ConsentHookActions {
acceptCookies: (cookies: CookieTypes, options?: AcceptCookiesOptions) => void;

@@ -44,12 +44,23 @@ declineAllCookies: () => void;

didDeclineAll: DidDeclineAllHandler;
cookies: CookieWrapper;
}
export declare type CookieConsent = CookieTypes;
export interface CookieConsentHookState extends CookieConsentHookActions {
consent: CookieConsent;
export declare type ConsentState = CookieTypes;
export interface CookieConsentHookState extends ConsentHookActions {
cookies?: CookieWrapper;
consent: ConsentState;
}
export interface CookieConsentOptions {
defaultConsent?: CookieConsent;
export interface StorageConsentHookState extends ConsentHookActions {
storage: Storage;
consent: ConsentState;
}
export declare type UseCookieConsentHookType = (options?: CookieConsentHookOptions) => CookieConsentHookState;
export declare type UseStorageConsentHookType = (options?: StorageConsentHookOptions) => StorageConsentHookState;
export declare type UseConsentHookType = UseCookieConsentHookType | UseStorageConsentHookType;
export interface CookieConsentHookOptions {
defaultConsent?: ConsentState;
consentCookieAttributes?: CookieAttributes;
}
export interface StorageConsentHookOptions {
defaultConsent?: ConsentState;
storage?: Storage;
}
export interface AcceptCookiesOptions {

@@ -56,0 +67,0 @@ allowChangingNecessary?: boolean;

@@ -1,2 +0,2 @@

import { CookieConsentHookState, CookieConsentOptions } from './types';
export declare const useCookieConsent: (options?: CookieConsentOptions) => CookieConsentHookState;
import { UseConsentHookType } from './types';
export declare const useCookieConsent: UseConsentHookType;

@@ -1,3 +0,3 @@

import { CookieConsent, SetCookieProps } from './types';
export declare const allCookiesSetToValue: (value: boolean) => Required<CookieConsent>;
export declare const allPropsApproved: (props: SetCookieProps, consent?: CookieConsent) => boolean;
import { ConsentState, SetCookieProps } from './types';
export declare const allCookiesSetToValue: (value: boolean) => Required<ConsentState>;
export declare const allPropsApproved: (props: SetCookieProps, consent?: ConsentState) => boolean;
{
"name": "@use-cookie-consent/core",
"version": "0.3.6",
"version": "0.4.0-dev.0",
"description": "React hook for managing GDPR cookie consent state.",

@@ -11,2 +11,6 @@ "main": "./build/cjs/index.js",

],
"resolutions": {
"glob-parent": "5.1.2",
"trim": "0.0.3"
},
"engines": {

@@ -22,3 +26,6 @@ "node": ">=12"

"test:watch": "jest --watch",
"coverage": "jest --ci --coverage"
"coverage": "jest --ci --coverage",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"cy:run": "cypress run"
},

@@ -50,2 +57,3 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.17.9",
"@quassum/prettier-config": "^1.0.1",

@@ -55,4 +63,11 @@ "@rollup/plugin-commonjs": "^21.0.1",

"@rollup/pluginutils": "^4.1.1",
"@storybook/addon-actions": "^6.4.22",
"@storybook/addon-essentials": "^6.4.22",
"@storybook/addon-interactions": "^6.4.22",
"@storybook/addon-links": "^6.4.22",
"@storybook/react": "^6.4.22",
"@storybook/testing-library": "^0.0.9",
"@testing-library/react": "^12.1.1",
"@testing-library/react-hooks": "^7",
"@types/chai": "^4.3.1",
"@types/jest": "^27.0.2",

@@ -65,2 +80,5 @@ "@types/js-cookie": "^2",

"@typescript-eslint/parser": "^5.6.0",
"babel-loader": "^8.2.4",
"chai": "^4.3.6",
"cypress": "^9.6.0",
"eslint": "^8.4.1",

@@ -72,2 +90,3 @@ "eslint-config-prettier": "^8.3.0",

"jest": "^27.2.3",
"jest-localstorage-mock": "^2.4.21",
"lint-staged": "^12.1.2",

@@ -85,5 +104,8 @@ "prettier": "^2.5.1",

"ts-jest": "^27",
"ts-node": "^10.7.0",
"tsconfig-paths": "^3.14.1",
"typescript": "^4.2"
},
"dependencies": {
"glob-parent": "^6.0.2",
"js-cookie": "^2"

@@ -90,0 +112,0 @@ },

@@ -16,3 +16,3 @@ # useCookieConsent hook for pure JavaScript projects

- **Hook-based** - extremely intuitive for React developers, but can be used in any JavaScript application.
- **Small** - Just under `1.5kB` gzipped.
- **Small** - Less than `2kB` gzipped.

@@ -158,2 +158,6 @@ <p align="center">

## Contributing
If you want to contribute to this project, read our [contributing guidelines](https://github.com/use-cookie-consent/use-cookie-consent/blob/main/CONTRIBUTING.md) first.
## Acknowledgements

@@ -160,0 +164,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc