MultiLevelAutoNumbering

MultiLevelAutoNumbering

MultiLevelAutoNumbering A hierarchical auto-numbering utility supporting nested sequences like: ``` 1. 1.1. 1.2. 2. 2.1.1. ``` Internally uses a stack of AutoNumbering instances, one for each level. Supports `nest()` to go deeper and `unnest()` to go back. Example: ```js const ml = new MultiLevelAutoNumbering(); ml.next("Root A"); // "1. Root A" ml.nest().next("Child A"); // "1.1. Child A" ml.next("Child B"); // "1.2. Child B" ml.unnest().next("Root B"); // "2. Root B" ml.next("Root C"); // "3. Root B" ```

Constructor

new MultiLevelAutoNumbering(startValueopt)

Description:
  • Creates a new multi-level auto-numbering generator. Only the default format `"{0}. "` is supported — other formats are not allowed.
Source:
Parameters:
Name Type Attributes Default Description
startValue number <optional>
1 The starting number for the top-level counter.
Throws:
If a custom numbering format is provided.
Type
Error

Classes

MultiLevelAutoNumbering

Members

level

Description:
  • Gets the current nesting level (1 = root).
Source:
Gets the current nesting level (1 = root).

Methods

nest(startValueopt) → {MultiLevelAutoNumbering}

Description:
  • Increases the nesting level (e.g., goes from `2.` to `2.1.`, or from `1.2.` to `1.2.1.`). The new level resets its own counter, while prefixing the last generated parent string.
Source:
Parameters:
Name Type Attributes Default Description
startValue number <optional>
1 Starting number for the new level.
Returns:
The current instance (for chaining).
Type
MultiLevelAutoNumbering

next(textopt) → {string}

Description:
  • Returns the next string in the current nesting level.
Source:
Parameters:
Name Type Attributes Description
text string <optional>
Optional content to append after the number (e.g., a title).
Returns:
Formatted numbered string like `1. Title` or `2.3. Another`.
Type
string

reset()

Description:
Source:

unnest() → {MultiLevelAutoNumbering}

Description:
  • Decreases the nesting level (e.g., goes from `1.1.1.` to `1.1.`). Does nothing if already at the top-level (level 1).
Source:
Returns:
The current instance (for chaining).
Type
MultiLevelAutoNumbering