@lsby/ts-jwt 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.
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ JWT\u7BA1\u7406\u5668: () => JWT\u7BA1\u7406\u5668
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
37
+ var JWT\u7BA1\u7406\u5668 = class {
38
+ constructor(secret, expiresIn) {
39
+ this.secret = secret;
40
+ this.expiresIn = expiresIn;
41
+ }
42
+ \u7B7E\u540D(\u8D1F\u8F7D) {
43
+ var token = import_jsonwebtoken.default.sign(\u8D1F\u8F7D, this.secret, {
44
+ expiresIn: this.expiresIn
45
+ });
46
+ return token;
47
+ }
48
+ \u89E3\u6790(token) {
49
+ if (token === void 0) {
50
+ return void 0;
51
+ }
52
+ token = token.replace("Bearer ", "");
53
+ try {
54
+ return import_jsonwebtoken.default.verify(token, this.secret);
55
+ } catch {
56
+ return void 0;
57
+ }
58
+ }
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ JWT\u7BA1\u7406\u5668
63
+ });
@@ -0,0 +1,9 @@
1
+ declare class JWT管理器<JWT负载 extends string | object | Buffer> {
2
+ private secret;
3
+ private expiresIn;
4
+ constructor(secret: string, expiresIn: string);
5
+ 签名(负载: JWT负载): string;
6
+ 解析(token: string | undefined): JWT负载 | undefined;
7
+ }
8
+
9
+ export { JWT管理器 };
@@ -0,0 +1,9 @@
1
+ declare class JWT管理器<JWT负载 extends string | object | Buffer> {
2
+ private secret;
3
+ private expiresIn;
4
+ constructor(secret: string, expiresIn: string);
5
+ 签名(负载: JWT负载): string;
6
+ 解析(token: string | undefined): JWT负载 | undefined;
7
+ }
8
+
9
+ export { JWT管理器 };
@@ -0,0 +1,28 @@
1
+ // src/index.ts
2
+ import jwt from "jsonwebtoken";
3
+ var JWT\u7BA1\u7406\u5668 = class {
4
+ constructor(secret, expiresIn) {
5
+ this.secret = secret;
6
+ this.expiresIn = expiresIn;
7
+ }
8
+ \u7B7E\u540D(\u8D1F\u8F7D) {
9
+ var token = jwt.sign(\u8D1F\u8F7D, this.secret, {
10
+ expiresIn: this.expiresIn
11
+ });
12
+ return token;
13
+ }
14
+ \u89E3\u6790(token) {
15
+ if (token === void 0) {
16
+ return void 0;
17
+ }
18
+ token = token.replace("Bearer ", "");
19
+ try {
20
+ return jwt.verify(token, this.secret);
21
+ } catch {
22
+ return void 0;
23
+ }
24
+ }
25
+ };
26
+ export {
27
+ JWT\u7BA1\u7406\u5668
28
+ };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@lsby/ts-jwt",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "exports": {
6
+ "require": "./dist/cjs/index.cjs",
7
+ "import": "./dist/esm/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build:all": "npm run build:cjs && npm run build:esm",
14
+ "build:cjs": "tsup src/**/*.ts --format cjs --clean --dts -d dist/cjs",
15
+ "build:esm": "tsup src/**/*.ts --format esm --clean --dts -d dist/esm",
16
+ "check:all": "npm run check:format && npm run check:lint && npm run check:type",
17
+ "check:format": "prettier --write .",
18
+ "check:lint": "eslint . --fix",
19
+ "check:type": "tsc --noEmit",
20
+ "check:type:watch": "tsc --noEmit -w",
21
+ "pub:public": "npm run check:all && npm run test:base && npm run build:all && bumpp && npm publish --access public",
22
+ "test:base": "npm run check:all && vitest run",
23
+ "test:coverage": "npm run check:all && vitest run --coverage && open-cli ./coverage/index.html"
24
+ },
25
+ "dependencies": {
26
+ "jsonwebtoken": "^9.0.2",
27
+ "vitest": "^2.0.2",
28
+ "zod": "^3.23.8"
29
+ },
30
+ "devDependencies": {
31
+ "@ianvs/prettier-plugin-sort-imports": "^4.2.1",
32
+ "@lsby/eslint-config": "^0.0.2",
33
+ "@types/jsonwebtoken": "^9.0.6",
34
+ "@types/node": "^20.12.10",
35
+ "@vitest/coverage-v8": "^2.0.2",
36
+ "bumpp": "^9.4.1",
37
+ "open-cli": "^8.0.0",
38
+ "prettier": "3.2.5",
39
+ "prettier-plugin-packagejson": "^2.5.0",
40
+ "tsup": "^8.0.2",
41
+ "tsx": "^4.9.3",
42
+ "typescript": "^5.4.5"
43
+ }
44
+ }