localstory

WebJar for localstory

Лицензия

Лицензия

ISC
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

localstory
Последняя версия

Последняя версия

0.8.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

localstory
WebJar for localstory
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/ricardobeat/localstory

Скачать localstory

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/localstory/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>localstory</artifactId>
    <version>0.8.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/localstory/
implementation 'org.webjars.npm:localstory:0.8.2'
// https://jarcasting.com/artifacts/org.webjars.npm/localstory/
implementation ("org.webjars.npm:localstory:0.8.2")
'org.webjars.npm:localstory:jar:0.8.2'
<dependency org="org.webjars.npm" name="localstory" rev="0.8.2">
  <artifact name="localstory" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='localstory', version='0.8.2')
)
libraryDependencies += "org.webjars.npm" % "localstory" % "0.8.2"
[org.webjars.npm/localstory "0.8.2"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

localstory

NPM version Build status

A lightweight (0.8kb) wrapper around browser storage APIs (localStorage / sessionStorage).

Features

  • namespaces to avoid key collisions
  • per-value TTL expires
  • safe API (avoids throwing errors)
  • zero dependencies
npm install localstory

Usage

const store = require('localstory')(window.localStorage, 'myNamespace', { ttl: '45m' })

store.set('foo', 'bar')
store.get('foo') // 'bar'
store.unset('foo')

store.keys() // ['foo']
store.clear()

Namespacing

Use namespaces to freely use IDs without fear of collisions between different applications/stores in the same domain.

const horses = localstory(window.localStorage, 'horses')
const ponies = localstory(window.localStorage, 'ponies')

horses.set('name', 'Thunder')
ponies.get('name') // undefined

ponies.set('name', 'Sparkle')

horses.get('name') // 'Thunder'
ponies.get('name') // 'Sparkle'

Expiry / TTL

Automatically expire values. Expiry is validated on reads and once on load (can be disabled with vacuum: false). Each key can have it's own expiry time.

To enable, provide { ttl: [milliseconds] } as second parameter to the set() method:

store.set('foo', 'bar', { ttl: 1000 * 60 * 60 /* 1 hour */ })

store.get('foo') // 'bar'
store.get('foo') // one hour later... undefined

// time parameter takes human readable strings: [s]econds, [m]inutes, [h]ours, [d]ays
store.set('foo', 'bar', { ttl: '1h' })

store.vacuum() // removes all expired keys

// disable automatic vacuum on startup
const store = localstory(localStorage, 'namespace', { vacuum: false })

// set custom delay (in ms) for vacuum on startup
const store = localstory(localStorage, 'namespace', { vacuum: 15000 })

Tests

Uses the tape test runner. Run tests with npm test after installing dependencies.

Contributing

https://github.com/ricardobeat/localstory

Made by Ricardo Tomasi

Версии библиотеки

Версия
0.8.2