├── .github └── workflows │ └── publish.yml ├── .gitignore ├── CODEOWNERS ├── LICENSE ├── README.md ├── jsconfig.json ├── package.json ├── pnpm-lock.yaml ├── pnpm-workspace.yaml └── projects ├── demo ├── .gitignore ├── .npmrc ├── jsconfig.json ├── package.json ├── src │ ├── app.d.ts │ ├── app.html │ └── routes │ │ ├── +page.js │ │ └── +page.svelte ├── svelte.config.js └── vite.config.js └── svelte-localstorage ├── README.md ├── browser.js ├── package.json └── server.js /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to NPM every tag (i.e. new version) 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*" 7 | 8 | jobs: 9 | publish: 10 | strategy: 11 | matrix: 12 | node-version: [22] 13 | os: [ubuntu-latest] 14 | runs-on: ${{ matrix.os }} 15 | timeout-minutes: 15 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-node@v4 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | registry-url: https://registry.npmjs.org/ 22 | - uses: pnpm/action-setup@v4.0.0 23 | with: 24 | version: 9.x 25 | - run: pnpm install 26 | - run: pnpm check 27 | - run: pnpm -r publish --access public --no-git-checks 28 | env: 29 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .history 2 | node_modules 3 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @babichjacob 2 | 3 | /projects/svelte-localstorage/ @babichjacob 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jacob Babich 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ./projects/svelte-localstorage/README.md -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "checkJs": true, 4 | "maxNodeModuleJsDepth": 0, 5 | "module": "esnext", 6 | "moduleResolution": "node", 7 | "noEmit": true, 8 | "resolveJsonModule": true, 9 | "strict": true, 10 | "target": "es2020", 11 | }, 12 | "include": ["./**/*.js", "./**/*.d.ts"], 13 | "exclude": ["node_modules", "./projects/demo/build"] 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@babichjacob/svelte-localstorage-workspace-root", 3 | "private": true, 4 | "version": "1.0.1", 5 | "description": "Svelte writable stores that automatically synchronize with localStorage", 6 | "author": "J / Jacob Babich ", 7 | "keywords": [ 8 | "svelte", 9 | "sveltekit", 10 | "svelte-kit", 11 | "sapper", 12 | "localstorage", 13 | "local-storage" 14 | ], 15 | "license": "MIT", 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/babichjacob/svelte-localstorage.git" 19 | }, 20 | "bugs": { 21 | "url": "https://github.com/babichjacob/svelte-localstorage/issues" 22 | }, 23 | "homepage": "https://github.com/babichjacob/svelte-localstorage", 24 | "scripts": { 25 | "check": "tsc --project jsconfig.json" 26 | }, 27 | "devDependencies": { 28 | "typescript": "^4.9.3" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '9.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | importers: 8 | 9 | .: 10 | devDependencies: 11 | typescript: 12 | specifier: ^4.9.3 13 | version: 4.9.5 14 | 15 | projects/demo: 16 | devDependencies: 17 | '@babichjacob/svelte-localstorage': 18 | specifier: workspace:1.1.2 19 | version: link:../svelte-localstorage 20 | '@sveltejs/adapter-static': 21 | specifier: next 22 | version: 1.0.0-next.50(@sveltejs/kit@1.0.0-next.589(svelte@3.59.2)(vite@3.2.11)) 23 | '@sveltejs/kit': 24 | specifier: next 25 | version: 1.0.0-next.589(svelte@3.59.2)(vite@3.2.11) 26 | lz-string: 27 | specifier: ^1.4.4 28 | version: 1.5.0 29 | svelte: 30 | specifier: ^3.53.1 31 | version: 3.59.2 32 | vite: 33 | specifier: ^3.2.4 34 | version: 3.2.11 35 | 36 | projects/svelte-localstorage: 37 | dependencies: 38 | svelte: 39 | specifier: ^3.53.1 || ^4.2 40 | version: 3.59.2 41 | 42 | packages: 43 | 44 | '@esbuild/android-arm@0.15.18': 45 | resolution: {integrity: sha512-5GT+kcs2WVGjVs7+boataCkO5Fg0y4kCjzkB5bAip7H4jfnOS3dA6KPiww9W1OEKTKeAcUVhdZGvgI65OXmUnw==} 46 | engines: {node: '>=12'} 47 | cpu: [arm] 48 | os: [android] 49 | 50 | '@esbuild/linux-loong64@0.15.18': 51 | resolution: {integrity: sha512-L4jVKS82XVhw2nvzLg/19ClLWg0y27ulRwuP7lcyL6AbUWB5aPglXY3M21mauDQMDfRLs8cQmeT03r/+X3cZYQ==} 52 | engines: {node: '>=12'} 53 | cpu: [loong64] 54 | os: [linux] 55 | 56 | '@jridgewell/sourcemap-codec@1.5.0': 57 | resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==} 58 | 59 | '@polka/url@1.0.0-next.28': 60 | resolution: {integrity: sha512-8LduaNlMZGwdZ6qWrKlfa+2M4gahzFkprZiAt2TF8uS0qQgBizKXpXURqvTJ4WtmupWxaLqjRb2UCTe72mu+Aw==} 61 | 62 | '@sveltejs/adapter-static@1.0.0-next.50': 63 | resolution: {integrity: sha512-xZKBmiwFGW8nrH8+eysUAAo9XrtApI81q0m67y1bexVw8IY7/x741b6VEklNM7BZ7js0Mi2x+yCkHpOee8UZKQ==} 64 | peerDependencies: 65 | '@sveltejs/kit': ^1.0.0-next.587 66 | 67 | '@sveltejs/kit@1.0.0-next.589': 68 | resolution: {integrity: sha512-5ABRw46z9B+cCe/YWhcx+I/azNZg1NCDEkVJifZn8ToFoJ3a1eP0OexNIrvMEWpllMbNMPcJm2TC9tnz9oPfWQ==} 69 | engines: {node: '>=16.14'} 70 | hasBin: true 71 | peerDependencies: 72 | svelte: ^3.54.0 73 | vite: ^4.0.0 74 | 75 | '@sveltejs/vite-plugin-svelte-inspector@1.0.4': 76 | resolution: {integrity: sha512-zjiuZ3yydBtwpF3bj0kQNV0YXe+iKE545QGZVTaylW3eAzFr+pJ/cwK8lZEaRp4JtaJXhD5DyWAV4AxLh6DgaQ==} 77 | engines: {node: ^14.18.0 || >= 16} 78 | peerDependencies: 79 | '@sveltejs/vite-plugin-svelte': ^2.2.0 80 | svelte: ^3.54.0 || ^4.0.0 81 | vite: ^4.0.0 82 | 83 | '@sveltejs/vite-plugin-svelte@2.5.3': 84 | resolution: {integrity: sha512-erhNtXxE5/6xGZz/M9eXsmI7Pxa6MS7jyTy06zN3Ck++ldrppOnOlJwHHTsMC7DHDQdgUp4NAc4cDNQ9eGdB/w==} 85 | engines: {node: ^14.18.0 || >= 16} 86 | peerDependencies: 87 | svelte: ^3.54.0 || ^4.0.0 || ^5.0.0-next.0 88 | vite: ^4.0.0 89 | 90 | '@types/cookie@0.5.4': 91 | resolution: {integrity: sha512-7z/eR6O859gyWIAjuvBWFzNURmf2oPBmJlfVWkwehU5nzIyjwBsTh7WMmEEV4JFnHuQ3ex4oyTvfKzcyJVDBNA==} 92 | 93 | busboy@1.6.0: 94 | resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==} 95 | engines: {node: '>=10.16.0'} 96 | 97 | cookie@0.5.0: 98 | resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==} 99 | engines: {node: '>= 0.6'} 100 | 101 | debug@4.3.7: 102 | resolution: {integrity: sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==} 103 | engines: {node: '>=6.0'} 104 | peerDependencies: 105 | supports-color: '*' 106 | peerDependenciesMeta: 107 | supports-color: 108 | optional: true 109 | 110 | deepmerge@4.3.1: 111 | resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} 112 | engines: {node: '>=0.10.0'} 113 | 114 | devalue@4.3.3: 115 | resolution: {integrity: sha512-UH8EL6H2ifcY8TbD2QsxwCC/pr5xSwPvv85LrLXVihmHVC3T3YqTCIwnR5ak0yO1KYqlxrPVOA/JVZJYPy2ATg==} 116 | 117 | esbuild-android-64@0.15.18: 118 | resolution: {integrity: sha512-wnpt3OXRhcjfIDSZu9bnzT4/TNTDsOUvip0foZOUBG7QbSt//w3QV4FInVJxNhKc/ErhUxc5z4QjHtMi7/TbgA==} 119 | engines: {node: '>=12'} 120 | cpu: [x64] 121 | os: [android] 122 | 123 | esbuild-android-arm64@0.15.18: 124 | resolution: {integrity: sha512-G4xu89B8FCzav9XU8EjsXacCKSG2FT7wW9J6hOc18soEHJdtWu03L3TQDGf0geNxfLTtxENKBzMSq9LlbjS8OQ==} 125 | engines: {node: '>=12'} 126 | cpu: [arm64] 127 | os: [android] 128 | 129 | esbuild-darwin-64@0.15.18: 130 | resolution: {integrity: sha512-2WAvs95uPnVJPuYKP0Eqx+Dl/jaYseZEUUT1sjg97TJa4oBtbAKnPnl3b5M9l51/nbx7+QAEtuummJZW0sBEmg==} 131 | engines: {node: '>=12'} 132 | cpu: [x64] 133 | os: [darwin] 134 | 135 | esbuild-darwin-arm64@0.15.18: 136 | resolution: {integrity: sha512-tKPSxcTJ5OmNb1btVikATJ8NftlyNlc8BVNtyT/UAr62JFOhwHlnoPrhYWz09akBLHI9nElFVfWSTSRsrZiDUA==} 137 | engines: {node: '>=12'} 138 | cpu: [arm64] 139 | os: [darwin] 140 | 141 | esbuild-freebsd-64@0.15.18: 142 | resolution: {integrity: sha512-TT3uBUxkteAjR1QbsmvSsjpKjOX6UkCstr8nMr+q7zi3NuZ1oIpa8U41Y8I8dJH2fJgdC3Dj3CXO5biLQpfdZA==} 143 | engines: {node: '>=12'} 144 | cpu: [x64] 145 | os: [freebsd] 146 | 147 | esbuild-freebsd-arm64@0.15.18: 148 | resolution: {integrity: sha512-R/oVr+X3Tkh+S0+tL41wRMbdWtpWB8hEAMsOXDumSSa6qJR89U0S/PpLXrGF7Wk/JykfpWNokERUpCeHDl47wA==} 149 | engines: {node: '>=12'} 150 | cpu: [arm64] 151 | os: [freebsd] 152 | 153 | esbuild-linux-32@0.15.18: 154 | resolution: {integrity: sha512-lphF3HiCSYtaa9p1DtXndiQEeQDKPl9eN/XNoBf2amEghugNuqXNZA/ZovthNE2aa4EN43WroO0B85xVSjYkbg==} 155 | engines: {node: '>=12'} 156 | cpu: [ia32] 157 | os: [linux] 158 | 159 | esbuild-linux-64@0.15.18: 160 | resolution: {integrity: sha512-hNSeP97IviD7oxLKFuii5sDPJ+QHeiFTFLoLm7NZQligur8poNOWGIgpQ7Qf8Balb69hptMZzyOBIPtY09GZYw==} 161 | engines: {node: '>=12'} 162 | cpu: [x64] 163 | os: [linux] 164 | 165 | esbuild-linux-arm64@0.15.18: 166 | resolution: {integrity: sha512-54qr8kg/6ilcxd+0V3h9rjT4qmjc0CccMVWrjOEM/pEcUzt8X62HfBSeZfT2ECpM7104mk4yfQXkosY8Quptug==} 167 | engines: {node: '>=12'} 168 | cpu: [arm64] 169 | os: [linux] 170 | 171 | esbuild-linux-arm@0.15.18: 172 | resolution: {integrity: sha512-UH779gstRblS4aoS2qpMl3wjg7U0j+ygu3GjIeTonCcN79ZvpPee12Qun3vcdxX+37O5LFxz39XeW2I9bybMVA==} 173 | engines: {node: '>=12'} 174 | cpu: [arm] 175 | os: [linux] 176 | 177 | esbuild-linux-mips64le@0.15.18: 178 | resolution: {integrity: sha512-Mk6Ppwzzz3YbMl/ZZL2P0q1tnYqh/trYZ1VfNP47C31yT0K8t9s7Z077QrDA/guU60tGNp2GOwCQnp+DYv7bxQ==} 179 | engines: {node: '>=12'} 180 | cpu: [mips64el] 181 | os: [linux] 182 | 183 | esbuild-linux-ppc64le@0.15.18: 184 | resolution: {integrity: sha512-b0XkN4pL9WUulPTa/VKHx2wLCgvIAbgwABGnKMY19WhKZPT+8BxhZdqz6EgkqCLld7X5qiCY2F/bfpUUlnFZ9w==} 185 | engines: {node: '>=12'} 186 | cpu: [ppc64] 187 | os: [linux] 188 | 189 | esbuild-linux-riscv64@0.15.18: 190 | resolution: {integrity: sha512-ba2COaoF5wL6VLZWn04k+ACZjZ6NYniMSQStodFKH/Pu6RxzQqzsmjR1t9QC89VYJxBeyVPTaHuBMCejl3O/xg==} 191 | engines: {node: '>=12'} 192 | cpu: [riscv64] 193 | os: [linux] 194 | 195 | esbuild-linux-s390x@0.15.18: 196 | resolution: {integrity: sha512-VbpGuXEl5FCs1wDVp93O8UIzl3ZrglgnSQ+Hu79g7hZu6te6/YHgVJxCM2SqfIila0J3k0csfnf8VD2W7u2kzQ==} 197 | engines: {node: '>=12'} 198 | cpu: [s390x] 199 | os: [linux] 200 | 201 | esbuild-netbsd-64@0.15.18: 202 | resolution: {integrity: sha512-98ukeCdvdX7wr1vUYQzKo4kQ0N2p27H7I11maINv73fVEXt2kyh4K4m9f35U1K43Xc2QGXlzAw0K9yoU7JUjOg==} 203 | engines: {node: '>=12'} 204 | cpu: [x64] 205 | os: [netbsd] 206 | 207 | esbuild-openbsd-64@0.15.18: 208 | resolution: {integrity: sha512-yK5NCcH31Uae076AyQAXeJzt/vxIo9+omZRKj1pauhk3ITuADzuOx5N2fdHrAKPxN+zH3w96uFKlY7yIn490xQ==} 209 | engines: {node: '>=12'} 210 | cpu: [x64] 211 | os: [openbsd] 212 | 213 | esbuild-sunos-64@0.15.18: 214 | resolution: {integrity: sha512-On22LLFlBeLNj/YF3FT+cXcyKPEI263nflYlAhz5crxtp3yRG1Ugfr7ITyxmCmjm4vbN/dGrb/B7w7U8yJR9yw==} 215 | engines: {node: '>=12'} 216 | cpu: [x64] 217 | os: [sunos] 218 | 219 | esbuild-windows-32@0.15.18: 220 | resolution: {integrity: sha512-o+eyLu2MjVny/nt+E0uPnBxYuJHBvho8vWsC2lV61A7wwTWC3jkN2w36jtA+yv1UgYkHRihPuQsL23hsCYGcOQ==} 221 | engines: {node: '>=12'} 222 | cpu: [ia32] 223 | os: [win32] 224 | 225 | esbuild-windows-64@0.15.18: 226 | resolution: {integrity: sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==} 227 | engines: {node: '>=12'} 228 | cpu: [x64] 229 | os: [win32] 230 | 231 | esbuild-windows-arm64@0.15.18: 232 | resolution: {integrity: sha512-q9bsYzegpZcLziq0zgUi5KqGVtfhjxGbnksaBFYmWLxeV/S1fK4OLdq2DFYnXcLMjlZw2L0jLsk1eGoB522WXQ==} 233 | engines: {node: '>=12'} 234 | cpu: [arm64] 235 | os: [win32] 236 | 237 | esbuild@0.15.18: 238 | resolution: {integrity: sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q==} 239 | engines: {node: '>=12'} 240 | hasBin: true 241 | 242 | esm-env@1.0.0: 243 | resolution: {integrity: sha512-Cf6VksWPsTuW01vU9Mk/3vRue91Zevka5SjyNf3nEpokFRuqt/KjUQoGAwq9qMmhpLTHmXzSIrFRw8zxWzmFBA==} 244 | 245 | fsevents@2.3.3: 246 | resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==} 247 | engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} 248 | os: [darwin] 249 | 250 | function-bind@1.1.2: 251 | resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} 252 | 253 | globalyzer@0.1.0: 254 | resolution: {integrity: sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==} 255 | 256 | globrex@0.1.2: 257 | resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} 258 | 259 | hasown@2.0.2: 260 | resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} 261 | engines: {node: '>= 0.4'} 262 | 263 | is-core-module@2.15.1: 264 | resolution: {integrity: sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==} 265 | engines: {node: '>= 0.4'} 266 | 267 | kleur@4.1.5: 268 | resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} 269 | engines: {node: '>=6'} 270 | 271 | lz-string@1.5.0: 272 | resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} 273 | hasBin: true 274 | 275 | magic-string@0.27.0: 276 | resolution: {integrity: sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==} 277 | engines: {node: '>=12'} 278 | 279 | magic-string@0.30.12: 280 | resolution: {integrity: sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==} 281 | 282 | mime@3.0.0: 283 | resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==} 284 | engines: {node: '>=10.0.0'} 285 | hasBin: true 286 | 287 | mri@1.2.0: 288 | resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} 289 | engines: {node: '>=4'} 290 | 291 | mrmime@2.0.0: 292 | resolution: {integrity: sha512-eu38+hdgojoyq63s+yTpN4XMBdt5l8HhMhc4VKLO9KM5caLIBvUm4thi7fFaxyTmCKeNnXZ5pAlBwCUnhA09uw==} 293 | engines: {node: '>=10'} 294 | 295 | ms@2.1.3: 296 | resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} 297 | 298 | nanoid@3.3.7: 299 | resolution: {integrity: sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==} 300 | engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} 301 | hasBin: true 302 | 303 | path-parse@1.0.7: 304 | resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} 305 | 306 | picocolors@1.1.1: 307 | resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} 308 | 309 | postcss@8.4.47: 310 | resolution: {integrity: sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==} 311 | engines: {node: ^10 || ^12 || >=14} 312 | 313 | resolve@1.22.8: 314 | resolution: {integrity: sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==} 315 | hasBin: true 316 | 317 | rollup@2.79.2: 318 | resolution: {integrity: sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==} 319 | engines: {node: '>=10.0.0'} 320 | hasBin: true 321 | 322 | sade@1.8.1: 323 | resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==} 324 | engines: {node: '>=6'} 325 | 326 | set-cookie-parser@2.7.0: 327 | resolution: {integrity: sha512-lXLOiqpkUumhRdFF3k1osNXCy9akgx/dyPZ5p8qAg9seJzXr5ZrlqZuWIMuY6ejOsVLE6flJ5/h3lsn57fQ/PQ==} 328 | 329 | sirv@2.0.4: 330 | resolution: {integrity: sha512-94Bdh3cC2PKrbgSOUqTiGPWVZeSiXfKOVZNJniWoqrWrRkB1CJzBU3NEbiTsPcYy1lDsANA/THzS+9WBiy5nfQ==} 331 | engines: {node: '>= 10'} 332 | 333 | source-map-js@1.2.1: 334 | resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} 335 | engines: {node: '>=0.10.0'} 336 | 337 | streamsearch@1.1.0: 338 | resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} 339 | engines: {node: '>=10.0.0'} 340 | 341 | supports-preserve-symlinks-flag@1.0.0: 342 | resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} 343 | engines: {node: '>= 0.4'} 344 | 345 | svelte-hmr@0.15.3: 346 | resolution: {integrity: sha512-41snaPswvSf8TJUhlkoJBekRrABDXDMdpNpT2tfHIv4JuhgvHqLMhEPGtaQn0BmbNSTkuz2Ed20DF2eHw0SmBQ==} 347 | engines: {node: ^12.20 || ^14.13.1 || >= 16} 348 | peerDependencies: 349 | svelte: ^3.19.0 || ^4.0.0 350 | 351 | svelte@3.59.2: 352 | resolution: {integrity: sha512-vzSyuGr3eEoAtT/A6bmajosJZIUWySzY2CzB3w2pgPvnkUjGqlDnsNnA0PMO+mMAhuyMul6C2uuZzY6ELSkzyA==} 353 | engines: {node: '>= 8'} 354 | 355 | tiny-glob@0.2.9: 356 | resolution: {integrity: sha512-g/55ssRPUjShh+xkfx9UPDXqhckHEsHr4Vd9zX55oSdGZc/MD0m3sferOkwWtp98bv+kcVfEHtRJgBVJzelrzg==} 357 | 358 | totalist@3.0.1: 359 | resolution: {integrity: sha512-sf4i37nQ2LBx4m3wB74y+ubopq6W/dIzXg0FDGjsYnZHVa1Da8FH853wlL2gtUhg+xJXjfk3kUZS3BRoQeoQBQ==} 360 | engines: {node: '>=6'} 361 | 362 | typescript@4.9.5: 363 | resolution: {integrity: sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==} 364 | engines: {node: '>=4.2.0'} 365 | hasBin: true 366 | 367 | undici@5.14.0: 368 | resolution: {integrity: sha512-yJlHYw6yXPPsuOH0x2Ib1Km61vu4hLiRRQoafs+WUgX1vO64vgnxiCEN9dpIrhZyHFsai3F0AEj4P9zy19enEQ==} 369 | engines: {node: '>=12.18'} 370 | 371 | vite@3.2.11: 372 | resolution: {integrity: sha512-K/jGKL/PgbIgKCiJo5QbASQhFiV02X9Jh+Qq0AKCRCRKZtOTVi4t6wh75FDpGf2N9rYOnzH87OEFQNaFy6pdxQ==} 373 | engines: {node: ^14.18.0 || >=16.0.0} 374 | hasBin: true 375 | peerDependencies: 376 | '@types/node': '>= 14' 377 | less: '*' 378 | sass: '*' 379 | stylus: '*' 380 | sugarss: '*' 381 | terser: ^5.4.0 382 | peerDependenciesMeta: 383 | '@types/node': 384 | optional: true 385 | less: 386 | optional: true 387 | sass: 388 | optional: true 389 | stylus: 390 | optional: true 391 | sugarss: 392 | optional: true 393 | terser: 394 | optional: true 395 | 396 | vitefu@0.2.5: 397 | resolution: {integrity: sha512-SgHtMLoqaeeGnd2evZ849ZbACbnwQCIwRH57t18FxcXoZop0uQu0uzlIhJBlF/eWVzuce0sHeqPcDo+evVcg8Q==} 398 | peerDependencies: 399 | vite: ^3.0.0 || ^4.0.0 || ^5.0.0 400 | peerDependenciesMeta: 401 | vite: 402 | optional: true 403 | 404 | snapshots: 405 | 406 | '@esbuild/android-arm@0.15.18': 407 | optional: true 408 | 409 | '@esbuild/linux-loong64@0.15.18': 410 | optional: true 411 | 412 | '@jridgewell/sourcemap-codec@1.5.0': {} 413 | 414 | '@polka/url@1.0.0-next.28': {} 415 | 416 | '@sveltejs/adapter-static@1.0.0-next.50(@sveltejs/kit@1.0.0-next.589(svelte@3.59.2)(vite@3.2.11))': 417 | dependencies: 418 | '@sveltejs/kit': 1.0.0-next.589(svelte@3.59.2)(vite@3.2.11) 419 | 420 | '@sveltejs/kit@1.0.0-next.589(svelte@3.59.2)(vite@3.2.11)': 421 | dependencies: 422 | '@sveltejs/vite-plugin-svelte': 2.5.3(svelte@3.59.2)(vite@3.2.11) 423 | '@types/cookie': 0.5.4 424 | cookie: 0.5.0 425 | devalue: 4.3.3 426 | esm-env: 1.0.0 427 | kleur: 4.1.5 428 | magic-string: 0.27.0 429 | mime: 3.0.0 430 | sade: 1.8.1 431 | set-cookie-parser: 2.7.0 432 | sirv: 2.0.4 433 | svelte: 3.59.2 434 | tiny-glob: 0.2.9 435 | undici: 5.14.0 436 | vite: 3.2.11 437 | transitivePeerDependencies: 438 | - supports-color 439 | 440 | '@sveltejs/vite-plugin-svelte-inspector@1.0.4(@sveltejs/vite-plugin-svelte@2.5.3(svelte@3.59.2)(vite@3.2.11))(svelte@3.59.2)(vite@3.2.11)': 441 | dependencies: 442 | '@sveltejs/vite-plugin-svelte': 2.5.3(svelte@3.59.2)(vite@3.2.11) 443 | debug: 4.3.7 444 | svelte: 3.59.2 445 | vite: 3.2.11 446 | transitivePeerDependencies: 447 | - supports-color 448 | 449 | '@sveltejs/vite-plugin-svelte@2.5.3(svelte@3.59.2)(vite@3.2.11)': 450 | dependencies: 451 | '@sveltejs/vite-plugin-svelte-inspector': 1.0.4(@sveltejs/vite-plugin-svelte@2.5.3(svelte@3.59.2)(vite@3.2.11))(svelte@3.59.2)(vite@3.2.11) 452 | debug: 4.3.7 453 | deepmerge: 4.3.1 454 | kleur: 4.1.5 455 | magic-string: 0.30.12 456 | svelte: 3.59.2 457 | svelte-hmr: 0.15.3(svelte@3.59.2) 458 | vite: 3.2.11 459 | vitefu: 0.2.5(vite@3.2.11) 460 | transitivePeerDependencies: 461 | - supports-color 462 | 463 | '@types/cookie@0.5.4': {} 464 | 465 | busboy@1.6.0: 466 | dependencies: 467 | streamsearch: 1.1.0 468 | 469 | cookie@0.5.0: {} 470 | 471 | debug@4.3.7: 472 | dependencies: 473 | ms: 2.1.3 474 | 475 | deepmerge@4.3.1: {} 476 | 477 | devalue@4.3.3: {} 478 | 479 | esbuild-android-64@0.15.18: 480 | optional: true 481 | 482 | esbuild-android-arm64@0.15.18: 483 | optional: true 484 | 485 | esbuild-darwin-64@0.15.18: 486 | optional: true 487 | 488 | esbuild-darwin-arm64@0.15.18: 489 | optional: true 490 | 491 | esbuild-freebsd-64@0.15.18: 492 | optional: true 493 | 494 | esbuild-freebsd-arm64@0.15.18: 495 | optional: true 496 | 497 | esbuild-linux-32@0.15.18: 498 | optional: true 499 | 500 | esbuild-linux-64@0.15.18: 501 | optional: true 502 | 503 | esbuild-linux-arm64@0.15.18: 504 | optional: true 505 | 506 | esbuild-linux-arm@0.15.18: 507 | optional: true 508 | 509 | esbuild-linux-mips64le@0.15.18: 510 | optional: true 511 | 512 | esbuild-linux-ppc64le@0.15.18: 513 | optional: true 514 | 515 | esbuild-linux-riscv64@0.15.18: 516 | optional: true 517 | 518 | esbuild-linux-s390x@0.15.18: 519 | optional: true 520 | 521 | esbuild-netbsd-64@0.15.18: 522 | optional: true 523 | 524 | esbuild-openbsd-64@0.15.18: 525 | optional: true 526 | 527 | esbuild-sunos-64@0.15.18: 528 | optional: true 529 | 530 | esbuild-windows-32@0.15.18: 531 | optional: true 532 | 533 | esbuild-windows-64@0.15.18: 534 | optional: true 535 | 536 | esbuild-windows-arm64@0.15.18: 537 | optional: true 538 | 539 | esbuild@0.15.18: 540 | optionalDependencies: 541 | '@esbuild/android-arm': 0.15.18 542 | '@esbuild/linux-loong64': 0.15.18 543 | esbuild-android-64: 0.15.18 544 | esbuild-android-arm64: 0.15.18 545 | esbuild-darwin-64: 0.15.18 546 | esbuild-darwin-arm64: 0.15.18 547 | esbuild-freebsd-64: 0.15.18 548 | esbuild-freebsd-arm64: 0.15.18 549 | esbuild-linux-32: 0.15.18 550 | esbuild-linux-64: 0.15.18 551 | esbuild-linux-arm: 0.15.18 552 | esbuild-linux-arm64: 0.15.18 553 | esbuild-linux-mips64le: 0.15.18 554 | esbuild-linux-ppc64le: 0.15.18 555 | esbuild-linux-riscv64: 0.15.18 556 | esbuild-linux-s390x: 0.15.18 557 | esbuild-netbsd-64: 0.15.18 558 | esbuild-openbsd-64: 0.15.18 559 | esbuild-sunos-64: 0.15.18 560 | esbuild-windows-32: 0.15.18 561 | esbuild-windows-64: 0.15.18 562 | esbuild-windows-arm64: 0.15.18 563 | 564 | esm-env@1.0.0: {} 565 | 566 | fsevents@2.3.3: 567 | optional: true 568 | 569 | function-bind@1.1.2: {} 570 | 571 | globalyzer@0.1.0: {} 572 | 573 | globrex@0.1.2: {} 574 | 575 | hasown@2.0.2: 576 | dependencies: 577 | function-bind: 1.1.2 578 | 579 | is-core-module@2.15.1: 580 | dependencies: 581 | hasown: 2.0.2 582 | 583 | kleur@4.1.5: {} 584 | 585 | lz-string@1.5.0: {} 586 | 587 | magic-string@0.27.0: 588 | dependencies: 589 | '@jridgewell/sourcemap-codec': 1.5.0 590 | 591 | magic-string@0.30.12: 592 | dependencies: 593 | '@jridgewell/sourcemap-codec': 1.5.0 594 | 595 | mime@3.0.0: {} 596 | 597 | mri@1.2.0: {} 598 | 599 | mrmime@2.0.0: {} 600 | 601 | ms@2.1.3: {} 602 | 603 | nanoid@3.3.7: {} 604 | 605 | path-parse@1.0.7: {} 606 | 607 | picocolors@1.1.1: {} 608 | 609 | postcss@8.4.47: 610 | dependencies: 611 | nanoid: 3.3.7 612 | picocolors: 1.1.1 613 | source-map-js: 1.2.1 614 | 615 | resolve@1.22.8: 616 | dependencies: 617 | is-core-module: 2.15.1 618 | path-parse: 1.0.7 619 | supports-preserve-symlinks-flag: 1.0.0 620 | 621 | rollup@2.79.2: 622 | optionalDependencies: 623 | fsevents: 2.3.3 624 | 625 | sade@1.8.1: 626 | dependencies: 627 | mri: 1.2.0 628 | 629 | set-cookie-parser@2.7.0: {} 630 | 631 | sirv@2.0.4: 632 | dependencies: 633 | '@polka/url': 1.0.0-next.28 634 | mrmime: 2.0.0 635 | totalist: 3.0.1 636 | 637 | source-map-js@1.2.1: {} 638 | 639 | streamsearch@1.1.0: {} 640 | 641 | supports-preserve-symlinks-flag@1.0.0: {} 642 | 643 | svelte-hmr@0.15.3(svelte@3.59.2): 644 | dependencies: 645 | svelte: 3.59.2 646 | 647 | svelte@3.59.2: {} 648 | 649 | tiny-glob@0.2.9: 650 | dependencies: 651 | globalyzer: 0.1.0 652 | globrex: 0.1.2 653 | 654 | totalist@3.0.1: {} 655 | 656 | typescript@4.9.5: {} 657 | 658 | undici@5.14.0: 659 | dependencies: 660 | busboy: 1.6.0 661 | 662 | vite@3.2.11: 663 | dependencies: 664 | esbuild: 0.15.18 665 | postcss: 8.4.47 666 | resolve: 1.22.8 667 | rollup: 2.79.2 668 | optionalDependencies: 669 | fsevents: 2.3.3 670 | 671 | vitefu@0.2.5(vite@3.2.11): 672 | optionalDependencies: 673 | vite: 3.2.11 674 | -------------------------------------------------------------------------------- /pnpm-workspace.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | - "projects/*" 3 | -------------------------------------------------------------------------------- /projects/demo/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /projects/demo/.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /projects/demo/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./.svelte-kit/tsconfig.json" 3 | } 4 | -------------------------------------------------------------------------------- /projects/demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo", 3 | "private": true, 4 | "version": "0.0.1", 5 | "scripts": { 6 | "dev": "vite dev", 7 | "build": "vite build", 8 | "preview": "vite preview" 9 | }, 10 | "devDependencies": { 11 | "@babichjacob/svelte-localstorage": "workspace:1.1.2", 12 | "@sveltejs/adapter-static": "next", 13 | "@sveltejs/kit": "next", 14 | "lz-string": "^1.4.4", 15 | "svelte": "^3.53.1", 16 | "vite": "^3.2.4" 17 | }, 18 | "type": "module" 19 | } 20 | -------------------------------------------------------------------------------- /projects/demo/src/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // See https://kit.svelte.dev/docs/types#the-app-namespace 4 | // for information about these interfaces 5 | declare namespace App { 6 | // interface Locals {} 7 | // interface Platform {} 8 | // interface Session {} 9 | // interface Stuff {} 10 | } 11 | -------------------------------------------------------------------------------- /projects/demo/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %sveltekit.head% 7 | 8 | 9 |
%sveltekit.body%
10 | 11 | 12 | -------------------------------------------------------------------------------- /projects/demo/src/routes/+page.js: -------------------------------------------------------------------------------- 1 | export const prerender = true; 2 | -------------------------------------------------------------------------------- /projects/demo/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 32 | 33 | 34 | 35 | 43 | 44 | 52 | 53 | ({$point.x}, {$point.y}) 54 | 55 | 105 | ``` 106 | 107 | ## 😵 Help! I have a question 108 | 109 | Create an issue and I'll try to help. 110 | 111 | ## 😡 Fix! There is something that needs improvement 112 | 113 | Create an issue or pull request and I'll try to fix. 114 | 115 | ## 📄 License 116 | 117 | MIT 118 | 119 | ## 🙏 Attribution 120 | 121 | _Repository preview image generated with [GitHub Social Preview](https://social-preview.pqt.dev/)_ 122 | 123 | _This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_ 124 | -------------------------------------------------------------------------------- /projects/svelte-localstorage/browser.js: -------------------------------------------------------------------------------- 1 | import { writable } from "svelte/store"; 2 | 3 | /** 4 | * @template Item 5 | * @param {string} key What key in localStorage to synchronize with 6 | * @param {Item} initial The initial value of the writable store 7 | * @param {object} param2 How to serialize and deserialize the Item 8 | * @param {function(Item): string} [param2.serialize] How to create a string representation of the Item to store in localStorage. You can also implement compression here. 9 | * @param {function(string): Item} [param2.deserialize] How to convert the string representation in localStorage to an Item. You can also implement decompression here. 10 | * @returns {import("svelte/store").Writable} A writable store that synchronizes with localStorage 11 | */ 12 | export const localStorageWritable = ( 13 | key, 14 | initial, 15 | { serialize = JSON.stringify, deserialize = JSON.parse } = {} 16 | ) => { 17 | let currentValue = initial; 18 | 19 | /** 20 | * @param {import("svelte/store").Writable["set"]} setStore 21 | * @param {Item} value 22 | */ 23 | const syncCurrentValue = (setStore, value) => { 24 | setStore(value); 25 | currentValue = value; 26 | }; 27 | 28 | /** @param {string | null} localValue */ 29 | const parseFromLocalStorage = (localValue) => { 30 | if (localValue === null) return initial; 31 | 32 | try { 33 | return deserialize(localValue); 34 | } catch (error) { 35 | console.error( 36 | `localStorage's value for \`${key}\` (\`${localValue}\`) could not be deserialized with ${deserialize} because of ${error}, so the initial value \`${initial}\` will be used instead` 37 | ); 38 | return initial; 39 | } 40 | }; 41 | 42 | const { set: setStore, subscribe } = writable(initial, (setStore) => { 43 | /** @type {string | null} */ 44 | let localStorageValue = null; 45 | try { 46 | localStorageValue = localStorage.getItem(key); 47 | } catch (error) { 48 | console.error( 49 | `the \`${key}\` store's value could not be restored from localStorage because of ${error}, so the initial value \`${initial}\` will be used instead` 50 | ); 51 | } 52 | 53 | syncCurrentValue(setStore, parseFromLocalStorage(localStorageValue)); 54 | 55 | /** @param {StorageEvent} event */ 56 | const setFromStorageEvents = (event) => { 57 | if (event.key === key) 58 | syncCurrentValue(setStore, parseFromLocalStorage(event.newValue)); 59 | }; 60 | window.addEventListener("storage", setFromStorageEvents); 61 | return () => window.removeEventListener("storage", setFromStorageEvents); 62 | }); 63 | 64 | // Set both localStorage and this Svelte store 65 | /** @type {import("svelte/store").Writable["set"]} */ 66 | const set = (value) => { 67 | syncCurrentValue(setStore, value); 68 | 69 | try { 70 | const serialized = serialize(value); 71 | 72 | try { 73 | localStorage.setItem(key, serialized); 74 | } catch (error) { 75 | console.error( 76 | `the \`${key}\` store's new value \`${value}\` (which serialized to \`${serialized}\`) could not be persisted to localStorage because of ${error}` 77 | ); 78 | } 79 | } catch (error) { 80 | console.error( 81 | `the \`${key}\` store was set to \`${value}\`, but this could not be serialized with ${serialize} because of ${error}, so it won't be persisted to localStorage` 82 | ); 83 | } 84 | }; 85 | 86 | /** @type {import("svelte/store").Writable["update"]} */ 87 | const update = (fn) => { 88 | set(fn(currentValue)); 89 | }; 90 | 91 | return { set, subscribe, update }; 92 | }; 93 | -------------------------------------------------------------------------------- /projects/svelte-localstorage/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@babichjacob/svelte-localstorage", 3 | "version": "1.1.2", 4 | "description": "Svelte writable stores that automatically synchronize with localStorage", 5 | "author": "J / Jacob Babich ", 6 | "keywords": [ 7 | "svelte", 8 | "localstorage", 9 | "local-storage", 10 | "svelte-kit", 11 | "sveltekit", 12 | "sapper" 13 | ], 14 | "license": "MIT", 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/babichjacob/svelte-localstorage.git" 18 | }, 19 | "bugs": { 20 | "url": "https://github.com/babichjacob/svelte-localstorage/issues" 21 | }, 22 | "homepage": "https://github.com/babichjacob/svelte-localstorage", 23 | "exports": { 24 | ".": { 25 | "browser": "./browser.js", 26 | "node": "./server.js", 27 | "default": "./server.js" 28 | } 29 | }, 30 | "type": "module", 31 | "dependencies": { 32 | "svelte": "^3.53.1 || ^4.2" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /projects/svelte-localstorage/server.js: -------------------------------------------------------------------------------- 1 | import { writable } from "svelte/store"; 2 | 3 | /** 4 | * @template Item 5 | * @param {string} key What key in localStorage to synchronize with 6 | * @param {Item} initial The initial value of the writable store 7 | * @param {object} param2 How to serialize and deserialize the Item 8 | * @param {function(Item): string} [param2.serialize] How to create a string representation of the Item to store in localStorage. You can also implement compression here. 9 | * @param {function(string): Item} [param2.deserialize] How to convert the string representation in localStorage to an Item. You can also implement decompression here. 10 | * @returns {import("svelte/store").Writable} A writable store that synchronizes with localStorage 11 | */ 12 | export const localStorageWritable = (key, initial, param2 = {}) => { 13 | const { set, subscribe, update } = writable(initial); 14 | 15 | return { set, subscribe, update }; 16 | }; 17 | --------------------------------------------------------------------------------