diff --git a/.changeset/lazy-pillows-leave.md b/.changeset/lazy-pillows-leave.md new file mode 100644 index 0000000..210c369 --- /dev/null +++ b/.changeset/lazy-pillows-leave.md @@ -0,0 +1,5 @@ +--- +"stackid": patch +--- + +Fixed the default stack id diff --git a/README.md b/README.md index d4f67f2..72d6206 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/index.ts b/src/index.ts index 63be3d0..4571db7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ function genNextId(prev?: T): T { - return (typeof prev === 'number' ? prev + 1 : 0) as T; + return (typeof prev === 'number' ? prev + 1 : 1) as T; } export function createStack(nextId?: (prev?: T) => T) {