
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
jsdoc-to-assert
Advanced tools
Convert JSDoc to assert that runtime assert.
Easy to use it with Babel.
jsdoc-to-assert create detection expression string:
Array.isArray(x) && x.every(function (item) {
return typeof item === 'number';
});
from following JSDoc comment:
/**
* @param {number[]} x
*/
npm install jsdoc-to-assert
import {AssertGenerator, CommentConverter, CodeGenerator} from "jsdoc-to-assert";
Create assertion AST from comment nodes.
/**
* @typedef {Object} AssertGeneratorOptions
* @property {Function} generator
*/
const defaultOptions = {
Generator: CodeGenerator
};
/**
*
* @param {Array<Object>} comments AST's comment nodes. it should be BlockComment
* @param {AssertGeneratorOptions} options
* @returns {Array<String>} array of assertion
*/
static createAsserts(comments, options = {});
/**
* @param tagNode tagNode is defined by doctorin
* @param {CodeGenerator} Generator
* @return {string|undefined} return assertion code string
* Reference https://esdoc.org/tags.html#type-syntax
* https://github.com/eslint/doctrine/blob/master/test/parse.js
*/
static createAssertFromTag(tagNode, Generator = CodeGenerator);
/**
* Parse comment nodes which is provided by JavaScript parser like esprima, babylon
* and return assertions code strings.
* This is mutable function.
* @param {Array<Object>} comment
* @param {AssertGeneratorOptions} [options]
* @returns {string[]}
*/
static toAsserts(comment, options);
Assertion code generator class
/**
* @param commentTagNode commentTagNode is doctrine tag node
*/
constructor(commentTagNode);
/**
* wrap assert function
* @param {string} expression
* @returns {string}
*/
assert(expression) {
return `console.assert(${expression},'${expression}');`;
}
npm test
Comment to assert
git checkout -b my-new-featuregit commit -am 'Add some feature'git push origin my-new-featureMIT
FAQs
Convert comment to assert. runtime assert
The npm package jsdoc-to-assert receives a total of 450 weekly downloads. As such, jsdoc-to-assert popularity was classified as not popular.
We found that jsdoc-to-assert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.