# base/identifier (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/base/identifier/

Identifier generator.

## Identifier extends Object

Identifier generator.

Example: Hand out numbers in order

```js
import { Identifier } from "./build/vanilla.js";

const identifier = new Identifier(1000, 1);
const firstId = identifier.auto();
const secondId = identifier.auto();
const jumpedId = identifier.auto(10);
console.log(firstId, secondId, jumpedId);

identifier.reset();
const restartedId = identifier.auto();
console.log(restartedId);
```

- `constructor(initialSerialNumber = 0, initialIncreaseNumber = 1)` (constructor, since 0.0.8): Constructor.
  - `initialSerialNumber` number: Initial value. (default 0, the first auto() returns this value plus the increment)
  - `initialIncreaseNumber` number: Default increment added per auto(). (default 1)
- `reset()` (method, since 0.0.8): Resets to the initial state. (Counts again from the first value)
- `auto(increaseNumber = 0)` (method, since 0.0.8): Returns an identifier incremented by (1 or custom) on each call.
  - `increaseNumber` number: Increment for this call only. (the default increment if 0 or omitted)
  - returns number: The identifier after adding.

## Enum extends Object

Enum identifier generator.

Example: Make a state enumeration

```js
import { Enum } from "./build/vanilla.js";

const GameState = {
	ready: Enum.begin(),
	playing: Enum.auto(),
	gameOver: Enum.auto()
};
Enum.readonly(GameState);
console.log(GameState.ready, GameState.gameOver, Object.isFrozen(GameState));
```

- `static begin()` (static, since 0.0.8): Starts from the start value.
  - returns number: The first value after counting again from the start. (always 1)
- `static auto()` (static, since 0.0.8): Increments the value and returns it.
  - returns number: The value increased by one.
- `static readonly(dictionary)` (static, since 0.0.9): Creates a frozen enum.
  - `dictionary` object: Enumeration object to freeze. (Object.freeze in place)
  - returns object: The frozen dictionary itself. (returns the given object as is, like Object.freeze)
