@newlogic-digital/cookieconsent-js 1.0.0 → 1.1.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
@@ -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
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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newlogic-digital/cookieconsent-js",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "author": "New Logic Studio s.r.o.",
@@ -8,20 +8,26 @@
8
8
  "scripts": {
9
9
  "eslint": "eslint '**/*.js'",
10
10
  "eslint-fix": "eslint '**/*.js' --fix",
11
- "publish-next": "npm publish --tag next"
11
+ "publish-next": "npm publish --tag next",
12
+ "dts": "node dts.js"
12
13
  },
13
14
  "dependencies": {
14
15
  "@newlogic-digital/utils-js": "^1"
15
16
  },
16
17
  "devDependencies": {
18
+ "dts-buddy": "^0.6.2",
17
19
  "eslint": "^9.13.0",
18
20
  "neostandard": "^0.11.6"
19
21
  },
20
22
  "files": [
21
- "index.js"
23
+ "index.js",
24
+ "types"
22
25
  ],
23
26
  "exports": {
24
- ".": "./index.js"
27
+ ".": {
28
+ "types": "./types/index.d.ts",
29
+ "default": "./index.js"
30
+ }
25
31
  },
26
32
  "engines": {
27
33
  "node": ">=20.0.0"
@@ -0,0 +1,18 @@
1
+ declare module '@newlogic-digital/cookieconsent-js' {
2
+ export function appendCookieConsent(element: HTMLElement, options?: {
3
+ ignoreAttributeName?: RegExp;
4
+ delay?: number;
5
+ }): void;
6
+ export function initCookieConsent(element?: Document | HTMLElement, type?: string[], attribute?: string): void;
7
+ export function unsetCookieConsent(): void;
8
+ export function setCookieConsent(type: string[], options: {
9
+ name?: string;
10
+ expire?: number;
11
+ setItem?: (key: string, value: string) => void;
12
+ getItem?: (key: string) => string | null;
13
+ }): Promise<string[]>;
14
+
15
+ export {};
16
+ }
17
+
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ {
2
+ "version": 3,
3
+ "file": "index.d.ts",
4
+ "names": [
5
+ "appendCookieConsent",
6
+ "initCookieConsent",
7
+ "unsetCookieConsent",
8
+ "setCookieConsent"
9
+ ],
10
+ "sources": [
11
+ "../index.js"
12
+ ],
13
+ "sourcesContent": [
14
+ null
15
+ ],
16
+ "mappings": ";iBAMaA,mBAAmBA;;;;iBAenBC,iBAAiBA;iBAWjBC,kBAAkBA;iBAWlBC,gBAAgBA",
17
+ "ignoreList": []
18
+ }