ezss
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i ezss

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

43.8 kB

Total Files

6

Last publish

Collaborators

  • kwaa