├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── commitlint.config.js ├── husky.config.js ├── jest.config.js ├── lib ├── module.js └── plugin.js ├── package.json ├── renovate.json ├── test ├── fixture │ ├── nuxt.config.js │ └── pages │ │ └── index.vue └── module.test.js └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_size = 2 6 | indent_style = space 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # Common 2 | node_modules 3 | dist 4 | .nuxt 5 | coverage 6 | 7 | # Plugin 8 | lib/plugin.js 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [ 4 | '@nuxtjs' 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | ci: 13 | runs-on: ${{ matrix.os }} 14 | 15 | strategy: 16 | matrix: 17 | # os: [ubuntu-latest, macos-latest, windows-latest] 18 | os: [ubuntu-latest] 19 | node: [10] 20 | 21 | steps: 22 | - uses: actions/setup-node@v2 23 | with: 24 | node-version: ${{ matrix.node }} 25 | 26 | - name: checkout 27 | uses: actions/checkout@v2 28 | 29 | - name: cache node_modules 30 | uses: actions/cache@v2 31 | with: 32 | path: node_modules 33 | key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }} 34 | 35 | - name: Install dependencies 36 | if: steps.cache.outputs.cache-hit != 'true' 37 | run: yarn 38 | 39 | - name: Lint 40 | run: yarn lint 41 | 42 | - name: Test 43 | run: yarn test 44 | 45 | - name: Coverage 46 | uses: codecov/codecov-action@v1 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.iml 3 | .idea 4 | *.log* 5 | .nuxt 6 | .vscode 7 | .DS_Store 8 | coverage 9 | dist 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | ## 1.1.0 (2020-02-11) 6 | 7 | 8 | ## [1.0.2](https://github.com/nuxt-community/localforage-module/compare/v1.0.1...v1.0.2) (2018-02-21) 9 | 10 | 11 | 12 | 13 | ## [1.0.1](https://github.com/compare/v0.0.6...v1.0.1) (2018-02-21) 14 | 15 | 16 | 17 | 18 | ## [0.0.6](https://github.com/compare/v0.0.5...v0.0.6) (2018-02-21) 19 | 20 | 21 | 22 | 23 | ## [0.0.5](https://github.com/compare/v0.0.4...v0.0.5) (2018-02-21) 24 | 25 | 26 | 27 | 28 | ## [0.0.4](https://github.com/compare/v0.0.3...v0.0.4) (2018-02-21) 29 | 30 | 31 | 32 | 33 | ## [0.0.3](https://github.com/compare/v0.0.2...v0.0.3) (2018-02-21) 34 | 35 | 36 | 37 | 38 | ## 0.0.2 (2018-02-21) 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Nuxt Community 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 | # @nuxtjs/localforage 2 | 3 | [![npm version][npm-version-src]][npm-version-href] 4 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 5 | [![Github Actions CI][github-actions-ci-src]][github-actions-ci-href] 6 | [![Codecov][codecov-src]][codecov-href] 7 | [![License][license-src]][license-href] 8 | 9 | > [Localforage](https://github.com/localForage/localForage) module for Nuxt.js 10 | 11 | [📖 **Release Notes**](./CHANGELOG.md) 12 | 13 | ## Setup 14 | 15 | 1. Add `@nuxtjs/localforage` dependency to your project 16 | 17 | ```bash 18 | yarn add --dev @nuxtjs/localforage # or npm install --save-dev @nuxtjs/localforage 19 | ``` 20 | 21 | 2. Add `@nuxtjs/localforage` to the `buildModules` section of `nuxt.config.js` 22 | 23 | ```js 24 | export default { 25 | buildModules: [ 26 | // Simple usage 27 | '@nuxtjs/localforage', 28 | 29 | // With options 30 | ['@nuxtjs/localforage', { /* module options */ }] 31 | ] 32 | } 33 | ``` 34 | 35 | :warning: If you are using Nuxt **< v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`. 36 | 37 | ### Using top level options 38 | 39 | ```js 40 | export default { 41 | buildModules: [ 42 | '@nuxtjs/localforage' 43 | ], 44 | localforage: { 45 | /* module options */ 46 | } 47 | } 48 | ``` 49 | 50 | ## Options 51 | 52 | ### driver (optional) 53 | 54 | - Default: `[localforage.INDEXEDDB, localforage.WEBSQL, localforage.LOCALSTORAGE]` 55 | 56 | The preferred driver(s) to use. Same format as what is passed to `setStorageDriver()`, above. 57 | 58 | ### name (optional) 59 | 60 | - Default: `'nuxtJS'` 61 | 62 | The name of the database. May appear during storage limit prompts. Useful to use the name of your app here. In localStorage, this is used as a key prefix for all keys stored in localStorage. 63 | 64 | ### version (optional) 65 | 66 | - Default: `1.0` 67 | 68 | The version of your database. May be used for upgrades in the future; currently unused. 69 | 70 | ### size (optional) 71 | 72 | - Default: `4980736` 73 | 74 | The size of the database in bytes. Used only in WebSQL for now. 75 | 76 | ### storeName (optional) 77 | 78 | - Default: `'nuxtLocalForage'` 79 | 80 | The name of the datastore. In IndexedDB this is the dataStore, in WebSQL this is the name of the key/value table in the database. Must be alphanumeric, with underscores. Any non-alphanumeric characters will be converted to underscores. 81 | 82 | ### description (optional) 83 | 84 | - Default: `''` 85 | 86 | A description of the database, essentially for developer usage. 87 | 88 | ### `instances` (optional) 89 | 90 | - Default: `[]` 91 | 92 | You can create multiple instances. 93 | 94 | [More informations on LocalForage documentation](https://github.com/localForage/localForage) 95 | 96 | ## Usage 97 | 98 | ### Get item 99 | 100 | ```js 101 | let item = await this.$localForage.getItem(key) 102 | ``` 103 | 104 | ### Set item 105 | 106 | ```js 107 | await this.$localForage.setItem(key, value) 108 | ``` 109 | 110 | ### Remove item 111 | 112 | ```js 113 | await this.$localForage.removeItem(key) 114 | ``` 115 | 116 | ### Clear 117 | 118 | ```js 119 | await this.$localForage.clear 120 | ``` 121 | 122 | ### Gets the length 123 | 124 | ```js 125 | let length = await this.$localForage.length 126 | ``` 127 | 128 | ### Get the name of a key based on its ID 129 | 130 | ```js 131 | let k = await this.$localForage.key(keyIndex) 132 | ``` 133 | 134 | ### Get the list of all keys 135 | 136 | ```js 137 | let keys = await this.$localForage.keys() 138 | ``` 139 | 140 | ### Force usage of a particular driver or drivers, if available 141 | 142 | ```js 143 | this.$localForage.setDriver(localforage.LOCALSTORAGE) 144 | ``` 145 | 146 | By default, localForage selects backend drivers for the datastore in this order: 147 | 148 | 1. IndexedDB 149 | 2. WebSQL 150 | 3. localStorage 151 | 152 | If you would like to force usage of a particular driver you can use $setStorageDriver() with one or more of the following parameters. 153 | 154 | - localforage.INDEXEDDB 155 | - localforage.WEBSQL 156 | - localforage.LOCALSTORAGE 157 | 158 | ## Advanced Usage 159 | 160 | You can register multiple instances, see below: 161 | 162 | ```js 163 | // nuxt.config.js 164 | export default { 165 | buildModules: [ 166 | '@nuxtjs/localforage' 167 | ], 168 | 169 | localforage: { 170 | instances: [{ 171 | name: 'myApp', 172 | storeName: 'images' 173 | }, { 174 | name: 'myApp', 175 | storeName: 'fileSystem' 176 | }] 177 | } 178 | } 179 | 180 | // for images 181 | await this.$localforage.images.setItem(key, value) 182 | 183 | // for fileSystem 184 | await this.$localforage.fileSystem.setItem(key, value) 185 | ``` 186 | 187 | ## Development 188 | 189 | - Clone this repository 190 | - Install dependnecies using `yarn install` or `npm install` 191 | - Start development server using `npm run dev` 192 | 193 | ## License 194 | 195 | [MIT License](./LICENSE) 196 | 197 | Copyright (c) Nuxt Community 198 | 199 | 200 | [npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/localforage/latest.svg 201 | [npm-version-href]: https://npmjs.com/package/@nuxtjs/localforage 202 | 203 | [npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/localforage.svg 204 | [npm-downloads-href]: https://npmjs.com/package/@nuxtjs/localforage 205 | 206 | [github-actions-ci-src]: https://github.com/nuxt-community/localforage-module/workflows/ci/badge.svg 207 | [github-actions-ci-href]: https://github.com/nuxt-community/localforage-module/actions?query=workflow%3Aci 208 | 209 | [codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/localforage-module.svg 210 | [codecov-href]: https://codecov.io/gh/nuxt-community/localforage-module 211 | 212 | [license-src]: https://img.shields.io/npm/l/@nuxtjs/localforage.svg 213 | [license-href]: https://npmjs.com/package/@nuxtjs/localforage 214 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | '@commitlint/config-conventional' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /husky.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | hooks: { 3 | 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', 4 | 'pre-commit': 'yarn lint', 5 | 'pre-push': 'yarn lint' 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | collectCoverage: true, 3 | collectCoverageFrom: ['lib/**/*.js', '!lib/plugin.js'], 4 | testEnvironment: 'node' 5 | } 6 | -------------------------------------------------------------------------------- /lib/module.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path') 2 | 3 | module.exports = function (moduleOptions) { 4 | const options = { 5 | name: 'nuxtJS', 6 | storeName: 'nuxtLocalForage', 7 | ...this.options.localforage, 8 | ...moduleOptions 9 | } 10 | 11 | this.addPlugin({ 12 | src: resolve(__dirname, 'plugin.js'), 13 | ssr: false, 14 | fileName: 'localforage.js', 15 | options 16 | }) 17 | } 18 | 19 | module.exports.meta = require('../package.json') 20 | -------------------------------------------------------------------------------- /lib/plugin.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueLocalforage from 'v-localforage' 3 | 4 | Vue.use(VueLocalforage, <%= serialize(options) %>) 5 | 6 | export default (ctx, inject) => { 7 | inject('localForage', Vue.$localforage) 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nuxtjs/localforage", 3 | "version": "1.1.0", 4 | "description": "Localforage module for Nuxt.js", 5 | "repository": "nuxt-community/localforage-module", 6 | "license": "MIT", 7 | "contributors": [ 8 | "Alexandre Chopin ", 9 | "Ricardo Gobbo de Souza " 10 | ], 11 | "main": "lib/module.js", 12 | "files": [ 13 | "lib" 14 | ], 15 | "scripts": { 16 | "dev": "nuxt test/fixture", 17 | "lint": "eslint --ext .js,.vue lib test", 18 | "release": "yarn test && standard-version && git push --follow-tags && npm publish", 19 | "test": "yarn lint && jest" 20 | }, 21 | "dependencies": { 22 | "v-localforage": "^2.0.1" 23 | }, 24 | "devDependencies": { 25 | "@commitlint/cli": "latest", 26 | "@commitlint/config-conventional": "latest", 27 | "@nuxtjs/eslint-config": "latest", 28 | "@nuxtjs/module-test-utils": "latest", 29 | "eslint": "latest", 30 | "husky": "latest", 31 | "jest": "latest", 32 | "nuxt-edge": "latest", 33 | "standard-version": "latest" 34 | }, 35 | "publishConfig": { 36 | "access": "public" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@nuxtjs" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixture/nuxt.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | rootDir: __dirname, 3 | buildModules: [ 4 | { handler: require('../../') } 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/fixture/pages/index.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 19 | -------------------------------------------------------------------------------- /test/module.test.js: -------------------------------------------------------------------------------- 1 | const { setup, loadConfig, url } = require('@nuxtjs/module-test-utils') 2 | 3 | describe('module', () => { 4 | let nuxt 5 | 6 | beforeAll(async () => { 7 | ({ nuxt } = (await setup(loadConfig(__dirname)))) 8 | }, 60000) 9 | 10 | afterAll(async () => { 11 | await nuxt.close() 12 | }) 13 | 14 | test('render', async () => { 15 | const window = await nuxt.server.renderAndGetWindow(url('/')) 16 | const html = window.document.body.innerHTML 17 | expect(html).toContain('Length: 1') 18 | }) 19 | }) 20 | --------------------------------------------------------------------------------