stack-typed 1.19.3

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.
@@ -0,0 +1 @@
1
+ export * from './stack';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./stack"), exports);
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license MIT
3
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
4
+ * @class
5
+ */
6
+ export declare class Stack<T = number> {
7
+ protected _elements: T[];
8
+ /**
9
+ * The constructor initializes an array of elements, which can be provided as an optional parameter.
10
+ * @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
11
+ * of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
12
+ * is provided and is an array, it is assigned to the `_elements
13
+ */
14
+ constructor(elements?: T[]);
15
+ /**
16
+ * The function "fromArray" creates a new Stack object from an array of elements.
17
+ * @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
18
+ * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
19
+ * array.
20
+ */
21
+ static fromArray<T>(elements: T[]): Stack<T>;
22
+ /**
23
+ * The function checks if an array is empty and returns a boolean value.
24
+ * @returns A boolean value indicating whether the `_elements` array is empty or not.
25
+ */
26
+ isEmpty(): boolean;
27
+ /**
28
+ * The size() function returns the number of elements in an array.
29
+ * @returns The size of the elements array.
30
+ */
31
+ size(): number;
32
+ /**
33
+ * The `peek` function returns the last element of an array, or null if the array is empty.
34
+ * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
35
+ */
36
+ peek(): T | null;
37
+ /**
38
+ * The push function adds an element to the stack and returns the updated stack.
39
+ * @param {T} element - The parameter "element" is of type T, which means it can be any data type.
40
+ * @returns The `push` method is returning the updated `Stack<T>` object.
41
+ */
42
+ push(element: T): Stack<T>;
43
+ /**
44
+ * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
45
+ * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
46
+ * array is empty, it returns `null`.
47
+ */
48
+ pop(): T | null;
49
+ /**
50
+ * The toArray function returns a copy of the elements in an array.
51
+ * @returns An array of type T.
52
+ */
53
+ toArray(): T[];
54
+ /**
55
+ * The clear function clears the elements array.
56
+ */
57
+ clear(): void;
58
+ /**
59
+ * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
60
+ * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
61
+ */
62
+ clone(): Stack<T>;
63
+ }
package/dist/stack.js ADDED
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stack = void 0;
4
+ /**
5
+ * @license MIT
6
+ * @copyright Tyler Zeng <zrwusa@gmail.com>
7
+ * @class
8
+ */
9
+ var Stack = /** @class */ (function () {
10
+ /**
11
+ * The constructor initializes an array of elements, which can be provided as an optional parameter.
12
+ * @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
13
+ * of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
14
+ * is provided and is an array, it is assigned to the `_elements
15
+ */
16
+ function Stack(elements) {
17
+ this._elements = Array.isArray(elements) ? elements : [];
18
+ }
19
+ /**
20
+ * The function "fromArray" creates a new Stack object from an array of elements.
21
+ * @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
22
+ * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
23
+ * array.
24
+ */
25
+ Stack.fromArray = function (elements) {
26
+ return new Stack(elements);
27
+ };
28
+ /**
29
+ * The function checks if an array is empty and returns a boolean value.
30
+ * @returns A boolean value indicating whether the `_elements` array is empty or not.
31
+ */
32
+ Stack.prototype.isEmpty = function () {
33
+ return this._elements.length === 0;
34
+ };
35
+ /**
36
+ * The size() function returns the number of elements in an array.
37
+ * @returns The size of the elements array.
38
+ */
39
+ Stack.prototype.size = function () {
40
+ return this._elements.length;
41
+ };
42
+ /**
43
+ * The `peek` function returns the last element of an array, or null if the array is empty.
44
+ * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
45
+ */
46
+ Stack.prototype.peek = function () {
47
+ if (this.isEmpty())
48
+ return null;
49
+ return this._elements[this._elements.length - 1];
50
+ };
51
+ /**
52
+ * The push function adds an element to the stack and returns the updated stack.
53
+ * @param {T} element - The parameter "element" is of type T, which means it can be any data type.
54
+ * @returns The `push` method is returning the updated `Stack<T>` object.
55
+ */
56
+ Stack.prototype.push = function (element) {
57
+ this._elements.push(element);
58
+ return this;
59
+ };
60
+ /**
61
+ * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
62
+ * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
63
+ * array is empty, it returns `null`.
64
+ */
65
+ Stack.prototype.pop = function () {
66
+ if (this.isEmpty())
67
+ return null;
68
+ return this._elements.pop() || null;
69
+ };
70
+ /**
71
+ * The toArray function returns a copy of the elements in an array.
72
+ * @returns An array of type T.
73
+ */
74
+ Stack.prototype.toArray = function () {
75
+ return this._elements.slice();
76
+ };
77
+ /**
78
+ * The clear function clears the elements array.
79
+ */
80
+ Stack.prototype.clear = function () {
81
+ this._elements = [];
82
+ };
83
+ /**
84
+ * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
85
+ * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
86
+ */
87
+ Stack.prototype.clone = function () {
88
+ return new Stack(this._elements.slice());
89
+ };
90
+ return Stack;
91
+ }());
92
+ exports.Stack = Stack;
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ testMatch: ['<rootDir>/tests/**/*.test.ts'],
5
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "stack-typed",
3
+ "version": "1.19.3",
4
+ "description": "Stack. Javascript & Typescript Data Structure.",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "build": "rm -rf dist && npx tsc",
8
+ "test": "jest",
9
+ "build:docs": "typedoc --out docs ./src",
10
+ "deps:check": "dependency-cruiser src",
11
+ "build:publish": "npm run build && npm run build:docs && npm publish"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/zrwusa/data-structure-typed"
16
+ },
17
+ "keywords": [
18
+ "Data structure",
19
+ "Stack",
20
+ "Last In, First Out (LIFO)",
21
+ "Push",
22
+ "Pop",
23
+ "Peek",
24
+ "Insertion",
25
+ "Deletion",
26
+ "Top",
27
+ "Element",
28
+ "Dynamic resizing",
29
+ "Memory management",
30
+ "Stack operations",
31
+ "Stack implementation",
32
+ "Stack frame",
33
+ "Function calls",
34
+ "Expression evaluation",
35
+ "Balancing symbols",
36
+ "Undo functionality",
37
+ "History tracking",
38
+ "Memory allocation",
39
+ "Data management",
40
+ "Sequential access"
41
+ ],
42
+ "author": "Tyler Zeng zrwusa@gmail.com",
43
+ "license": "MIT",
44
+ "bugs": {
45
+ "url": "https://github.com/zrwusa/data-structure-typed/issues"
46
+ },
47
+ "homepage": "https://github.com/zrwusa/data-structure-typed#readme",
48
+ "types": "dist/index.d.ts",
49
+ "devDependencies": {
50
+ "@types/jest": "^29.5.3",
51
+ "@types/node": "^20.4.9",
52
+ "dependency-cruiser": "^13.1.2",
53
+ "jest": "^29.6.2",
54
+ "ts-jest": "^29.1.1",
55
+ "typedoc": "^0.24.8",
56
+ "typescript": "^4.9.5"
57
+ },
58
+ "dependencies": {
59
+ "data-structure-typed": "^1.19.3",
60
+ "zod": "^3.22.2"
61
+ }
62
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "outDir": "./dist",
5
+ "module": "commonjs",
6
+ "target": "es5",
7
+ "lib": [
8
+ "esnext",
9
+ ],
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "moduleResolution": "node",
13
+ "declarationDir": "./dist",
14
+ "skipLibCheck": true,
15
+ "downlevelIteration": true,
16
+ "experimentalDecorators": true,
17
+ // "allowJs": true,
18
+ // "allowSyntheticDefaultImports": true,
19
+ // "forceConsistentCasingInFileNames": true,
20
+ // "noFallthroughCasesInSwitch": true,
21
+ // "resolveJsonModule": true,
22
+ // "isolatedModules": true,
23
+ // "noEmit": true,
24
+ "typeRoots": [
25
+ "node_modules/@types"
26
+ ]
27
+ },
28
+
29
+ "include": [
30
+ "src",
31
+ ],
32
+ "exclude": [
33
+ // "node_modules/data-structure-typed",
34
+ "node_modules",
35
+ "dist"
36
+ ]
37
+ }