@newlogic-digital/cookieconsent-js 0.2.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +19 -2
- package/package.json +13 -6
package/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { replaceScript } from '@newlogic-digital/utils-js'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @param {HTMLElement} element
|
|
5
|
+
* @param {{ignoreAttributeName?: RegExp, delay?: number}} options
|
|
6
|
+
*/
|
|
3
7
|
export const appendCookieConsent = (element, options = {}) => {
|
|
4
8
|
options = {
|
|
5
9
|
ignoreAttributeName: /(type|data-cookieconsent)/,
|
|
@@ -10,6 +14,11 @@ export const appendCookieConsent = (element, options = {}) => {
|
|
|
10
14
|
setTimeout(() => replaceScript(element, options.ignoreAttributeName), options.delay)
|
|
11
15
|
}
|
|
12
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @param {Document|HTMLElement} element
|
|
19
|
+
* @param {string[]} type
|
|
20
|
+
* @param {string} attribute
|
|
21
|
+
*/
|
|
13
22
|
export const initCookieConsent = (element = document, type = localStorage.getItem('cookieconsent-js') ?? [], attribute = 'data-cookieconsent') => {
|
|
14
23
|
element.querySelectorAll(`[${attribute}]`).forEach((element) => {
|
|
15
24
|
if (type.includes(element.getAttribute(attribute))) {
|
|
@@ -18,12 +27,20 @@ export const initCookieConsent = (element = document, type = localStorage.getIte
|
|
|
18
27
|
})
|
|
19
28
|
}
|
|
20
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
21
33
|
export const unsetCookieConsent = () => {
|
|
22
|
-
document.cookie.split(';').forEach(c => {
|
|
34
|
+
document.cookie.split(';').forEach((c) => {
|
|
23
35
|
document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/')
|
|
24
36
|
})
|
|
25
37
|
}
|
|
26
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {string[]} type
|
|
41
|
+
* @param {{name?: string, expire?: number, setItem?: (key: string, value: string) => void, getItem?: (key: string) => string|null}} options
|
|
42
|
+
* @returns {Promise<string[]>}
|
|
43
|
+
*/
|
|
27
44
|
export const setCookieConsent = (type, options) => {
|
|
28
45
|
options = {
|
|
29
46
|
name: 'cookieconsent-js',
|
|
@@ -33,7 +50,7 @@ export const setCookieConsent = (type, options) => {
|
|
|
33
50
|
...options
|
|
34
51
|
}
|
|
35
52
|
|
|
36
|
-
return new Promise(resolve => {
|
|
53
|
+
return new Promise((resolve) => {
|
|
37
54
|
options.setItem(options.name, JSON.stringify(type))
|
|
38
55
|
options.setItem(`${options.name}-expire`, (Date.now() + options.expire).toString())
|
|
39
56
|
|
package/package.json
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newlogic-digital/cookieconsent-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "New Logic Studio s.r.o.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"eslint": "eslint '**/*.js'",
|
|
10
|
-
"eslint-fix": "eslint '**/*.js' --fix"
|
|
10
|
+
"eslint-fix": "eslint '**/*.js' --fix",
|
|
11
|
+
"publish-next": "npm publish --tag next",
|
|
12
|
+
"dts": "node dts.js"
|
|
11
13
|
},
|
|
12
14
|
"dependencies": {
|
|
13
|
-
"@newlogic-digital/utils-js": "^
|
|
15
|
+
"@newlogic-digital/utils-js": "^1"
|
|
14
16
|
},
|
|
15
17
|
"devDependencies": {
|
|
16
|
-
"
|
|
18
|
+
"dts-buddy": "^0.6.2",
|
|
19
|
+
"eslint": "^9.13.0",
|
|
20
|
+
"neostandard": "^0.11.6"
|
|
17
21
|
},
|
|
18
22
|
"files": [
|
|
19
23
|
"index.js"
|
|
20
24
|
],
|
|
21
25
|
"exports": {
|
|
22
|
-
".":
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./types/index.d.ts",
|
|
28
|
+
"default": "./index.js"
|
|
29
|
+
}
|
|
23
30
|
},
|
|
24
31
|
"engines": {
|
|
25
|
-
"node": "
|
|
32
|
+
"node": ">=20.0.0"
|
|
26
33
|
},
|
|
27
34
|
"repository": {
|
|
28
35
|
"type": "git",
|