{"id":13403853,"url":"https://github.com/localForage/localForage","last_synced_at":"2025-03-14T08:32:15.140Z","repository":{"id":11521254,"uuid":"14003349","full_name":"localForage/localForage","owner":"localForage","description":"💾 Offline storage, improved. Wraps IndexedDB, WebSQL, or localStorage using a simple but powerful API.","archived":false,"fork":false,"pushed_at":"2024-01-08T04:02:29.000Z","size":4857,"stargazers_count":24217,"open_issues_count":249,"forks_count":1254,"subscribers_count":311,"default_branch":"master","last_synced_at":"2024-04-13T22:23:52.705Z","etag":null,"topics":["indexeddb","javascript","localforage","localstorage","offline","storage","websql"],"latest_commit_sha":null,"homepage":"https://localforage.github.io/localForage","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localForage.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-10-31T00:10:06.000Z","updated_at":"2024-04-13T14:36:09.000Z","dependencies_parsed_at":"2023-01-13T16:33:02.662Z","dependency_job_id":"55b2ab15-0323-405e-98cb-d53fa138f05d","html_url":"https://github.com/localForage/localForage","commit_stats":{"total_commits":877,"total_committers":111,"mean_commits":7.900900900900901,"dds":"0.49372862029646525","last_synced_commit":"c5b66157252988dc4e74a3eab5226b59be376a2f"},"previous_names":["mozilla/localforage"],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localForage%2FlocalForage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localForage%2FlocalForage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localForage%2FlocalForage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localForage%2FlocalForage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localForage","download_url":"https://codeload.github.com/localForage/localForage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243547531,"owners_count":20308719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["indexeddb","javascript","localforage","localstorage","offline","storage","websql"],"created_at":"2024-07-30T19:01:35.489Z","updated_at":"2025-03-14T08:32:15.116Z","avatar_url":"https://github.com/localForage.png","language":"JavaScript","readme":"# localForage\n[![NPM version](https://badge.fury.io/js/localforage.svg)](http://badge.fury.io/js/localforage)\n[![npm](https://img.shields.io/npm/dm/localforage.svg?maxAge=2592000)](https://npmcharts.com/compare/localforage?minimal=true)\n[![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/localforage/badge?style=rounded)](https://www.jsdelivr.com/package/npm/localforage)\n[![minzipped size](https://badgen.net/bundlephobia/minzip/localforage)](https://bundlephobia.com/result?p=localforage@1.10.0)\n\nlocalForage is a fast and simple storage library for JavaScript. localForage\nimproves the offline experience of your web app by using asynchronous storage\n(IndexedDB or WebSQL) with a simple, `localStorage`-like API.\n\nlocalForage uses localStorage in browsers with no IndexedDB or\nWebSQL support. See [the wiki for detailed compatibility info][supported browsers].\n\nTo use localForage, just drop a single JavaScript file into your page:\n\n```html\n\u003cscript src=\"localforage/dist/localforage.js\"\u003e\u003c/script\u003e\n\u003cscript\u003elocalforage.getItem('something', myCallback);\u003c/script\u003e\n```\nTry the [live example](http://codepen.io/thgreasi/pen/ojYKeE).\n\nDownload the [latest localForage from GitHub](https://github.com/localForage/localForage/releases/latest), or install with\n[npm](https://www.npmjs.com/):\n\n```bash\nnpm install localforage\n```\n\n[supported browsers]: https://github.com/localForage/localForage/wiki/Supported-Browsers-Platforms\n\n## Support\n\nLost? Need help? Try the\n[localForage API documentation](https://localforage.github.io/localForage). [localForage API文档也有中文版。](https://localforage.docschina.org)\n\nIf you're having trouble using the library, running the tests, or want to contribute to localForage, please look through the [existing issues](https://github.com/localForage/localForage/issues) for your problem first before creating a new one. If you still need help, [feel free to file an issue](https://github.com/localForage/localForage/issues/new).\n\n# How to use localForage\n\n## Callbacks vs Promises\n\nBecause localForage uses async storage, it has an async API.\nIt's otherwise exactly the same as the\n[localStorage API](https://hacks.mozilla.org/2009/06/localstorage/).\n\nlocalForage has a dual API that allows you to either use Node-style callbacks\nor [Promises](https://www.promisejs.org/). If you are unsure which one is right for you, it's recommended to use Promises.\n\nHere's an example of the Node-style callback form:\n\n```js\nlocalforage.setItem('key', 'value', function (err) {\n  // if err is non-null, we got an error\n  localforage.getItem('key', function (err, value) {\n    // if err is non-null, we got an error. otherwise, value is the value\n  });\n});\n```\n\nAnd the Promise form:\n\n```js\nlocalforage.setItem('key', 'value').then(function () {\n  return localforage.getItem('key');\n}).then(function (value) {\n  // we got our value\n}).catch(function (err) {\n  // we got an error\n});\n```\n\nOr, use `async`/`await`:\n\n```js\ntry {\n    const value = await localforage.getItem('somekey');\n    // This code runs once the value has been loaded\n    // from the offline store.\n    console.log(value);\n} catch (err) {\n    // This code runs if there were any errors.\n    console.log(err);\n}\n```\n\nFor more examples, please visit [the API docs](https://localforage.github.io/localForage).\n\n## Storing Blobs, TypedArrays, and other JS objects\n\nYou can store any type in localForage; you aren't limited to strings like in\nlocalStorage. Even if localStorage is your storage backend, localForage\nautomatically does `JSON.parse()` and `JSON.stringify()` when getting/setting\nvalues.\n\nlocalForage supports storing all native JS objects that can be serialized to\nJSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the\n[API docs][api] for a full list of types supported by localForage.\n\nAll types are supported in every storage backend, though storage limits in\nlocalStorage make storing many large Blobs impossible.\n\n[api]: https://localforage.github.io/localForage/#data-api-setitem\n\n## Configuration\n\nYou can set database information with the `config()` method.\nAvailable options are `driver`, `name`, `storeName`, `version`, `size`, and\n`description`.\n\nExample:\n```javascript\nlocalforage.config({\n    driver      : localforage.WEBSQL, // Force WebSQL; same as using setDriver()\n    name        : 'myApp',\n    version     : 1.0,\n    size        : 4980736, // Size of database, in bytes. WebSQL-only for now.\n    storeName   : 'keyvaluepairs', // Should be alphanumeric, with underscores.\n    description : 'some description'\n});\n```\n\n**Note:** you must call `config()` _before_ you interact with your data. This\nmeans calling `config()` before using `getItem()`, `setItem()`, `removeItem()`,\n`clear()`, `key()`, `keys()` or `length()`.\n\n## Multiple instances\n\nYou can create multiple instances of localForage that point to different stores\nusing `createInstance`. All the configuration options used by\n[`config`](#configuration) are supported.\n\n``` javascript\nvar store = localforage.createInstance({\n  name: \"nameHere\"\n});\n\nvar otherStore = localforage.createInstance({\n  name: \"otherName\"\n});\n\n// Setting the key on one of these doesn't affect the other.\nstore.setItem(\"key\", \"value\");\notherStore.setItem(\"key\", \"value2\");\n```\n\n## RequireJS\n\nYou can use localForage with [RequireJS](http://requirejs.org/):\n\n```javascript\ndefine(['localforage'], function(localforage) {\n    // As a callback:\n    localforage.setItem('mykey', 'myvalue', console.log);\n\n    // With a Promise:\n    localforage.setItem('mykey', 'myvalue').then(console.log);\n});\n```\n\n## TypeScript\n\nIf you have the [`allowSyntheticDefaultImports` compiler option](https://www.typescriptlang.org/docs/handbook/compiler-options.html) set to `true` in your [tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (supported in TypeScript v1.8+), you should use:\n\n```javascript\nimport localForage from \"localforage\";\n```\n\nOtherwise you should use one of the following:\n\n```javascript\nimport * as localForage from \"localforage\";\n// or, in case that the typescript version that you are using\n// doesn't support ES6 style imports for UMD modules like localForage\nimport localForage = require(\"localforage\");\n```\n\n## Framework Support\n\nIf you use a framework listed, there's a localForage storage driver for the\nmodels in your framework so you can store data offline with localForage. We\nhave drivers for the following frameworks:\n\n* [AngularJS](https://github.com/ocombe/angular-localForage)\n* [Angular 4 and up](https://github.com/Alorel/ngforage/)\n* [Backbone](https://github.com/localForage/localForage-backbone)\n* [Ember](https://github.com/genkgo/ember-localforage-adapter)\n* [Vue](https://github.com/dmlzj/vlf)\n* [NuxtJS](https://github.com/nuxt-community/localforage-module)\n\nIf you have a driver you'd like listed, please\n[open an issue](https://github.com/localForage/localForage/issues/new) to have it\nadded to this list.\n\n## Custom Drivers\n\nYou can create your own driver if you want; see the\n[`defineDriver`](https://localforage.github.io/localForage/#driver-api-definedriver) API docs.\n\nThere is a [list of custom drivers on the wiki][custom drivers].\n\n[custom drivers]: https://github.com/localForage/localForage/wiki/Custom-Drivers\n\n# Working on localForage\n\nYou'll need [node/npm](http://nodejs.org/) and\n[bower](http://bower.io/#installing-bower).\n\nTo work on localForage, you should start by\n[forking it](https://github.com/localForage/localForage/fork) and installing its\ndependencies. Replace `USERNAME` with your GitHub username and run the\nfollowing:\n\n```bash\n# Install bower globally if you don't have it:\nnpm install -g bower\n\n# Replace USERNAME with your GitHub username:\ngit clone git@github.com:USERNAME/localForage.git\ncd localForage\nnpm install\nbower install\n```\n\nOmitting the bower dependencies will cause the tests to fail!\n\n## Running Tests\n\nYou need PhantomJS installed to run local tests. Run `npm test` (or,\ndirectly: `grunt test`). Your code must also pass the\n[linter](http://jshint.com/).\n\nlocalForage is designed to run in the browser, so the tests explicitly require\na browser environment. Local tests are run on a headless WebKit (using\n[PhantomJS](http://phantomjs.org)).\n\nWhen you submit a pull request, tests will be run against all browsers that\nlocalForage supports on Travis CI using [Sauce Labs](https://saucelabs.com/).\n\n## Library Size\nAs of version 1.7.3 the payload added to your app is rather small. Served using gzip compression, localForage will add less than 10k to your total bundle size:\n\n\u003cdl\u003e\n  \u003cdt\u003eminified\u003c/dt\u003e\u003cdd\u003e`~29kB`\u003c/dd\u003e\n  \u003cdt\u003egzipped\u003c/dt\u003e\u003cdd\u003e`~8.8kB`\u003c/dd\u003e\n  \u003cdt\u003ebrotli'd\u003c/dt\u003e\u003cdd\u003e`~7.8kB`\u003c/dd\u003e\n\u003c/dl\u003e\n\n# License\n\nThis program is free software; it is distributed under an\n[Apache License](https://github.com/localForage/localForage/blob/master/LICENSE).\n\n---\n\nCopyright (c) 2013-2016 [Mozilla](https://mozilla.org)\n([Contributors](https://github.com/localForage/localForage/graphs/contributors)).\n","funding_links":[],"categories":["JavaScript","javascript","awesome-web-storage [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)","Tools 🧰","目录","网络服务","Repository","Tools"],"sub_categories":["Different Storage APIs","网络服务_其他","Storage","Data","Slides"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlocalForage%2FlocalForage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FlocalForage%2FlocalForage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlocalForage%2FlocalForage/lists"}