diff --git a/CHANGELOG.md b/CHANGELOG.md
index c81234a..7b866ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [3.1.0] - 2021-06-13
+
+### Added
+- typescript.
+
## [3.0.0] - 2021-01-02
### Changed
diff --git a/README.md b/README.md
index dd4ab47..8bed578 100644
--- a/README.md
+++ b/README.md
@@ -6,12 +6,15 @@
A wrapper around javascript array push/pop with a standard stack interface.
-# Table of Contents
+
+
+
+# Contents
* [Install](#install)
* [require](#require)
* [import](#import)
* [API](#api)
- * [Construction](#construction)
+ * [constructor](#constructor)
* [.push(element)](#pushelement)
* [.peek()](#peek)
* [.pop()](#pop)
@@ -29,21 +32,23 @@ A wrapper around javascript array push/pop with a standard stack interface.
npm install --save @datastructures-js/stack
```
-### require
+### JS
```js
const { Stack } = require('@datastructures-js/stack');
```
-### import
+### TS
```js
import { Stack } from '@datastructures-js/stack';
```
+
## API
-### Construction
+### constructor
#### using "new"
+##### JS
```js
// empty stack
const stack = new Stack();
@@ -52,8 +57,18 @@ const stack = new Stack();
const stack = new Stack([10, 3, 8, 40, 1]);
```
+##### TS
+```TS
+// empty stack
+const stack = new Stack();
+
+// from an array
+const stack = new Stack([10, 3, 8, 40, 1]);
+```
+
#### using ".fromArray"
+##### JS
```js
// empty stack
const stack = Stack.fromArray([]);
@@ -66,7 +81,12 @@ const stack = Stack.fromArray(list);
const stack = Stack.fromArray(list.slice());
```
-### .push(element)
+##### TS
+```ts
+const stack = Stack.fromArray([10, 3, 8, 40, 1]);
+```
+
+### .push(element: T)
push an element to the top of the stack.
@@ -76,14 +96,14 @@ push an element to the top of the stack.
| runtime |
- | element: any |
- Stack |
+ element: T |
+ Stack<T> |
O(1) |
```js
-stack.push('test');
+stack.push(11);
```
### .peek()
@@ -95,13 +115,13 @@ returns the top element in the stack.
runtime |
- | any |
+ T |
O(1) |
```js
-console.log(stack.peek()); // test
+console.log(stack.peek()); // 11
```
### .pop()
@@ -113,13 +133,13 @@ removes and returns the top element of the stack.
runtime |
- | any |
+ T |
O(1) |
```js
-console.log(stack.pop()); // test
+console.log(stack.pop()); // 11
console.log(stack.peek()); // null
```
@@ -138,7 +158,7 @@ checks if the stack is empty.
```js
-stack.push('test');
+stack.push(11);
console.log(stack.isEmpty()); // false
```
diff --git a/index.js b/index.js
index a362403..5bda705 100644
--- a/index.js
+++ b/index.js
@@ -1,3 +1,3 @@
-const Stack = require('./src/stack');
+const { Stack } = require('./src/stack');
exports.Stack = Stack;
diff --git a/package.json b/package.json
index f32ad9f..3d55423 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@datastructures-js/stack",
- "version": "3.0.0",
+ "version": "3.1.0",
"description": "stack implementation in javascript",
"main": "index.js",
"scripts": {
diff --git a/src/stack.d.ts b/src/stack.d.ts
new file mode 100644
index 0000000..2f47111
--- /dev/null
+++ b/src/stack.d.ts
@@ -0,0 +1,12 @@
+export class Stack {
+ constructor(elements?: T[]);
+ isEmpty(): boolean;
+ size(): number;
+ peek(): T;
+ push(element: T): Stack;
+ pop(): T;
+ toArray(): T[];
+ clear(): void;
+ clone(): Stack;
+ static fromArray(elements: T[]): Stack;
+}
diff --git a/src/stack.js b/src/stack.js
index 009abae..c5a38be 100644
--- a/src/stack.js
+++ b/src/stack.js
@@ -101,4 +101,4 @@ class Stack {
}
}
-module.exports = Stack;
+exports.Stack = Stack;
diff --git a/test/stack.test.js b/test/stack.test.js
index 418a73e..b61d512 100644
--- a/test/stack.test.js
+++ b/test/stack.test.js
@@ -1,5 +1,5 @@
const { expect } = require('chai');
-const Stack = require('../src/stack');
+const { Stack } = require('../src/stack');
describe('stack tests', () => {
const stack = new Stack();