has-consent
Version:
GDPR consent string validation library
1 lines • 4.76 kB
JavaScript
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=0)}([function(e,n,t){"use strict";function r(e){return function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,t=e;for(;t.length<n;)t="0".concat(t);return t}(e.toString(2))}function o(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}t.r(n);var i=function(){function e(){if(function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.maxVendorID=null,this.minVendorID=null,this.vendorIDs=[],1===arguments.length)this.vendorIDs.push(arguments.length<=0?void 0:arguments[0]),this.maxVendorID=this.minVendorID=arguments.length<=0?void 0:arguments[0];else{if(2!==arguments.length)throw new Error("Expected 1 or 2 arguments, received ".concat(arguments.length));this.minVendorID=arguments.length<=0?void 0:arguments[0],this.maxVendorID=arguments.length<=1?void 0:arguments[1];for(var n=this.minVendorID;n<=this.maxVendorID;n+=1)this.vendorIDs.push(n)}}return function(e,n,t){n&&o(e.prototype,n),t&&o(e,t)}(e,[{key:"containsVendorID",value:function(e){return this.vendorIDs.indexOf(e)>=0}},{key:"vendorIDGreaterThanMax",value:function(e){return e>this.maxVendorID}}]),e}();function s(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var u=1,a=function(){function e(n){if(function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),!n)throw new Error("Invalid consent string value");this.consentString=n;var t=function(e){for(var n=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:window).atob(function(e){for(var n=e;n.length%4!=0;)n+="=";return n=n.replace(/-/g,"+").replace(/_/g,"/")}(e)),t=n.length,r=new Uint8Array(t),o=0;o<t;o+=1)r[o]=n.charCodeAt(o);return r}(n);this.consentData=t.reduce(function(e,n){return"".concat(e).concat(r(n))},""),this._processPurposes(),this.vendorEncodingType===u&&this._processVendorsList()}return function(e,n,t){n&&s(e.prototype,n),t&&s(e,t)}(e,[{key:"purposeAllowed",value:function(e){return!(e<1||e>this.allowedPurposes.length)&&Boolean(this.allowedPurposes[e-1])}},{key:"vendorAllowed",value:function(e){if(this.vendorEncodingType===u)return this._vendorInRange(e)!==Boolean(this.defaultConsent);try{return Boolean(this._getBit(173+e-1))}catch(e){return!1}}},{key:"_getBit",value:function(e){var n=this.consentData.substr(e,1);return parseInt(n,10)}},{key:"_getInt",value:function(e,n){return function(e){return parseInt(e,2)}(this.consentData.substr(e,n))}},{key:"_processPurposes",value:function(){this.allowedPurposes=[];for(var e=132;e<156;e+=1)this.allowedPurposes.push(this._getBit(e));this.purposes=[];for(var n=1,t=this.allowedPurposes.length;n<=t;n+=1)this.purposeAllowed(n)&&this.purposes.push(n)}},{key:"_processVendorsList",value:function(){this.rangeEntries=[],this.defaultConsent=this._getBit(173);for(var e=this._getInt(174,12),n=186,t=0;t<e;t+=1){var r=Boolean(this._getBit(n));if(n+=1,r){var o=this._getInt(n,16);n+=16;var s=this._getInt(n,16);n+=16,this.rangeEntries.push(new i(o,s))}else{var u=this._getInt(n,16);n+=16,this.rangeEntries.push(new i(u))}}}},{key:"_vendorInRange",value:function(e){var n=this.rangeEntries.length;if(0===n)return!1;for(var t=Math.floor(n/2);t>=0&&t<n;){var r=this.rangeEntries[t];if(r.containsVendorID(e))return!0;if(0===t||t===n-1)return!1;r.vendorIDGreaterThanMax(e)?t+=Math.floor((n-t)/2):t=Math.floor(t/2)}return!1}},{key:"cmpID",get:function(){return this._getInt(78,12)}},{key:"cmpVersion",get:function(){return this._getInt(90,12)}},{key:"vendorEncodingType",get:function(){return this._getInt(172,1)}},{key:"version",get:function(){return this._getInt(0,6)}}]),e}();t.d(n,"ConsentStringParser",function(){return a})}]);