@newlogic-digital/cookieconsent-js 1.1.1 → 1.2.0-next.1

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 CHANGED
@@ -5,61 +5,53 @@ import { replaceScript } from '@newlogic-digital/utils-js'
5
5
  * @param {{ignoreAttributeName?: RegExp, delay?: number}} options
6
6
  */
7
7
  export const appendCookieConsent = (element, options = {}) => {
8
- options = {
9
- ignoreAttributeName: /(type|data-cookieconsent)/,
10
- delay: 0,
11
- ...options
12
- }
8
+ options = {
9
+ ignoreAttributeName: /(type|data-cookieconsent)/,
10
+ delay: 0,
11
+ ...options,
12
+ }
13
13
 
14
- setTimeout(() => replaceScript(element, options.ignoreAttributeName), options.delay)
14
+ setTimeout(() => replaceScript(element, options.ignoreAttributeName), options.delay)
15
15
  }
16
16
 
17
17
  /**
18
18
  * @param {Document|HTMLElement} element
19
- * @param {string[]} type
19
+ * @param {string} type
20
20
  * @param {string} attribute
21
21
  */
22
- export const initCookieConsent = (element = document, type = localStorage.getItem('cookieconsent-js') ?? [], attribute = 'data-cookieconsent') => {
23
- element.querySelectorAll(`[${attribute}]`).forEach((element) => {
24
- if (type.includes(element.getAttribute(attribute))) {
25
- appendCookieConsent(element)
26
- }
27
- })
22
+ export const initCookieConsent = (element = document, type = localStorage.getItem('cookieconsent-js'), attribute = 'data-cookieconsent') => {
23
+ element.querySelectorAll(`[${attribute}]`).forEach((element) => {
24
+ if (type.includes(element.getAttribute(attribute))) {
25
+ appendCookieConsent(element)
26
+ }
27
+ })
28
28
  }
29
29
 
30
30
  /**
31
31
  * @returns {void}
32
32
  */
33
33
  export const unsetCookieConsent = () => {
34
- document.cookie.split(';').forEach((c) => {
35
- document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/')
36
- })
34
+ document.cookie.split(';').forEach((c) => {
35
+ document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/')
36
+ })
37
37
  }
38
38
 
39
39
  /**
40
40
  * @param {string[]} type
41
41
  * @param {{name?: string, expire?: number, setItem?: (key: string, value: string) => void, getItem?: (key: string) => string|null}} options
42
- * @returns {Promise<string[]>}
42
+ * @returns {void}
43
43
  */
44
- export const setCookieConsent = (type, options) => {
45
- options = {
46
- name: 'cookieconsent-js',
47
- expire: 31556926 * 1000,
48
- setItem: (key, value) => localStorage.setItem(key, value),
49
- getItem: key => localStorage.getItem(key),
50
- ...options
51
- }
44
+ export const setCookieConsent = (type, options = {}) => {
45
+ options = {
46
+ name: 'cookieconsent-js',
47
+ expire: 31556926 * 1000,
48
+ setItem: (key, value) => localStorage.setItem(key, value),
49
+ getItem: key => localStorage.getItem(key),
50
+ ...options,
51
+ }
52
52
 
53
- return new Promise((resolve) => {
54
- options.setItem(options.name, JSON.stringify(type))
55
- options.setItem(`${options.name}-expire`, (Date.now() + options.expire).toString())
53
+ options.setItem(options.name, JSON.stringify(type))
54
+ options.setItem(`${options.name}-expire`, (Date.now() + options.expire).toString())
56
55
 
57
- if (type.length > 0) {
58
- resolve(type)
59
- } else {
60
- options.setItem(options.name, JSON.stringify([]))
61
- unsetCookieConsent()
62
- resolve([])
63
- }
64
- })
56
+ if (type.length === 0) unsetCookieConsent()
65
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newlogic-digital/cookieconsent-js",
3
- "version": "1.1.1",
3
+ "version": "1.2.0-next.1",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "author": "New Logic Studio s.r.o.",
@@ -15,9 +15,11 @@
15
15
  "@newlogic-digital/utils-js": "^1"
16
16
  },
17
17
  "devDependencies": {
18
- "dts-buddy": "^0.6.2",
19
- "eslint": "^9.13.0",
20
- "neostandard": "^0.11.6"
18
+ "@eslint/js": "^10.0.1",
19
+ "@stylistic/eslint-plugin": "^5.10.0",
20
+ "dts-buddy": "^0.8.2",
21
+ "eslint": "^10.5.0",
22
+ "globals": "^17.7.0"
21
23
  },
22
24
  "files": [
23
25
  "index.js",
package/types/index.d.ts CHANGED
@@ -3,14 +3,14 @@ declare module '@newlogic-digital/cookieconsent-js' {
3
3
  ignoreAttributeName?: RegExp;
4
4
  delay?: number;
5
5
  }): void;
6
- export function initCookieConsent(element?: Document | HTMLElement, type?: string[], attribute?: string): void;
6
+ export function initCookieConsent(element?: Document | HTMLElement, type?: string, attribute?: string): void;
7
7
  export function unsetCookieConsent(): void;
8
- export function setCookieConsent(type: string[], options: {
8
+ export function setCookieConsent(type: string[], options?: {
9
9
  name?: string;
10
10
  expire?: number;
11
11
  setItem?: (key: string, value: string) => void;
12
12
  getItem?: (key: string) => string | null;
13
- }): Promise<string[]>;
13
+ }): void;
14
14
 
15
15
  export {};
16
16
  }