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.
- 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.
You can install the package via npm:
npm install uniapp-plus-plugin-cache-size
or
pnpm add uniapp-plus-plugin-cache-size
This package provides two main functions:
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"
});
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"
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/');
- 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.
Contributions are welcome! If you'd like to improve this utility, feel free to open issues or submit pull requests.
- Fork the repository
- Create a new branch for your feature/bugfix
- Submit a pull request with your changes
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! 😎