als-store
Version:
Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations
58 lines (45 loc) • 2.8 kB
Markdown
### File Filtering Methods
#### Method: `skip(skip)`
- **Purpose**: Sets the number of files to skip before starting to collect files in the results.
- **Parameters**:
- `skip` (Number, required): The number of files to skip.
- **Returns**: The `Store` instance for method chaining.
- **Description**: This method sets the `skip` option in the internal `options` object, determining how many files will be skipped in the retrieval process.
#### Method: `limit(limit)`
- **Purpose**: Specifies the maximum number of files to include in the results.
- **Parameters**:
- `limit` (Number, required): The maximum number of files to retrieve.
- **Returns**: The `Store` instance for method chaining.
- **Description**: This method sets the `limit` option in the internal `options` object, controlling the maximum number of files that can be retrieved in one call.
#### Method: `level(level)`
- **Purpose**: Sets the depth level for file retrieval in directory substructures.
- **Parameters**:
- `level` (Number, required): The depth level for file retrieval.
- **Returns**: The `Store` instance for method chaining.
- **Description**: This method configures how deep the file retrieval process will go into the directory structure. A level of 0 means only the current directory, 1 includes one level of subdirectories, and so on.
#### Method: `dir(dir)`
- **Purpose**: Specifies a subdirectory within the main directory for file operations.
- **Parameters**:
- `dir` (String, required, 1-255 characters): The subdirectory path.
- **Returns**: The `Store` instance for method chaining.
- **Description**: This method sets a specific subdirectory path within the main directory where file operations (like retrieval and storage) will be focused.
- The subdirectory can be relative path to directory, like `somedir/anotherdir`
#### Method: `filter(...fns)`
- **Purpose**: Applies custom filter functions to the file retrieval process.
- **Parameters**:
- `...fns` (Function, required): One or more functions used as filters.
- **Returns**: The `Store` instance for method chaining.
- **Description**: This method allows adding custom filter functions to the internal `options.filters` array. Each filter function is applied in sequence to the file list during the retrieval process.
#### Example
```js
const jsFilter = (file) => file.name.endsWith('.js')
const sizeFilter = (file) => file.stats.size <= 1024
await store
.skip(10) // skip first 10 files
.limit(50) // limit to 50 files
.dir('some-dir') // include files only from some-dir folder
.level(2) // don't include files up to level 2
.filter(jsFilter,sizeFilter) // include only js files smaller than 1024 bytes
get()
console.log(store.results)
```