This file contains hidden or 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
| const objectToUrlSafeBase64 = (obj) => { | |
| const stringifiedObject = JSON.stringify(obj); | |
| const base64String = btoa(stringifiedObject); | |
| return encodeURIComponent(base64String); | |
| }; | |
| const urlSafeBase64ToObject = (urlSafeBase64String) => { | |
| const base64String = decodeURIComponent(urlSafeBase64String); | |
| const stringifiedObject = atob(base64String); |
This file contains hidden or 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
| /** | |
| * a === b is true if a and b have the same value, with the following exceptions: | |
| * - NaN === NaN is false | |
| * - 0 === -0 is true | |
| */ | |
| function strictEquals(a, b) { | |
| if (Object.is(a, NaN) && Object.is(b, NaN)) { | |
| return false; | |
| } |
This file contains hidden or 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
| import { storage } from 'std:kv-storage'; | |
| (async () => { | |
| await storage.set('mycat', 'Tom'); | |
| console.assert((await storage.get('mycat')) === 'Tom'); | |
| for await (const [key, value] of storage.entries()) { | |
| console.log(key, value); | |
| } |
This file contains hidden or 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
| const serializedData = localStorage.getItem('data'); | |
| const myData = JSON.parse(serializedData); |
This file contains hidden or 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
| let savedTheme; | |
| if ('localStorage' in window) { | |
| savedTheme = localStorage.getItem('theme'); | |
| } |
This file contains hidden or 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
| const serializedData = JSON.stringify(myData); | |
| localStorage.setItem('data', serializedData); |
This file contains hidden or 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
| if ('localStorage' in window) { | |
| localStorage.setItem('theme', 'dark'); | |
| } |