-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for local and session storage (#25)
- Loading branch information
1 parent
f532b4b
commit 94112e3
Showing
11 changed files
with
105 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1193,11 +1193,6 @@ | |
resolved "https://registry.yarnpkg.com/@csstools/selector-specificity/-/selector-specificity-2.0.2.tgz#1bfafe4b7ed0f3e4105837e056e0a89b108ebe36" | ||
integrity sha512-IkpVW/ehM1hWKln4fCA3NzJU8KwD+kIOvPZA4cqxoJHtE21CCzjyp+Kxbu0i5I4tBNOlXPL9mjwnWlL0VEG4Fg== | ||
|
||
"@digitalentities/react-hook-bem@^1.0.5": | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/@digitalentities/react-hook-bem/-/react-hook-bem-1.0.5.tgz#456f44a00082b0e0514222751602caf6203f0e93" | ||
integrity sha512-rzzvtIE6S1vVLuxVZqG4Ue+9ZYnwD/bdWR71zNHvEIpOnY01cNq/Mya3B0MnpuKOtOBTlYhC+4dx+V2MtONh2A== | ||
|
||
"@eslint/eslintrc@^1.4.0": | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.4.0.tgz#8ec64e0df3e7a1971ee1ff5158da87389f167a63" | ||
|
@@ -3069,6 +3064,11 @@ cjs-module-lexer@^1.0.0: | |
resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz#9f84ba3244a512f3a54e5277e8eef4c489864e40" | ||
integrity sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA== | ||
|
||
classnames@^2.2.5: | ||
version "2.3.2" | ||
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.3.2.tgz#351d813bf0137fcc6a76a16b88208d2560a0d924" | ||
integrity sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw== | ||
|
||
clean-css@^5.2.2: | ||
version "5.3.1" | ||
resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-5.3.1.tgz#d0610b0b90d125196a2894d35366f734e5d7aa32" | ||
|
@@ -7513,6 +7513,13 @@ [email protected]: | |
optionalDependencies: | ||
fsevents "^2.3.2" | ||
|
||
react-toggle@^4.1.3: | ||
version "4.1.3" | ||
resolved "https://registry.yarnpkg.com/react-toggle/-/react-toggle-4.1.3.tgz#99193392cca8e495710860c49f55e74c4e6cf452" | ||
integrity sha512-WoPrvbwfQSvoagbrDnXPrlsxwzuhQIrs+V0I162j/s+4XPgY/YDAUmHSeWiroznfI73wj+MBydvW95zX8ABbSg== | ||
dependencies: | ||
classnames "^2.2.5" | ||
|
||
read-cache@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/read-cache/-/read-cache-1.0.0.tgz#e664ef31161166c9751cdbe8dbcf86b5fb58f774" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { removeLocalStorage } from './remove'; | ||
|
||
describe('removelocalStorage', () => { | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
test('should remove all listed items from local storage', () => { | ||
localStorage.setItem('foo', 'bar'); | ||
localStorage.setItem('baz', 'qux'); | ||
localStorage.setItem('quux', 'quuz'); | ||
|
||
removeLocalStorage(['foo', 'baz']); | ||
|
||
expect(localStorage.getItem('foo')).toBeNull(); | ||
expect(localStorage.getItem('baz')).toBeNull(); | ||
expect(localStorage.getItem('quux')).not.toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ConsentOptionsService } from '../../Context'; | ||
|
||
export function removeLocalStorage(localStorageItems?: ConsentOptionsService['localStorage']) { | ||
if (localStorageItems) { | ||
for (const localStorageItem of localStorageItems) { | ||
localStorage.removeItem(localStorageItem); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
import { ConsentOptionsService } from '../Context'; | ||
import { removeCookies } from './cookies/remove'; | ||
import { removeLocalStorage } from './local-storage/remove'; | ||
import { removeScripts } from './scripts/remove'; | ||
import { removeSessionStorage } from './session-storage/remove'; | ||
|
||
export function removeServices(services: ConsentOptionsService[]) { | ||
services.forEach(({ id, scripts, cookies }) => { | ||
services.forEach(({ id, scripts, cookies, localStorage, sessionStorage }) => { | ||
removeScripts(id, scripts); | ||
removeCookies(cookies); | ||
removeLocalStorage(localStorage); | ||
removeSessionStorage(sessionStorage); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { removeSessionStorage } from './remove'; | ||
|
||
describe('removeSessionStorage', () => { | ||
beforeEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
test('should remove all listed items from session storage', () => { | ||
sessionStorage.setItem('foo', 'bar'); | ||
sessionStorage.setItem('baz', 'qux'); | ||
sessionStorage.setItem('quux', 'quuz'); | ||
|
||
removeSessionStorage(['foo', 'baz']); | ||
|
||
expect(sessionStorage.getItem('foo')).toBeNull(); | ||
expect(sessionStorage.getItem('baz')).toBeNull(); | ||
expect(sessionStorage.getItem('quux')).not.toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ConsentOptionsService } from '../../Context'; | ||
|
||
export function removeSessionStorage(sessionStorageItems?: ConsentOptionsService['sessionStorage']) { | ||
if (sessionStorageItems) { | ||
for (const sessionStorageItem of sessionStorageItems) { | ||
sessionStorage.removeItem(sessionStorageItem); | ||
} | ||
} | ||
} |