uniapp-plus-plugin-cache-size
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

File UserData Size Utils 📦

A utility for calculating directory sizes and converting bytes to human-readable formats, tailored for uni-app applications. This package allows you to calculate the size of any given directory in your uni-app project and clean up user data (cache, files, etc.) easily. It's a simple tool for managing storage in uni-app apps.

Features ✨

  • Directory Size Calculation: Calculate the total size of files within a specific directory (including nested subdirectories).
  • Size Formatting: Convert raw byte size to a human-readable format like B, KB, MB, GB, etc.
  • Clean User Data: A utility for clearing out cache or user-generated files in uni-app applications.
  • Remove Directory: A utility for removing a specified directory (including all contents) in uni-app applications, such as the path: /storage/emulated/0/Android/data/packageName/apps/appid/doc/video .
  • Optimized Bundle Size: Using Vite to build the bundle and Tree Shaking to reduce the final size.

Installation 🚀

You can install the package via npm:

npm install uniapp-plus-plugin-cache-size  

or

pnpm add uniapp-plus-plugin-cache-size

Usage 📑

This package provides two main functions:

1. getDirSize(url: string, callback: (totalSize: number) => void): void

Calculate the total size of a specified directory. It supports nested directories and returns the size in bytes.

Example:

import { getDirSize, formatSize } from 'uniapp-plus-plugin-cache-size';

// Get the size of '_doc/video/' directory
getDirSize('_doc/video/', (size) => {
  console.log('Directory Size:', formatSize(size));  // E.g., "Directory Size: 45.3 MB"
});

2. formatSize(bytes: number): string

Format the size in bytes into a human-readable string, converting it into units like B, KB, MB, GB, etc.

Example:

const sizeInBytes = 1048576;  // 1MB in bytes
console.log(formatSize(sizeInBytes));  // Output: "1.00 MB"

3. deleteDir(url: string): void

Clears the files in a specified directory to free up storage space, perfect for cleaning up user data or cached files in a uni-app application.

Example:

import { deleteDir } from 'uniapp-plus-plugin-cache-size';

// Clear cache in '_doc/video/' directory
deleteDir('_doc/video/');

Why Use This? 🤔

  • Space Management: As your uni-app app grows, it can accumulate a lot of cache and files. Use this utility to quickly calculate storage usage and clear up space.
  • User Data Cleanup: Perfect for apps where users can upload or store files. Easily clear out old data or cache to optimize performance.
  • Compatibility: Works with uni-app and HTML5+ environments, making it ideal for mobile and cross-platform applications.

Contributing 💪

Contributions are welcome! If you'd like to improve this utility, feel free to open issues or submit pull requests.

How to contribute:

  1. Fork the repository
  2. Create a new branch for your feature/bugfix
  3. Submit a pull request with your changes

License 📜

This project is licensed under the MIT License - see the LICENSE file for details.


👨‍💻 Developed by cherishtao

Thanks for using uniapp-plus-plugin-cache-size! 😎

Package Sidebar

Install

npm i uniapp-plus-plugin-cache-size

Weekly Downloads

7

Version

1.3.1

License

MIT

Unpacked Size

25.5 kB

Total Files

8

Last publish

Collaborators

  • cherishtao