1.1.6 • Published 4 years ago

simple-browser-session v1.1.6

Weekly downloads
9
License
MIT
Repository
-
Last release
4 years ago

simple-browser-session

Library to get/set session values from localStorage/cookie and/or URL query string.

simple-browser-session

How to use

import { getSessionValue, setSessionValue } from 'simple-browser-session'

Get a value:

getSessionValue(property, defaultValue, options = { useHash: false, useCookies: false, cookieName: 'app' })

Set a value:

setSessionValue(property, value, options = { updateStored: true, updatePath: false, useHash: false, useCookies: false, cookieName: 'app' })

Options

  • cookieName: app as default.
  • updateStored: true/false, update localStorage/cookie
  • updatePath: true/false, update browser URL
  • useCookies: false as default, uses localStorage if not true.
  • useHash: true/false, uses values after # in URL if true.

How it works

simple-browser-session uses localStorage, or creates a cookie called app (this can be changed with the cookieName prop).

localStorage/cookie contains a (serialized) JSON object with all the values that you save with setSessionValue.

simple-browser-session uses both the URL query string (e.g. ?name=value) and localStorage/cookie. Query strings have precedence over localStorage/cookie.

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.0

5 years ago