0.0.3 • Published 7 months ago

ezss v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

EZSS npm install size bundle size

Easier alternative of react-secure-storage.

Why

The react-secure-storage code is unnecessarily complex and doesn't support custom data types.

EZSS only implements its internal EncryptionService class so that you can use it with the libraries you want. (e.g. @mantine/hooks)

Install

pnpm add ezss
# yarn add ezss
# npm i ezss

Usage Examples

do you have other examples? PR's welcome!

@mantine/hooks - useLocalStorage
import { useLocalStorage } from '@mantine/hooks'
import encryption from 'ezss' // A
// import { EncryptionService } from 'ezss' // B

export const useSecureLocalStorage =
  <T = string>(props: Parameters<typeof useLocalStorage<T>>[0]) => {
    // const encryption = new EncryptionService() // B

    return useLocalStorage<T>({
      ...props,
      serialize: value => encryption.encrypt(JSON.stringify(value)),
      deserialize: value => {
        if (value) {
          try {
            return JSON.parse(encryption.decrypt(value))
          } catch {
            return encryption.decrypt(value)
          }
        } else return value
      },
    })
  }

License

Licensed under the MIT.

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago