File edition helpers working on top of mem-fs
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
File state management system for tracking file lifecycle states, commit status, and managing pending changes in the mem-fs-editor store.
Set, check, and manage file states for tracking modifications and deletions.
/**
* Set the state of a file
* @param file - The file object to modify
* @param state - The state value to set ('modified' | 'deleted')
*/
function setFileState(file: MemFsEditorFile, state: 'modified' | 'deleted'): void;
/**
* Check if a file is new (doesn't exist on disk)
* @param file - The file object to check
* @returns True if file is new, false if it exists on disk
*/
function isFileNew(file: MemFsEditorFile): boolean;
/**
* Check if a file's state is marked as modified
* @param file - The file object to check
* @returns True if file state is 'modified'
*/
function isFileStateModified(file: MemFsEditorFile): boolean;
/**
* Set a file's state to modified
* @param file - The file object to modify
*/
function setModifiedFileState(file: MemFsEditorFile): void;
/**
* Check if a file's state is marked as deleted
* @param file - The file object to check
* @returns True if file state is 'deleted'
*/
function isFileStateDeleted(file: MemFsEditorFile): boolean;
/**
* Set a file's state to deleted
* @param file - The file object to modify
*/
function setDeletedFileState(file: MemFsEditorFile): void;
/**
* Check if a file has pending changes (modified or deleted but not new)
* @param file - The file object to check
* @returns True if file has pending changes
*/
function isFilePending(file: MemFsEditorFile): boolean;Manage file commit status and track which files have been committed to disk.
/**
* Mark a file as committed to disk
* @param file - The file object to mark as committed
*/
function setCommittedFile(file: MemFsEditorFile): void;
/**
* Check if a file has been committed to disk
* @param file - The file object to check
* @returns True if file is committed
*/
function isFileCommitted(file: MemFsEditorFile): boolean;Reset file states and clean up internal state tracking properties.
/**
* Reset the file state (remove state property)
* @param file - The file object to reset
*/
function resetFileState(file: MemFsEditorFile): void;
/**
* Delete commit-related states (stateCleared and committed properties)
* @param file - The file object to clean up
*/
function resetFileCommitStates(file: MemFsEditorFile): void;
/**
* Delete all mem-fs-editor related states (complete cleanup)
* @param file - The file object to reset completely
*/
function resetFile(file: MemFsEditorFile): void;
/**
* Clear file state by moving current state to stateCleared
* @param file - The file object to clear state for
*/
function clearFileState(file: MemFsEditorFile): void;Check for the presence of state properties on file objects.
/**
* Check if a file has any state property set
* @param file - The file object to check
* @returns True if file has a state property
*/
function hasState(file: MemFsEditorFile): boolean;
/**
* Check if a file has a cleared state property
* @param file - The file object to check
* @returns True if file has a stateCleared property
*/
function hasClearedState(file: MemFsEditorFile): boolean;import {
setFileState,
isFileNew,
isFileStateModified,
setModifiedFileState,
isFilePending,
resetFile
} from "mem-fs-editor/state";
import { create as createMemFs } from "mem-fs";
import { create as createEditor } from "mem-fs-editor";
const store = createMemFs();
const fs = createEditor(store);
// Write a file and check its state
fs.write("example.txt", "Hello World");
const file = store.get("example.txt");
// Check if file is new
console.log(isFileNew(file)); // true (doesn't exist on disk yet)
// File is automatically marked as modified when written
console.log(isFileStateModified(file)); // true
// Check if file has pending changes
console.log(isFilePending(file)); // true
// After committing, the file state changes
await fs.commit();
console.log(isFilePending(file)); // false
// Manually manage file states
const anotherFile = store.get("another.txt");
setModifiedFileState(anotherFile);
// Clean up all states when done
resetFile(file);Files in mem-fs-editor follow this state lifecycle:
isNew: true when file doesn't exist on diskstate: 'modified' when file contents changestate: 'deleted' when file is marked for deletioncommitted: true after successful commit to diskstateCleared: 'modified'|'deleted' when state is cleared but preservedThe state management functions allow you to query and manipulate files at any point in this lifecycle, providing fine-grained control over file operations and commit behavior.