Service for managing snippets and interacting with data access.

Constructors

Methods

  • Adds an existing snippet to the appropriate parent in the snippet collection. If the parent ID is root, the snippet is added to the root's children. Otherwise, the snippet is added to the parent identified by the parentId.

    Parameters

    • newSnippet: Snippet

      The snippet to add.

    Returns void

  • Converts the root snippet object to a JSON string representation.

    Returns string

    A JSON string of the root snippet.

  • Exports snippets from a specific parent to a destination file path.

    Parameters

    • destinationPath: string

      The path where snippets should be exported.

    • parentId: number

      The parent ID to start exporting from.

    Returns void

  • Ensures that the lastId property in the root snippet is updated to the maximum ID found in all snippets.

    Returns void

  • Retrieves the parent snippet by its ID.

    Parameters

    • parentId: undefined | number

      The ID of the parent snippet.

    Returns undefined | Snippet

    The parent snippet, or undefined if not found.

  • Imports snippets from a specified file path and replaces the current snippets. A backup of the current snippets is saved before the import.

    Parameters

    • destinationPath: string

      The path from which to import the snippets.

    Returns void

  • Increments and returns the next available ID for a snippet.

    Returns number

    The next available ID.

  • Moves a snippet by the specified offset in the list of its siblings.

    Parameters

    • snippet: Snippet

      The snippet to move.

    • offset: number

      The offset to move the snippet by (positive or negative).

    Returns void

  • Overrides the snippet's ID with a new ID and updates the snippet. The last used ID is also updated after assigning the new ID to the snippet.

    Parameters

    • snippet: Snippet

      The snippet to update with a new ID.

    Returns void

  • Removes a snippet from the collection locally without deleting the associated Gist.

    Parameters

    • snippet: Snippet

      The snippet to remove.

    Returns void

  • Updates an existing snippet in the collection by its ID and updates the associated Gist. If the snippet is a folder, the content is not updated; otherwise, the content is updated.

    Parameters

    • snippet: Snippet

      The snippet to update.

    Returns Promise<void>

  • Recursively searches for the parent snippet by its ID in the given snippet tree.

    Parameters

    • parentId: number

      The ID of the parent snippet to find.

    • currentElt: Snippet

      The current snippet being examined.

    Returns undefined | Snippet

    The parent snippet if found, otherwise undefined.

  • Parameters

    • arr: any
    • result: any[] = []

    Returns any[]