als-store
Version:
Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations
29 lines (20 loc) • 1.5 kB
Markdown
### Sorting Methods in Store Class
#### Sorting Properties
- **Purpose**: To define how files in the store can be sorted.
- **Available Properties for Sorting**:
- `name`: Sorts files based on their names.
- `stats.size`, `stats.birthtime`, etc.: Sorts files based on specific statistics like size, creation time, etc.
- Any other custom property defined in the files.
#### Specifying Sorting Order
- **Ascending Order**: By default, files are sorted in ascending order based on the chosen property.
- **Descending Order**: To sort in descending order, you can use either of the following methods:
- Prefix the property name with a minus sign (`-`). For example, `-name` sorts files by name in descending order.
- Use the `desc()` method after specifying the sorting property. For example, if you have set the sorting property as `name`, calling `desc()` will sort the files by name in descending order.
### Usage Examples
1. **Ascending Order**:
- `.sort('name')`: Sorts files by name in ascending order.
- `.sort('stats.size')`: Sorts files by size in ascending order.
2. **Descending Order**:
- `.sort('-name')`: Sorts files by name in descending order.
- `.sort('stats.size').desc()`: Sorts files by size in descending order.
These sorting methods allow users to organize files in the `Store` according to specific criteria, either in ascending or descending order, enhancing the flexibility and usability of the file management system.