Socket
Socket
Sign inDemoInstall

api-doc-validator

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-doc-validator - npm Package Compare versions

Comparing version 2.24.0 to 2.25.0

11

index.d.ts

@@ -7,6 +7,13 @@ export function filesToEndpoints(files: Strings, options: Partial<CliConfig>): Promise<Endpoint[]>;

export type parseComments = {
createHandle: () => ParseCommentsHandle,
(file: string): Promise<ParsedComment[]>,
CLEAN_MODE: 1,
INNER_MODE: 2,
OUTER_MODE: 3,
createHandle: (params?: ParseCommentsParams) => ParseCommentsHandle,
(file: string, params?: ParseCommentsParams): Promise<ParsedComment[]>,
};
export type ParseCommentsParams = {
mode?: 1 | 2 | 3,
};
export type ParseCommentsHandle = {

@@ -13,0 +20,0 @@ comments: ParsedComment[],

173

lib/parseComments.js

@@ -17,5 +17,9 @@ const fs = require('fs');

module.exports = function parseComments(file) {
const CLEAN_MODE = 1;
const INNER_MODE = 2;
const OUTER_MODE = 3;
module.exports = function parseComments(file, params) {
const stream = fs.createReadStream(file);
const handle = createHandle();
const handle = createHandle(params);

@@ -37,3 +41,7 @@ stream.on('data', function (chunk) {

function createHandle() {
module.exports.CLEAN_MODE = CLEAN_MODE;
module.exports.INNER_MODE = INNER_MODE;
module.exports.OUTER_MODE = OUTER_MODE;
function createHandle({mode = CLEAN_MODE} = {}) {
let state = TEXT;

@@ -93,4 +101,9 @@ let comment = '';

if (mode === OUTER_MODE) {
comment = '/';
}
state = COMMENT_WAIT_1;
text = slice(text, start + 1);
break;

@@ -128,4 +141,3 @@

const item = list.at(-1);
item.array = toArray(array_text + text.slice(0, arr_end + 1), {line, column});
list.at(-1).array = toArray(array_text + text.slice(0, arr_end + 1), {line, column});
text = slice(text, arr_end + 1);

@@ -138,23 +150,33 @@ state = TEXT;

case COMMENT_WAIT_1:
if (text.charAt(0) === '*') {
state = COMMENT_WAIT_2;
text = slice(text, 1);
}
else {
if (text.charAt(0) !== '*') {
state = TEXT;
break;
}
if (mode === OUTER_MODE) {
comment += '*';
}
state = COMMENT_WAIT_2;
text = slice(text, 1);
break;
case COMMENT_WAIT_2:
if (text.charAt(0) === '*') {
state = COMMENT_TEXT;
text = slice(text, 1);
loc = {
line,
column: column - 3,
};
}
else {
if (text.charAt(0) !== '*') {
state = TEXT;
break;
}
if (mode === OUTER_MODE) {
comment += '*';
}
state = COMMENT_TEXT;
text = slice(text, 1);
loc = {
line,
column: column - 3,
};
break;

@@ -173,3 +195,3 @@

if (nl > -1 && (end === -1 || end > nl)) {
comment += text.slice(0, nl + 1);
comment += text.slice(0, nl + (mode === CLEAN_MODE ? 1 : 0));
text = slice(text, nl);

@@ -189,2 +211,6 @@ }

if (spaces) {
if (mode > CLEAN_MODE) {
comment += spaces[0];
}
text = slice(text, spaces[0].length);

@@ -194,67 +220,76 @@ break;

if (text.charAt(0) === '*') {
if (text.charAt(1) === '/') {
text = slice(text, 2);
if (text.charAt(0) !== '*') {
state = TEXT;
comment = '';
loc = null;
break;
}
const item = {
value: comment,
start: loc,
end: {
line,
column,
}
};
if (text.charAt(1) !== '/') {
if (mode > CLEAN_MODE) {
comment += '*';
}
state = TEXT;
comment = '';
loc = null;
list.push(item);
state = COMMENT_TEXT;
text = slice(text, 1);
break;
}
const match = text.match(propRule);
if (mode === OUTER_MODE) {
comment += '*/';
}
if (match && !prefixRule.test(match[2])) {
const prefix = match[1] || '';
const suffix = match[3] || '';
text = slice(text, 2);
const target = {
name: match[2],
};
const item = {
value: comment,
start: loc,
end: {
line,
column,
}
};
if (varRule.test(prefix)) {
target.var = prefix.trim();
}
state = TEXT;
comment = '';
loc = null;
list.push(item);
if (prefix.includes('class')) {
target.class = true;
}
const match = text.match(propRule);
if (prefix.includes('async') || suffix.includes('async')) {
target.async = true;
}
if (match && !prefixRule.test(match[2])) {
const prefix = match[1] || '';
const suffix = match[3] || '';
if (prefix.includes('static')) {
target.static = true;
}
const target = {
name: match[2],
};
if (prefix.includes('function')) {
target.function = true;
}
if (varRule.test(prefix)) {
target.var = prefix.trim();
}
item.target = target;
}
if (prefix.includes('class')) {
target.class = true;
}
if (item.value.trim().startsWith('@array ')) {
state = ARRAY_START_WAIT;
}
if (prefix.includes('async') || suffix.includes('async')) {
target.async = true;
}
else {
state = COMMENT_TEXT;
text = slice(text, 1);
if (prefix.includes('static')) {
target.static = true;
}
if (prefix.includes('function')) {
target.function = true;
}
item.target = target;
}
else {
state = TEXT;
comment = '';
loc = null;
if (item.value.trim().startsWith('@array ')) {
state = ARRAY_START_WAIT;
}
break;

@@ -261,0 +296,0 @@ }

{
"name": "api-doc-validator",
"version": "2.24.0",
"version": "2.25.0",
"description": "api doc and validator",

@@ -5,0 +5,0 @@ "main": "index.js",

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