Skip to content

Commit

Permalink
Fixed the default stack id
Browse files Browse the repository at this point in the history
  • Loading branch information
royteusink committed Dec 18, 2023
1 parent 29e417f commit b3830f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-pillows-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"stackid": patch
---

Fixed the default stack id
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import { createStack } from 'stackid';
// Create a stack
const stack = createStack();

const id1 = stack.pushStack(); // Pushes a new identifier (e.g., 0)
const id2 = stack.pushStack(); // Pushes another identifier (e.g., 1)
const id1 = stack.pushStack(); // Pushes a new identifier (e.g., 1)
const id2 = stack.pushStack(); // Pushes another identifier (e.g., 2)

console.log(stack.onTopStack(id2)); // true

stack.popStack(id2); // Pops the identifier from the stack

console.log(stack.getState()); // [0]
console.log(stack.getState()); // [1]
```

### Managing the stack
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function genNextId<T>(prev?: T): T {
return (typeof prev === 'number' ? prev + 1 : 0) as T;
return (typeof prev === 'number' ? prev + 1 : 1) as T;
}

export function createStack<T = number>(nextId?: (prev?: T) => T) {
Expand Down

0 comments on commit b3830f5

Please sign in to comment.