Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-routes-readme

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-routes-readme - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

133

lib/index.js
#!/usr/bin/env node
"use strict";
/* eslint-disable @typescript-eslint/no-explicit-any */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -9,2 +33,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const path_1 = __importDefault(require("path"));
const parser = __importStar(require("@babel/parser"));
const traverse_1 = __importDefault(require("@babel/traverse"));
const t = __importStar(require("@babel/types"));
function parseRouteHandlers(routeFile) {

@@ -15,51 +42,65 @@ const content = fs_1.default.readFileSync(routeFile, 'utf-8');

let currentHandler = null;
const lines = content.split('\n');
for (const line of lines) {
const trimmedLine = line.trim();
const currentLineNumber = lines.indexOf(line) + 1;
if (trimmedLine.startsWith('import {')) {
dependencies.push(trimmedLine);
}
const match = /export async function (\w+)\(([\w: ,]*)\)/.exec(trimmedLine);
if (match) {
currentHandler = {
implementation: match[0],
name: match[1],
method: 'GET',
doc: { variables: [], conditionals: [], errors: [], comments: [] },
dependencies,
};
}
if (currentHandler && trimmedLine.includes('=')) {
currentHandler.doc.variables.push({ value: trimmedLine, line: currentLineNumber });
}
if (currentHandler && (trimmedLine.includes('if') || trimmedLine.includes('?'))) {
currentHandler.doc.conditionals.push({ value: trimmedLine, line: currentLineNumber });
}
if (currentHandler &&
(trimmedLine.includes('throw') ||
trimmedLine.includes('new Error') ||
trimmedLine.includes('Promise.reject'))) {
currentHandler.doc.errors.push({ value: trimmedLine, line: currentLineNumber });
}
if (currentHandler && trimmedLine.startsWith('//')) {
currentHandler.doc.comments.push({ value: trimmedLine, line: currentLineNumber });
}
if (currentHandler && trimmedLine.startsWith('/*') && trimmedLine.endsWith('*/')) {
currentHandler.doc.comments.push({ value: trimmedLine, line: currentLineNumber });
}
if (currentHandler && trimmedLine.startsWith('/*') && !trimmedLine.endsWith('*/')) {
const commentInLines = { value: trimmedLine, line: currentLineNumber };
for (let i = currentLineNumber; i < lines.length; i++) {
const nextLine = lines[i].trim();
commentInLines.value += '\n' + nextLine;
if (nextLine.endsWith('*/')) {
break;
const ast = parser.parse(content, {
sourceType: 'module',
plugins: ['jsx', 'typescript'],
});
(0, traverse_1.default)(ast, {
enter(path) {
var _a;
if (t.isImportDeclaration(path.node)) {
dependencies.push(path.toString());
}
else if (t.isFunctionDeclaration(path.node) && path.node.async) {
const { name } = path.node.id;
const params = path.node.params
.map(param => content.substring(param.start, param.end))
.join(', ');
const returnType = path.node.returnType
? content.substring(path.node.returnType.start, path.node.returnType.end)
: '';
currentHandler = {
implementation: `async function ${name}(${params})${returnType}`,
name,
method: 'GET',
doc: {
variables: [],
conditionals: [],
errors: [],
comments: [],
},
dependencies,
};
if (path.node.leadingComments) {
path.node.leadingComments.forEach(comment => {
const value = content.substring(comment.start, comment.end);
currentHandler.doc.comments.push({ value, line: comment.loc.start.line });
});
}
}
currentHandler.doc.comments.push(commentInLines);
}
}
else if (currentHandler) {
const currentLineNumber = ((_a = path.node.loc) === null || _a === void 0 ? void 0 : _a.start.line) || 0;
if (t.isVariableDeclaration(path.node)) {
const value = content.substring(path.node.start, path.node.end);
currentHandler.doc.variables.push({ value, line: currentLineNumber });
}
else if (t.isIfStatement(path.node) || t.isConditionalExpression(path.node)) {
const value = content.substring(path.node.start, path.node.end);
currentHandler.doc.conditionals.push({ value, line: currentLineNumber });
}
else if (t.isThrowStatement(path.node) ||
t.isNewExpression(path.node) ||
t.isCallExpression(path.node)) {
const value = content.substring(path.node.start, path.node.end);
currentHandler.doc.errors.push({ value, line: currentLineNumber });
}
else if (path.node.leadingComments) {
path.node.leadingComments.forEach(comment => {
const value = content.substring(comment.start, comment.end);
currentHandler.doc.comments.push({ value, line: comment.loc.start.line });
});
}
}
},
});
if (currentHandler) {
currentHandler.dependencies = dependencies;
handlers.push(currentHandler);

@@ -66,0 +107,0 @@ }

{
"name": "next-routes-readme",
"version": "0.0.3",
"version": "0.0.4",
"description": "Creates README badges from istanbul coverage report",
"type": "commonjs",
"scripts": {

@@ -60,3 +61,8 @@ "build": "rm -rf lib/ && tsc",

"typescript": "^5.2.2"
},
"dependencies": {
"@babel/parser": "^7.23.0",
"@babel/traverse": "^7.23.0",
"@babel/types": "^7.23.0"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc