User: Create a TS code for stack data structure
Assistant: class Stack {  
private items: any\[\];  
  
constructor() {  
this.items = \[\];  
}  
  
push(item: any): void {  
this.items.push(item);  
}  
  
pop(): any {  
if (this.isEmpty()) {  
return null;  
}  
return this.items.pop();  
}  
  
peek(): any {  
if (this.isEmpty()) {  
return null;  
}  
return this.items\[this.items.length - 1\];  
}  
  
isEmpty(): boolean {  
return this.items.length === 0;  
}  
  
size(): number {  
return this.items.length;  
}  
  
clear(): void {  
this.items = \[\];  
}  
}  
  
// Usage example  
const stack = new Stack();  
  
stack.push(1);  
stack.push(2);  
stack.push(3);  
  
console.log(stack.peek()); // Outputs: 3  
  
console.log(stack.pop()); // Outputs: 3  
  
console.log(stack.size()); // Outputs: 2  
  
stack.clear();  
  
console.log(stack.isEmpty()); // Outputs: true
User: Could you rename the class to `StackDs`
Assistant: class StackDs {  
private items: any\[\];  
  
constructor() {  
this.items = \[\];  
}  
  
push(item: any): void {  
this.items.push(item);  
}  
  
pop(): any {  
if (this.isEmpty()) {  
return null;  
}  
return this.items.pop();  
}  
  
peek(): any {  
if (this.isEmpty()) {  
return null;  
}  
return this.items\[this.items.length - 1\];  
}  
  
isEmpty(): boolean {  
return this.items.length === 0;  
}  
  
size(): number {  
return this.items.length;  
}  
  
clear(): void {  
this.items = \[\];  
}  
}  
  
// Usage example  
const stack = new StackDs();  
  
stack.push(1);  
stack.push(2);  
stack.push(3);  
  
console.log(stack.peek()); // Outputs: 3  
  
console.log(stack.pop()); // Outputs: 3  
  
console.log(stack.size()); // Outputs: 2  
  
stack.clear();  
  
console.log(stack.isEmpty()); // Outputs: true
User: very good
Assistant: Thank you! If you have any more questions or need further assistance, feel free to ask.
User: Could you write some tests
Assistant: <p>// Test cases for StackDs class  </p>
<p>const stack = new StackDs();  </p>
<p>// Test case 1: Pushing elements into the stack<br>stack.push(1);<br>stack.push(2);<br>stack.push(3);  </p>
<p>console.log(stack.peek()); // Expected output: 3  </p>
<p>// Test case 2: Popping an element from the stack<br>console.log(stack.pop()); // Expected output: 3  </p>
<p>// Test case 3: Checking the size of the stack<br>console.log(stack.size()); // Expected output: 2  </p>
<p>// Test case 4: Clearing the stack<br>stack.clear();<br>console.log(stack.isEmpty()); // Expected output: true</p>

User: I meant to create a test case for my function using jest
Assistant: <p>// Import the StackDs class<br>const StackDs = require(‘./StackDs’);  </p>
<p>// Test case for StackDs class<br>describe(‘StackDs’, () =&gt; {<br>test(‘Pushing and popping elements from stack’, () =&gt; {<br>const stack = new StackDs();<br>stack.push(1);<br>stack.push(2);<br>stack.push(3);  </p>
<p>expect(stack.peek()).toBe(3); // Expected output: 3  </p>
<p>expect(stack.pop()).toBe(3); // Expected output: 3  </p>
<p>expect(stack.size()).toBe(2); // Expected output: 2  </p>
<p>stack.clear();<br>expect(stack.isEmpty()).toBe(true); // Expected output: true<br>});<br>});</p>

User: use esm instead of commonjs
Assistant: