@use-cookie-consent/core
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var react=require("react"),js_cookie={exports:{}};!function(){var e;e=function(){function s(){for(var e=0,t={};e<arguments.length;e++){var o,n=arguments[e];for(o in n)t[o]=n[o]}return t}function a(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function e(u){function c(){}function o(e,t,o){if("undefined"!=typeof document){"number"==typeof(o=s({path:"/"},c.defaults,o)).expires&&(o.expires=new Date(+new Date+864e5*o.expires)),o.expires=o.expires?o.expires.toUTCString():"";try{var n=JSON.stringify(t);/^[\{\[]/.test(n)&&(t=n)}catch(e){}t=u.write?u.write(t,e):encodeURIComponent(String(t)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var r,i="";for(r in o)o[r]&&(i+="; "+r,!0!==o[r]&&(i+="="+o[r].split(";")[0]));return document.cookie=e+"="+t+i}}function t(e,t){if("undefined"!=typeof document){for(var o={},n=document.cookie?document.cookie.split("; "):[],r=0;r<n.length;r++){var i=n[r].split("="),c=i.slice(1).join("=");t||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var s=a(i[0]),c=(u.read||u)(c,s)||a(c);if(t)try{c=JSON.parse(c)}catch(e){}if(o[s]=c,e===s)break}catch(e){}}return e?o[e]:o}}return c.set=o,c.get=function(e){return t(e,!1)},c.getJSON=function(e){return t(e,!0)},c.remove=function(e,t){o(e,"",s(t,{expires:-1}))},c.defaults={},c.withConverter=e,c}(function(){})},js_cookie.exports=e()}();var COOKIE_CONSENT_KEY="USE_COOKIE_CONSENT_STATE",EMPTY_CONSENT={},allCookiesSetToValue=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}},allPropsApproved=function(e,t){return!!t&&(!!t[e.duration]&&(!!t[e.provenance]&&!!t[e.purpose]))},useCookieConsent=function(e){var t=js_cookie.exports.getJSON(COOKIE_CONSENT_KEY)||(null==e?void 0:e.defaultConsent)||EMPTY_CONSENT,t=react.useState(t),r=t[0],o=t[1];react.useEffect(function(){null!=r&&r.necessary&&js_cookie.exports.set(COOKIE_CONSENT_KEY,r,null==e?void 0:e.consentCookieAttributes)},[r]);t={set:function(e,t,o,n){if(allPropsApproved(o,r))return js_cookie.exports.set(e,t,n)},get:js_cookie.exports.get,getAll:js_cookie.exports.get,getJSON:js_cookie.exports.getJSON,getAllJSON:js_cookie.exports.getJSON,remove:js_cookie.exports.remove};return{consent:r,acceptCookies:function(e){o(e)},declineAllCookies:function(){o(allCookiesSetToValue(!1))},acceptAllCookies:function(){o(allCookiesSetToValue(!0))},didAcceptAll:function(){return Object.keys(r||{}).reduce(function(e,t){return e&&r&&r[t]||!1},!0)},didDeclineAll:function(o){return Object.keys(r||{}).reduce(function(e,t){return null!=o&&o.includingNecessary||"necessary"!==t?e&&r&&!r[t]||!1:e},!0)},cookies:t}};exports.useCookieConsent=useCookieConsent; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n={exports:{}};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(){}))},n.exports=e();var r={},o=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}};exports.useCookieConsent=function(e){var i=n.exports.getJSON("USE_COOKIE_CONSENT_STATE")||(null==e?void 0:e.defaultConsent)||r,c=t.useState(i),s=c[0],u=c[1];t.useEffect((function(){(null==s?void 0:s.necessary)&&n.exports.set("USE_COOKIE_CONSENT_STATE",s,null==e?void 0:e.consentCookieAttributes)}),[s]);var a={set:function(e,t,r,o){if(function(e,t){return!!(t&&t[e.duration]&&t[e.provenance]&&t[e.purpose])}(r,s))return n.exports.set(e,t,o)},get:n.exports.get,getAll:n.exports.get,getJSON:n.exports.getJSON,getAllJSON:n.exports.getJSON,remove:n.exports.remove};return{consent:s,acceptCookies:function(e){u(e)},declineAllCookies:function(){u(o(!1))},acceptAllCookies:function(){u(o(!0))},didAcceptAll:function(){return Object.keys(s||{}).reduce((function(e,t){return e&&s&&s[t]||!1}),!0)},didDeclineAll:function(e){return Object.keys(s||{}).reduce((function(t,n){return(null==e?void 0:e.includingNecessary)||"necessary"!==n?t&&s&&!s[n]||!1:t}),!0)},cookies:a}}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,9 @@ | ||
import{useState,useEffect}from"react";var js_cookie={exports:{}};!function(){var e;e=function(){function s(){for(var e=0,t={};e<arguments.length;e++){var o,n=arguments[e];for(o in n)t[o]=n[o]}return t}function a(e){return e.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function e(u){function c(){}function o(e,t,o){if("undefined"!=typeof document){"number"==typeof(o=s({path:"/"},c.defaults,o)).expires&&(o.expires=new Date(+new Date+864e5*o.expires)),o.expires=o.expires?o.expires.toUTCString():"";try{var n=JSON.stringify(t);/^[\{\[]/.test(n)&&(t=n)}catch(e){}t=u.write?u.write(t,e):encodeURIComponent(String(t)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var r,i="";for(r in o)o[r]&&(i+="; "+r,!0!==o[r]&&(i+="="+o[r].split(";")[0]));return document.cookie=e+"="+t+i}}function t(e,t){if("undefined"!=typeof document){for(var o={},n=document.cookie?document.cookie.split("; "):[],r=0;r<n.length;r++){var i=n[r].split("="),c=i.slice(1).join("=");t||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var s=a(i[0]),c=(u.read||u)(c,s)||a(c);if(t)try{c=JSON.parse(c)}catch(e){}if(o[s]=c,e===s)break}catch(e){}}return e?o[e]:o}}return c.set=o,c.get=function(e){return t(e,!1)},c.getJSON=function(e){return t(e,!0)},c.remove=function(e,t){o(e,"",s(t,{expires:-1}))},c.defaults={},c.withConverter=e,c}(function(){})},js_cookie.exports=e()}();var COOKIE_CONSENT_KEY="USE_COOKIE_CONSENT_STATE",EMPTY_CONSENT={},allCookiesSetToValue=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}},allPropsApproved=function(e,t){return!!t&&(!!t[e.duration]&&(!!t[e.provenance]&&!!t[e.purpose]))},useCookieConsent=function(e){var t=js_cookie.exports.getJSON(COOKIE_CONSENT_KEY)||(null==e?void 0:e.defaultConsent)||EMPTY_CONSENT,t=useState(t),r=t[0],o=t[1];useEffect(function(){null!=r&&r.necessary&&js_cookie.exports.set(COOKIE_CONSENT_KEY,r,null==e?void 0:e.consentCookieAttributes)},[r]);t={set:function(e,t,o,n){if(allPropsApproved(o,r))return js_cookie.exports.set(e,t,n)},get:js_cookie.exports.get,getAll:js_cookie.exports.get,getJSON:js_cookie.exports.getJSON,getAllJSON:js_cookie.exports.getJSON,remove:js_cookie.exports.remove};return{consent:r,acceptCookies:function(e){o(e)},declineAllCookies:function(){o(allCookiesSetToValue(!1))},acceptAllCookies:function(){o(allCookiesSetToValue(!0))},didAcceptAll:function(){return Object.keys(r||{}).reduce(function(e,t){return e&&r&&r[t]||!1},!0)},didDeclineAll:function(o){return Object.keys(r||{}).reduce(function(e,t){return null!=o&&o.includingNecessary||"necessary"!==t?e&&r&&!r[t]||!1:e},!0)},cookies:t}};export{useCookieConsent}; | ||
import{useState as e,useEffect as t}from"react";var n,r={exports:{}}; | ||
/*! | ||
* JavaScript Cookie v2.2.1 | ||
* https://github.com/js-cookie/js-cookie | ||
* | ||
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack | ||
* Released under the MIT license | ||
*/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 p=t(s[0]);if(u=(r.read||r)(u,p)||t(u),n)try{u=JSON.parse(u)}catch(e){}if(o[p]=u,e===p)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=n();var o={},i=function(e){return{session:e,persistent:e,necessary:!0,preferences:e,statistics:e,marketing:e,firstParty:e,thirdParty:e}},c=function(n){var c=r.exports.getJSON("USE_COOKIE_CONSENT_STATE")||(null==n?void 0:n.defaultConsent)||o,s=e(c),u=s[0],p=s[1];t((function(){(null==u?void 0:u.necessary)&&r.exports.set("USE_COOKIE_CONSENT_STATE",u,null==n?void 0:n.consentCookieAttributes)}),[u]);var a={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){p(e)},declineAllCookies:function(){p(i(!1))},acceptAllCookies:function(){p(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:a}};export{c as useCookieConsent}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@use-cookie-consent/core", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "React hook for managing GDPR cookie consent state.", | ||
"main": "./build/cjs/index.js", | ||
"types": "./build/cjs/index.d.ts", | ||
"types": "./build/index.d.ts", | ||
"module": "./build/esm/index.js", | ||
@@ -76,5 +76,6 @@ "files": [ | ||
"rollup": "^2.61.1", | ||
"rollup-plugin-gzip": "^3.0.0", | ||
"rollup-plugin-peer-deps-external": "^2.2.4", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "^0.31.1", | ||
"rollup-plugin-uglify": "^6.0.4", | ||
"ts-jest": "^27", | ||
@@ -81,0 +82,0 @@ "typescript": "^4.2" |
@@ -7,3 +7,3 @@ # useCookieConsent hook for pure JavaScript projects | ||
[![Codecov](https://img.shields.io/codecov/c/github/use-cookie-consent/use-cookie-consent-core)](https://github.com/use-cookie-consent/use-cookie-consent-core/actions/workflows/codecov.yml) | ||
![Lines of code](https://img.shields.io/tokei/lines/github/use-cookie-consent/use-cookie-consent-core) | ||
[![gzipped size](https://img.badgesize.io/https:/unpkg.com/@use-cookie-consent/core@latest/build/esm/index.js?label=gzipped&compression=gzip&style=flat-square)](https://unpkg.com/@use-cookie-consent/core@latest/build/esm/index.js) | ||
[![License](https://img.shields.io/npm/l/@use-cookie-consent/core)](https://github.com/use-cookie-consent/use-cookie-consent-core/blob/main/LICENSE) | ||
@@ -15,2 +15,3 @@ | ||
- **Hook-based** - extremely intuitive for React developers, but can be used in any JavaScript application. | ||
- **Small** - Just under `1.5kB` gzipped. | ||
@@ -58,6 +59,6 @@ ## Library-specific packages | ||
```tsx | ||
import {useCookieConsent} from '@use-cookie-consent/core'; | ||
import { useCookieConsent } from '@use-cookie-consent/core'; | ||
export const YourComponent = () => { | ||
const {consent, acceptAllCookies, declineAllCookies, acceptCookies} = | ||
const { consent, acceptAllCookies, declineAllCookies, acceptCookies } = | ||
useCookieConsent(); | ||
@@ -75,6 +76,6 @@ | ||
<button onClick={acceptAllCookies}>Accept all</button> | ||
<button onClick={() => acceptCookies({thirdParty: true})}> | ||
<button onClick={() => acceptCookies({ thirdParty: true })}> | ||
Accept third-party | ||
</button> | ||
<button onClick={() => acceptCookies({firstParty: true})}> | ||
<button onClick={() => acceptCookies({ firstParty: true })}> | ||
Accept first-party | ||
@@ -81,0 +82,0 @@ </button> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
42513
14
93
146
0
32