typescript-ds-lib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Artiom Baloian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # TypeScript Data Structure Library
2
+ Native TypeScript data structure implementations without external dependencies.
3
+
4
+
5
+ ## Contributions
6
+ Contributions are welcome and can be made by submitting GitHub pull requests
7
+ to this repository. In general, the source code follows
8
+ [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) and the
9
+ rules specified in `.eslintrc.json` file.
10
+
11
+
12
+ ## License
13
+ This source code is available to everyone under the standard
14
+ [MIT LICENSE](https://github.com/baloian/marcal/blob/master/LICENSE).
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { Config } from '@jest/types';
2
+ declare const config: Config.InitialOptions;
3
+ export default config;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config = {
4
+ verbose: true,
5
+ transform: {
6
+ '^.+\\.(ts|tsx)$': 'ts-jest'
7
+ },
8
+ testPathIgnorePatterns: ['/node_modules/', '/dist/']
9
+ };
10
+ exports.default = config;
11
+ //# sourceMappingURL=jest.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":";;AAEA,MAAM,MAAM,GAA0B;IACpC,OAAO,EAAE,IAAI;IACb,SAAS,EAAE;QACT,iBAAiB,EAAE,SAAS;KAC7B;IACD,sBAAsB,EAAE,CAAC,gBAAgB,EAAE,QAAQ,CAAC;CACrD,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,28 @@
1
+ export declare class Stack<T> {
2
+ private items;
3
+ constructor();
4
+ /**
5
+ * Adds an element to the top of the stack.
6
+ */
7
+ push(element: T): void;
8
+ /**
9
+ * Removes and returns the top element from the stack, or undefined if stack is empty.
10
+ */
11
+ pop(): T | undefined;
12
+ /**
13
+ * Returns the top element of the stack without removing it, or undefined if stack is empty.
14
+ */
15
+ top(): T | undefined;
16
+ /**
17
+ * Checks if the stack is empty. Returns true if the stack is empty, false otherwise.
18
+ */
19
+ empty(): boolean;
20
+ /**
21
+ * Returns the number of elements in the stack. The size of the stack
22
+ */
23
+ size(): number;
24
+ /**
25
+ * Removes all elements from the stack.
26
+ */
27
+ clear(): void;
28
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stack = void 0;
4
+ class Stack {
5
+ items;
6
+ constructor() {
7
+ this.items = [];
8
+ }
9
+ /**
10
+ * Adds an element to the top of the stack.
11
+ */
12
+ push(element) {
13
+ this.items.push(element);
14
+ }
15
+ /**
16
+ * Removes and returns the top element from the stack, or undefined if stack is empty.
17
+ */
18
+ pop() {
19
+ return this.items.pop();
20
+ }
21
+ /**
22
+ * Returns the top element of the stack without removing it, or undefined if stack is empty.
23
+ */
24
+ top() {
25
+ return this.items[this.items.length - 1];
26
+ }
27
+ /**
28
+ * Checks if the stack is empty. Returns true if the stack is empty, false otherwise.
29
+ */
30
+ empty() {
31
+ return this.items.length === 0;
32
+ }
33
+ /**
34
+ * Returns the number of elements in the stack. The size of the stack
35
+ */
36
+ size() {
37
+ return this.items.length;
38
+ }
39
+ /**
40
+ * Removes all elements from the stack.
41
+ */
42
+ clear() {
43
+ this.items = [];
44
+ }
45
+ }
46
+ exports.Stack = Stack;
47
+ //# sourceMappingURL=stack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stack.js","sourceRoot":"","sources":["../../lib/stack.ts"],"names":[],"mappings":";;;AAAA,MAAa,KAAK;IACR,KAAK,CAAM;IAEnB;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAAU;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,GAAG;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;CACF;AAhDD,sBAgDC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const stack_1 = require("../lib/stack");
4
+ describe('Stack', () => {
5
+ let stack;
6
+ beforeEach(() => {
7
+ stack = new stack_1.Stack();
8
+ });
9
+ test('should create empty stack', () => {
10
+ expect(stack.empty()).toBe(true);
11
+ expect(stack.size()).toBe(0);
12
+ });
13
+ test('should push elements to stack', () => {
14
+ stack.push(1);
15
+ stack.push(2);
16
+ expect(stack.size()).toBe(2);
17
+ expect(stack.top()).toBe(2);
18
+ });
19
+ test('should pop elements from stack', () => {
20
+ stack.push(1);
21
+ stack.push(2);
22
+ expect(stack.pop()).toBe(2);
23
+ expect(stack.size()).toBe(1);
24
+ expect(stack.pop()).toBe(1);
25
+ expect(stack.empty()).toBe(true);
26
+ });
27
+ test('should return undefined when popping empty stack', () => {
28
+ expect(stack.pop()).toBeUndefined();
29
+ });
30
+ test('should return top element without removing it', () => {
31
+ stack.push(1);
32
+ stack.push(2);
33
+ expect(stack.top()).toBe(2);
34
+ expect(stack.size()).toBe(2);
35
+ });
36
+ test('should return undefined when checking top of empty stack', () => {
37
+ expect(stack.top()).toBeUndefined();
38
+ });
39
+ test('should clear all elements from stack', () => {
40
+ stack.push(1);
41
+ stack.push(2);
42
+ stack.push(3);
43
+ stack.clear();
44
+ expect(stack.empty()).toBe(true);
45
+ expect(stack.size()).toBe(0);
46
+ });
47
+ test('should correctly report size', () => {
48
+ expect(stack.size()).toBe(0);
49
+ stack.push(1);
50
+ expect(stack.size()).toBe(1);
51
+ stack.push(2);
52
+ expect(stack.size()).toBe(2);
53
+ stack.pop();
54
+ expect(stack.size()).toB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AAE;QACxC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7B,KAAK,CAAC,GAAG,EAAE,CAAC;QACZ,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "typescript-ds-lib",
3
+ "version": "0.0.1",
4
+ "description": "A collection of TypeScript data structure implementations",
5
+ "author": "Artiom Baloian <artiom.baloian@gmail.com>",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "rm -rf dist && tsc",
14
+ "prepare": "npm run build",
15
+ "test": "rm -rf dist && tsc && jest"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/baloian/typescript-ds.git"
20
+ },
21
+ "dependencies": {
22
+ "ts-node": "^10.9.2"
23
+ },
24
+ "devDependencies": {
25
+ "@types/jest": "^29.5.14",
26
+ "@types/node": "^22.10.1",
27
+ "ts-jest": "^29.2.5",
28
+ "typescript": "^5.7.2"
29
+ }
30
+ }