Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@doars/doars-persist
Advanced tools
Doars plugin that adds cookies, local storage, and sessions storage contexts to get and set persistent data.
Plugin that adds cookies, local storage, and sessions storage contexts to get and set persistent data.
Install the package from NPM, then import and enable the library in your build.
npm i @doars/doars @doars/doars-persist
// Import library.
import Doars from '@doars/doars'
import DoarsPersist from '@doars/doars-persist'
// Setup a library instance.
const doars = new Doars()
// Setup the plugin.
const doarsPersist = DoarsPersist(doars /*, options */)
// Enable library.
doars.enable()
Add the IIFE build to the page from for example the jsDelivr CDN and enable the library.
<!-- Import library. -->
<script src="https://cdn.jsdelivr.net/npm/@doars/doars@3/dst/doars.iife.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@doars/doars-persist@3/dst/doars-persist.iife.js"></script>
<script type="application/javascript">
document.addEventListener('DOMContentLoaded', () => {
// Setup a library instance.
const doars = new window.Doars()
// Setup the plugin.
const doarsPersist = window.DoarsPersist(doars /*, options */)
// Enable library.
doars.enable()
})
</script>
The following contexts are added by the plugin.
Access the cookies object.
<!-- Sets a 'hello' cookie to 'world' -->
<div d-initialize="$cookies.hello = 'world'"></div>
<!-- Logs the 'hello' cookie the console -->
<div d-initialize="console.log($cookies.hello)"></div>
<!-- Deletes the 'hello' cookie -->
<div d-initialize="$cookies.hello = null"></div>
Access the local storage object.
<!-- Sets a 'hello' value on local storage to 'world' -->
<div d-initialize="$localStorage.hello = 'world'"></div>
<!-- Logs the 'hello' value from local storage the console -->
<div d-initialize="console.log($localStorage.hello)"></div>
<!-- Deletes the 'hello' local storage value -->
<div d-initialize="$localStorage.hello = null"></div>
Access the session storage object.
<!-- Sets a 'hello' value on session storage to 'world' -->
<div d-initialize="$sessionStorage.hello = 'world'"></div>
<!-- Logs the 'hello' value from session storage the console -->
<div d-initialize="console.log($sessionStorage.hello)"></div>
<!-- Deletes the 'hello' session storage value -->
<div d-initialize="$sessionStorage.hello = null"></div>
constructor
Create plugin instance.
@param {Doars} library
A doars library instance.@param {object} options = null
See options.@returns {DoarsPersist}
disable
Disables the plugin. Can only be called when the doars is disabled.enable
Enables the plugin. Can only be called when the doars is disabled.{boolean} cookiesContextDeconstruct = false
Whether to deconstruct the context so when accessing the properties you do not need to prefix it with $cookies
. Do note the $cookies
context will be checked after the $for
and $state
contexts since the $cookies
context is inserted before the others. This means that when a property exists on both the cookies and state the value from the state will be returned.{string} cookiesContextName = '$cookies'
The name of the cookies context.{boolean} localStorageContextDeconstruct = false
Whether to deconstruct the context so when accessing the properties you do not need to prefix it with $localStorage
. Do note the $localStorage
context will be checked after the $for
and $state
contexts since the $localStorage
context is inserted before the others. This means that when a property exists on both the local storage and state the value from the state will be returned.{string} localStorageContextName = '$localStorage'
The name of the local storage context.{boolean} sessionStorageContextDeconstruct = false
Whether to deconstruct the context so when accessing the properties you do not need to prefix it with $sessionStorage
. Do note the $sessionStorage
context will be checked after the $for
and $state
contexts since the $sessionStorage
context is inserted before the others. This means that when a property exists on both the session storage and state the value from the state will be returned.{string} sessionStorageContextName = '$sessionStorage'
The name of the session storage context.@doars/doars-persist version | @doars/doars version |
---|---|
3.x | 3.x |
FAQs
Doars plugin that adds cookies, local storage, and sessions storage contexts to get and set persistent data.
We found that @doars/doars-persist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.