next-lib-utils 1.0.0

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/dist/index.cjs ADDED
@@ -0,0 +1,51 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ Response: () => Response,
23
+ getIdFromContext: () => getIdFromContext
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/components/response.js
28
+ var import_server = require("next/server");
29
+ var Response = {
30
+ success: (data = null, message = "", status = 200) => {
31
+ return import_server.NextResponse.json({ success: true, message, data }, { status });
32
+ },
33
+ error: (error = "Erro interno", details = null, status = 500) => {
34
+ return import_server.NextResponse.json({ success: false, error, details }, { status });
35
+ }
36
+ };
37
+
38
+ // src/components/routes.js
39
+ async function getIdFromContext(context) {
40
+ const params = await context.params;
41
+ if (!params || !params.id) throw new Error("ID n\xE3o fornecido");
42
+ const id = params.id;
43
+ const parsedId = Number(id);
44
+ if (!isNaN(parsedId)) return parsedId;
45
+ return id;
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ Response,
50
+ getIdFromContext
51
+ });
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ // src/components/response.js
2
+ import { NextResponse } from "next/server";
3
+ var Response = {
4
+ success: (data = null, message = "", status = 200) => {
5
+ return NextResponse.json({ success: true, message, data }, { status });
6
+ },
7
+ error: (error = "Erro interno", details = null, status = 500) => {
8
+ return NextResponse.json({ success: false, error, details }, { status });
9
+ }
10
+ };
11
+
12
+ // src/components/routes.js
13
+ async function getIdFromContext(context) {
14
+ const params = await context.params;
15
+ if (!params || !params.id) throw new Error("ID n\xE3o fornecido");
16
+ const id = params.id;
17
+ const parsedId = Number(id);
18
+ if (!isNaN(parsedId)) return parsedId;
19
+ return id;
20
+ }
21
+ export {
22
+ Response,
23
+ getIdFromContext
24
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "next-lib-utils",
3
+ "version": "1.0.0",
4
+ "description": "Library of reusable components for my projects.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "scripts": {
8
+ "build": "tsup src/index.js --format cjs,esm false --clean"
9
+ },
10
+ "author": "GustavoOliveira",
11
+ "license": "ISC",
12
+ "type": "module",
13
+ "peerDependencies": {
14
+ "next": "^13 || ^14 || ^15 || ^16",
15
+ "react": "^18 || ^19",
16
+ "react-dom": "^18 || ^19"
17
+ },
18
+ "devDependencies": {
19
+ "tsup": "^8.5.1",
20
+ "typescript": "^6.0.2"
21
+ }
22
+ }
@@ -0,0 +1,11 @@
1
+ import { NextResponse } from "next/server";
2
+
3
+ export const Response = {
4
+ success: (data = null, message = "", status = 200) => {
5
+ return NextResponse.json({ success: true, message, data }, { status });
6
+ },
7
+
8
+ error: (error = "Erro interno", details = null, status = 500) => {
9
+ return NextResponse.json({ success: false, error, details }, { status });
10
+ }
11
+ };
@@ -0,0 +1,12 @@
1
+ export async function getIdFromContext(context) {
2
+ const params = await context.params;
3
+
4
+ if (!params || !params.id) throw new Error("ID não fornecido");
5
+
6
+ const id = params.id;
7
+ const parsedId = Number(id);
8
+
9
+ if (!isNaN(parsedId)) return parsedId;
10
+
11
+ return id;
12
+ };
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./components/response.js";
2
+ export * from "./components/routes.js";