todotxt4js
    Preparing search index...

    Class TodoList

    A class representing a collection of todo.txt todos. Provides methods for parsing, managing, and querying todos in the todo.txt format.

    Index

    Constructors

    • Creates a new TodoList instance.

      Parameters

      • Optionaltext: string

        Optional todotxt text to parse into todos.

      Returns TodoList

    Properties

    todos: Todo[]

    Array of Todo objects managed by this TodoList

    Methods

    • Add a new todo from a single line of text.

      Parameters

      • line: string

        The todotxt formatted line to parse.

      • OptionalparserOptions: ParserOptions

        Optional configuration for the parser.

      Returns void

    • Add a todo object directly to the list.

      Parameters

      • todo: Todo

        The Todo object to add.

      Returns void

    • Delete a todo by id.

      Parameters

      • todoId: string

        The unique identifier of the todo to delete.

      Returns void

    • Delete a todo by object reference.

      Parameters

      • todo: Todo

        The Todo object to delete.

      Returns void

    • Edit a todo by id using an updater function.

      Parameters

      • todoId: string

        The unique identifier of the todo to edit.

      • updater: (todo: Todo) => void

        Function that modifies the todo object.

      Returns void

      If the todo with the specified ID is not found.

    • Edit a todo by providing a todo object with the same ID.

      Parameters

      • updatedTodo: Todo

        The modified Todo object with the same ID as the todo to replace.

      Returns void

      If the todo with the specified ID is not found.

    • Filter todos based on multiple criteria.

      Parameters

      • criteria: {
            completed?: boolean;
            contexts?: string[];
            dueAfter?: string;
            dueBefore?: string;
            priority?: string;
            projects?: string[];
        }

        An object containing filter criteria.

        • Optionalcompleted?: boolean

          Whether to include completed todos.

        • Optionalcontexts?: string[]

          Filter by context names.

        • OptionaldueAfter?: string

          Include todos due after this date (YYYY-MM-DD).

        • OptionaldueBefore?: string

          Include todos due before this date (YYYY-MM-DD).

        • Optionalpriority?: string

          Filter by priority.

        • Optionalprojects?: string[]

          Filter by project names.

      Returns Todo[]

      Array of todos matching all specified criteria.

    • Get todos that are marked as completed.

      Returns Todo[]

      Array of completed todos.

    • Get all unique contexts used across all todos.

      Returns string[]

      Array of unique context names.

    • Get todos that are due within a specified number of days from today.

      Parameters

      • n: number

        Number of days from today.

      Returns Todo[]

      Array of todos due within the specified time period.

    • Get todos that are not marked as completed.

      Returns Todo[]

      Array of incomplete todos.

    • Get all unique key names used in key-value pairs across all todos.

      Returns string[]

      Array of unique key names.

    • Get todos that are past their due date and not completed.

      Returns Todo[]

      Array of overdue todos.

    • Get all unique projects used across all todos.

      Returns string[]

      Array of unique project names.

    • Get a specific todo by its unique identifier.

      Parameters

      • todoId: string

        The unique identifier of the todo to retrieve.

      Returns undefined | Todo

      The matching todo or undefined if not found.

    • Get a todo by its position in the todo list (zero-based).

      Parameters

      • lineNumber: number

        The line number (0-based index).

      Returns undefined | Todo

      The todo at the specified position or undefined if out of bounds.

    • Get todos that include a specific context.

      Parameters

      • context: string

        The context to search for (without the @ symbol).

      Returns Todo[]

      Array of todos containing the specified context.

    • Get todos that match a specific key-value pair.

      Parameters

      • key: string

        The key name to match.

      • value: any

        The value to match against.

      Returns Todo[]

      Array of todos matching the key-value pair.

    • Get todos that include a specific project.

      Parameters

      • project: string

        The project to search for (without the + symbol).

      Returns Todo[]

      Array of todos containing the specified project.

    • Get todos that match a specific property value.

      Type Parameters

      • T extends keyof Todo

      Parameters

      • property: T

        The property name to match.

      • value: Todo[T]

        The value to match against.

      Returns Todo[]

      Array of todos matching the property value.

    • Parse a multiline todotxt text. Each non-empty line is parsed as a separate todo. Throws an error if any todo fails to parse.

      Parameters

      • text: string

        The todotxt formatted string to parse.

      • OptionalparserOptions: ParserOptions

        Optional configuration for the parser.

      Returns void

    • Add multiple todo objects directly to the list.

      Parameters

      • todos: Todo[]

        Array of Todo objects to add to the list.

      Returns void

    • Sort todos by a given criteria.

      Parameters

      • criteria: "priority" | "due" | "creation" | "completion"

        The criteria to sort by: "priority", "due", "creation", or "completion".

      Returns void

    • Convert the todo list back to a string representation. This generates a complete todotxt output with one todo per line.

      Returns string

      The string representation of all todos.