From dcecca9eaf99c87bbe2d74f17560495ae0bcbdc5 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Fri, 11 Jun 2021 21:17:24 +0200 Subject: [PATCH 01/16] add typescript --- index.js | 2 +- src/stack.d.ts | 12 ++++++++++++ src/stack.js | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/stack.d.ts 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/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; From 6360822d7be85eaa6f6e65389ddf5ed261c78cbc Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:01:58 +0200 Subject: [PATCH 02/16] fix test --- test/stack.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 40fe2c7a8ca7fd8dd4b0e5af6b8d587a0f47b48e Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:06:15 +0200 Subject: [PATCH 03/16] update --- README.md | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index dd4ab47..ae270ac 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ 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,18 +29,19 @@ 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" @@ -52,6 +53,14 @@ const stack = new Stack(); const stack = new Stack([10, 3, 8, 40, 1]); ``` +```TS +// empty stack +const stack = new Stack(); + +// from an array +const stack = new Stack([10, 3, 8, 40, 1]); +``` + #### using ".fromArray" ```js @@ -66,7 +75,11 @@ const stack = Stack.fromArray(list); const stack = Stack.fromArray(list.slice()); ``` -### .push(element) +```ts +const stack = Stack.fromArray([10, 3, 8, 40, 1]); +``` + +### .push(element: T) push an element to the top of the stack. @@ -95,7 +108,7 @@ returns the top element in the stack. - +
runtime
anyT O(1)
@@ -113,7 +126,7 @@ removes and returns the top element of the stack. runtime - any + T O(1) From 4499c23ed5a354b429909242efbdad7b5f76b520 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:08:28 +0200 Subject: [PATCH 04/16] update --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ae270ac..684009d 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ A wrapper around javascript array push/pop with a standard stack interface. +product + + # Contents * [Install](#install) * [require](#require) From 51f5a0bf8d2d60b886b2efb4916b5b54883595ea Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:09:04 +0200 Subject: [PATCH 05/16] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 684009d..0d934d9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A wrapper around javascript array push/pop with a standard stack interface. -product +product # Contents From b672513cdf6c73041a2f21d536b4659a74d88093 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:09:37 +0200 Subject: [PATCH 06/16] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d934d9..06d1d8e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A wrapper around javascript array push/pop with a standard stack interface. -product +product # Contents From 01397d8e2576b3ed5985c766b29f79bb66aff071 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:10:10 +0200 Subject: [PATCH 07/16] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06d1d8e..0d934d9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A wrapper around javascript array push/pop with a standard stack interface. -product +product # Contents From 41a812b4f23cddf67feee352098b490fe4a3ccf3 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:11:05 +0200 Subject: [PATCH 08/16] update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0d934d9..e66f4e2 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,8 @@ push an element to the top of the stack. runtime - element: any - Stack + element: T + Stack O(1) From a2705d4a5d6349549fceba4387a23bc9de7b6dcf Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:11:59 +0200 Subject: [PATCH 09/16] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e66f4e2..81797af 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ push an element to the top of the stack. element: T - Stack + Stack<T> O(1) From 22e531b8b822edd83dc8185f1705145b13834855 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:14:49 +0200 Subject: [PATCH 10/16] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 81797af..65fea88 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A wrapper around javascript array push/pop with a standard stack interface. -product +product # Contents From d0fb82d1fccd8d01a2914ea16aef0710f2c338f6 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:26:35 +0200 Subject: [PATCH 11/16] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 65fea88..ec095b9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A wrapper around javascript array push/pop with a standard stack interface. -product + # Contents From a81ca7d2714c9512eedbd20f9721b154767eadad Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:29:03 +0200 Subject: [PATCH 12/16] update --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ec095b9..c3039d9 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ import { Stack } from '@datastructures-js/stack'; #### using "new" +##### JS ```js // empty stack const stack = new Stack(); @@ -56,6 +57,7 @@ const stack = new Stack(); const stack = new Stack([10, 3, 8, 40, 1]); ``` +##### TS ```TS // empty stack const stack = new Stack(); @@ -66,6 +68,7 @@ const stack = new Stack([10, 3, 8, 40, 1]); #### using ".fromArray" +##### JS ```js // empty stack const stack = Stack.fromArray([]); @@ -78,6 +81,7 @@ const stack = Stack.fromArray(list); const stack = Stack.fromArray(list.slice()); ``` +##### TS ```ts const stack = Stack.fromArray([10, 3, 8, 40, 1]); ``` From 1aeecdc9bf893ccfda740df84286157d6c0582e7 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 17:53:13 +0200 Subject: [PATCH 13/16] v3.1.0 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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/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": { From 95908ade093187984d621fa838cf76425cd73978 Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 18:03:24 +0200 Subject: [PATCH 14/16] update --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c3039d9..484533a 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ push an element to the top of the stack. ```js -stack.push('test'); +stack.push(11); ``` ### .peek() @@ -121,7 +121,7 @@ returns the top element in the stack. ```js -console.log(stack.peek()); // test +console.log(stack.peek()); // 11 ``` ### .pop() @@ -139,7 +139,7 @@ removes and returns the top element of the stack. ```js -console.log(stack.pop()); // test +console.log(stack.pop()); // 11 console.log(stack.peek()); // null ``` @@ -158,7 +158,7 @@ checks if the stack is empty. ```js -stack.push('test'); +stack.push(11); console.log(stack.isEmpty()); // false ``` @@ -194,6 +194,8 @@ creates a shallow copy of the stack. +##### JS + ```js const stack = Stack.fromArray([{ id: 2 }, { id: 4 } , { id: 8 }]); const clone = stack.clone(); From f8e1b937256eea220d5355d845fdc3ebb40f03fa Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 18:05:53 +0200 Subject: [PATCH 15/16] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 484533a..2d3fc8f 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ creates a shallow copy of the stack. -##### JS +##### example in JS ```js const stack = Stack.fromArray([{ id: 2 }, { id: 4 } , { id: 8 }]); From b0ea1b88ed256136f85e0282619e785b3d29018a Mon Sep 17 00:00:00 2001 From: Eyas Ranjous Date: Sun, 13 Jun 2021 18:06:21 +0200 Subject: [PATCH 16/16] update --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 2d3fc8f..8bed578 100644 --- a/README.md +++ b/README.md @@ -194,8 +194,6 @@ creates a shallow copy of the stack. -##### example in JS - ```js const stack = Stack.fromArray([{ id: 2 }, { id: 4 } , { id: 8 }]); const clone = stack.clone();