DEV Community

Cover image for Discover Kando The Lightweight Storage Utility You Didn’t Know You Needed
A.S Nasseri
A.S Nasseri

Posted on

Discover Kando The Lightweight Storage Utility You Didn’t Know You Needed

Managing data storage in web and Node.js applications can sometimes feel cumbersome, especially when dealing with localStorage or sessionStorage. Meet Kando—a versatile 2KB gzip storage utility that streamlines your storage tasks with its intuitive API.

Whether you're working on a small web app or a complex Node.js project, Kando's flexibility and developer-friendly design can make your life easier. Let's dive into why it's worth a try!

Why Use Kando?

Kando offers powerful features in a lightweight package:

  • Cross-Environment Support: Works in both browsers and Node.js, with a fallback to an in-memory Map if localStorage or sessionStorage is unavailable.
  • Namespace Management: Organize and group related data for easier retrieval and cleanup.
  • Nested Path Access: Use dot notation to access or update deeply nested properties.
  • Data Expiration: Automatically expire session data after a defined duration.
  • Flexible Data Handling: Easily work with single values, arrays, and objects.

Installation

Node.js

Install Kando with npm:

npm install kando-storage
Enter fullscreen mode Exit fullscreen mode

Browser

Add Kando to your project using a script tag:

<script src="path/to/kando.js"></script>
Enter fullscreen mode Exit fullscreen mode

Quick Examples

Here are a few examples to get you started. More advanced usage is available in the GitHub repository.

Setting and Retrieving Data

const kando = require('kando-storage');

// Store a single value
kando('local.app.theme', 'dark');

// Retrieve the value
console.log(kando('local.app.theme')); // Output: 'dark'

// Store an object
kando('local.user.profile', { name: 'Alice', age: 30 });

// Retrieve the object
console.log(kando('local.user.profile')); // Output: { name: 'Alice', age: 30 }
Enter fullscreen mode Exit fullscreen mode

Clearing Data

// Remove a specific property
kando('local.user.profile.name', null);

// Clear an entire namespace
kando('local.user', null);
Enter fullscreen mode Exit fullscreen mode

Session Storage with Expiration

// Store session data with a 60-second expiration
kando('session.tempData', 'Temporary', 60);

// Access it before it expires
console.log(kando('session.tempData')); // Output: 'Temporary'

// After 60 seconds, it will automatically expire
Enter fullscreen mode Exit fullscreen mode

Dive Deeper into Kando

These examples only scratch the surface of what Kando can do. Check out the full README on GitHub for:

  • Advanced examples like handling nested paths, arrays, and namespaces.
  • Full API reference with parameter descriptions.
  • Guidance on using Kando’s fallback mechanism in Node.js environments.

Conclusion

Kando is a simple yet powerful tool to manage storage seamlessly across browsers and Node.js. Its small size, feature-rich API, and ease of use make it a must-try for developers.

Ready to simplify your storage? Get started on GitHub today! 🚀

Top comments (0)