Socket
Socket
Sign inDemoInstall

jest-docblock

Package Overview
Dependencies
Maintainers
5
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-docblock - npm Package Compare versions

Comparing version 21.3.0-alpha.1e3ee68e to 21.3.0-alpha.eff7a1cf

9

build/index.js

@@ -29,2 +29,7 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.

strip = strip;exports.
parse = parse;exports.

@@ -70,4 +75,4 @@

*
*/const commentEndRe = /\*\/$/;const commentStartRe = /^\/\*\*/;const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;const lineCommentRe = /\/\/([^\r\n]*)/g;const ltrimRe = /^\s*/;const multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;const propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;const stringStartRe = /(\r?\n|^) *\*/g;const lineStartRe = /(\r?\n|^) */g;const wsRe = /[\t ]+/g;function extract(contents) {const match = contents.match(docblockRe);return match ? match[0].replace(ltrimRe, '') || '' : '';}function parse(docblock) {return parseWithComments(docblock).pragmas;}function parseWithComments(docblock) {const line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL;docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(wsRe, ' ').replace(lineCommentRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
let prev = '';while (prev !== docblock) {prev = docblock;docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);}docblock = docblock.trim();const result = Object.create(null);const comments = docblock.replace(propertyRe, '').replace(lineStartRe, line);let match;while (match = propertyRe.exec(docblock)) {result[match[1]] = match[2];}return { comments: comments.trim(), pragmas: result };}function print(_ref) {var _ref$comments = _ref.comments;let comments = _ref$comments === undefined ? '' : _ref$comments;var _ref$pragmas = _ref.pragmas;let pragmas = _ref$pragmas === undefined ? {} : _ref$pragmas;const line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL;const head = '/**';
*/const commentEndRe = /\*\/$/;const commentStartRe = /^\/\*\*/;const docblockRe = /^\s*(\/\*\*?(.|\r?\n)*?\*\/)/;const lineCommentRe = /\/\/([^\r\n]*)/g;const ltrimRe = /^\s*/;const rtrimRe = /\s*$/;const ltrimNewlineRe = /^(\r?\n)+/;const multilineRe = /(?:^|\r?\n) *(@[^\r\n]*?) *\r?\n *([^@\r\n\s][^@\r\n]+?) *\r?\n/g;const propertyRe = /(?:^|\r?\n) *@(\S+) *([^\r\n]*)/g;const stringStartRe = /(\r?\n|^) *\* ?/g;function extract(contents) {const match = contents.match(docblockRe);return match ? match[0].replace(ltrimRe, '') || '' : '';}function strip(contents) {const match = contents.match(docblockRe);return match && match[0] ? contents.substring(match[0].length) : contents;}function parse(docblock) {return parseWithComments(docblock).pragmas;}function parseWithComments(docblock) {const line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL;docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(lineCommentRe, '').replace(stringStartRe, '$1'); // Normalize multi-line directives
let prev = '';while (prev !== docblock) {prev = docblock;docblock = docblock.replace(multilineRe, `${line}$1 $2${line}`);}docblock = docblock.replace(ltrimNewlineRe, '').replace(rtrimRe, '');const result = Object.create(null);const comments = docblock.replace(propertyRe, '');let match;while (match = propertyRe.exec(docblock)) {result[match[1]] = match[2];}return { comments, pragmas: result };}function print(_ref) {var _ref$comments = _ref.comments;let comments = _ref$comments === undefined ? '' : _ref$comments;var _ref$pragmas = _ref.pragmas;let pragmas = _ref$pragmas === undefined ? {} : _ref$pragmas;const line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL;const head = '/**';
const start = ' *';

@@ -74,0 +79,0 @@ const tail = ' */';

{
"name": "jest-docblock",
"version": "21.3.0-alpha.1e3ee68e",
"version": "21.3.0-alpha.eff7a1cf",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

@@ -60,3 +60,3 @@ # jest-docblock

const { extract, parse, parseWithComments, print } = require("jest-docblock");
const { extract, strip, parse, parseWithComments, print } = require("jest-docblock");

@@ -66,2 +66,5 @@ const docblock = extract(code);

const stripped = strip(code);
console.log(stripped); // "export const everything = Object.create(null);\n export default function isAwesome(something) {\n return something === everything;\n }"
const pragmas = parse(docblock);

@@ -81,2 +84,5 @@ console.log(pragmas); // { everything: "is:awesome", flow: "" }

### `strip(contents: string): string`
Strips the top docblock from a file and return the result. If a file does not have a docblock at the top, then return the file unchanged.
### `parse(docblock: string): {[key: string]: string}`

@@ -89,2 +95,2 @@ Parses the pragmas in a docblock string into an object whose keys are the pragma tags and whose values are the arguments to those pragmas.

### `print({ comments?: string, pragmas?: {[key: string]: string} }): string`
Prints an object of key-value pairs back into a docblock. If `comments` are provided, they will be positioned on the top of the docblock.
Prints an object of key-value pairs back into a docblock. If `comments` are provided, they will be positioned on the top of the docblock.
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