jc-structure 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) 2025 hzqhxy
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.
@@ -0,0 +1,35 @@
1
+ class e {
2
+ items = {};
3
+ count = 0;
4
+ constructor() {
5
+ }
6
+ pop() {
7
+ if (this.isEmpty()) return;
8
+ this.count--;
9
+ const t = this.items[this.count];
10
+ return delete this.items[this.count], t;
11
+ }
12
+ push(...t) {
13
+ t.forEach((s) => {
14
+ this.items[this.count] = s, this.count++;
15
+ });
16
+ }
17
+ peek() {
18
+ return this.isEmpty() ? void 0 : this.items[this.count - 1];
19
+ }
20
+ isEmpty() {
21
+ return this.count === 0;
22
+ }
23
+ size() {
24
+ return this.count;
25
+ }
26
+ clear() {
27
+ this.items = {}, this.count = 0;
28
+ }
29
+ toString() {
30
+ return this.isEmpty() ? "" : `Stack(count: ${this.count}):[${this.items[this.count - 1]},...rest]`;
31
+ }
32
+ }
33
+ export {
34
+ e as Stack
35
+ };
@@ -0,0 +1 @@
1
+ (function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t["jc-structure"]={}))})(this,(function(t){"use strict";class i{items={};count=0;constructor(){}pop(){if(this.isEmpty())return;this.count--;const e=this.items[this.count];return delete this.items[this.count],e}push(...e){e.forEach(s=>{this.items[this.count]=s,this.count++})}peek(){return this.isEmpty()?void 0:this.items[this.count-1]}isEmpty(){return this.count===0}size(){return this.count}clear(){this.items={},this.count=0}toString(){return this.isEmpty()?"":`Stack(count: ${this.count}):[${this.items[this.count-1]},...rest]`}}t.Stack=i,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
package/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ interface Structure {
2
+ /**
3
+ * 判断数据结构是否为空
4
+ */
5
+ isEmpty(): boolean;
6
+ /**
7
+ * 数据结构元素长度
8
+ */
9
+ size(): number;
10
+ /**
11
+ * 清除数据结构元素
12
+ */
13
+ clear(): void;
14
+ /**
15
+ * 数据结构字符串表示
16
+ */
17
+ toString(): string;
18
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "jc-structure",
3
+ "private": false,
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "index.d.ts",
9
+ "types",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "description": "create data structure set using ts.",
14
+ "keywords": [
15
+ "data",
16
+ "structure",
17
+ "set",
18
+ "typescript"
19
+ ],
20
+ "author": "chuz1 <jckjsjz@163.com>",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://gitee.com/hzqhxy/jc-structure"
25
+ },
26
+ "exports": {
27
+ "types": "./index.d.ts",
28
+ "import": "./dist/jc-structure.js",
29
+ "require": "./dist/jc-structure.cjs"
30
+ },
31
+ "scripts": {
32
+ "dev": "vite",
33
+ "build": "tsc && vite build"
34
+ },
35
+ "devDependencies": {
36
+ "typescript": "~5.9.2",
37
+ "vite": "^7.1.5"
38
+ }
39
+ }
@@ -0,0 +1,21 @@
1
+ interface StackObj<T> {
2
+ [key: number]: T;
3
+ }
4
+
5
+ interface IStack<T> extends Structure {
6
+ /**
7
+ * 移除栈顶元素并返回该元素
8
+ */
9
+ pop(): T | undefined;
10
+
11
+ /**
12
+ * #### 向栈顶添加元素
13
+ * @param item 要添加的元素
14
+ */
15
+ push(...args: Array<T>): void;
16
+
17
+ /**
18
+ * #### 返回栈顶元素,但不移除
19
+ */
20
+ peek(): T | undefined;
21
+ }