jest-docblock
Advanced tools
Comparing version 22.4.3 to 23.0.1
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
@@ -15,3 +15,3 @@ }); | ||
function _load_detectNewline() { | ||
return _detectNewline = _interopRequireDefault(require('detect-newline')); | ||
return (_detectNewline = _interopRequireDefault(require('detect-newline'))); | ||
} | ||
@@ -22,6 +22,8 @@ | ||
function _load_os() { | ||
return _os = require('os'); | ||
return (_os = require('os')); | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
@@ -34,3 +36,3 @@ /** | ||
* | ||
* | ||
* | ||
*/ | ||
@@ -62,5 +64,10 @@ | ||
function parseWithComments(docblock) { | ||
const line = (0, (_detectNewline || _load_detectNewline()).default)(docblock) || (_os || _load_os()).EOL; | ||
const line = | ||
(0, (_detectNewline || _load_detectNewline()).default)(docblock) || | ||
(_os || _load_os()).EOL; | ||
docblock = docblock.replace(commentStartRe, '').replace(commentEndRe, '').replace(stringStartRe, '$1'); | ||
docblock = docblock | ||
.replace(commentStartRe, '') | ||
.replace(commentEndRe, '') | ||
.replace(stringStartRe, '$1'); | ||
@@ -76,9 +83,15 @@ // Normalize multi-line directives | ||
const result = Object.create(null); | ||
const comments = docblock.replace(propertyRe, '').replace(ltrimNewlineRe, '').trimRight(); | ||
const comments = docblock | ||
.replace(propertyRe, '') | ||
.replace(ltrimNewlineRe, '') | ||
.trimRight(); | ||
let match; | ||
while (match = propertyRe.exec(docblock)) { | ||
while ((match = propertyRe.exec(docblock))) { | ||
// strip linecomments from pragmas | ||
const nextPragma = match[2].replace(lineCommentRe, ''); | ||
if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) { | ||
if ( | ||
typeof result[match[1]] === 'string' || | ||
Array.isArray(result[match[1]]) | ||
) { | ||
result[match[1]] = [].concat(result[match[1]], nextPragma); | ||
@@ -89,3 +102,3 @@ } else { | ||
} | ||
return { comments, pragmas: result }; | ||
return {comments, pragmas: result}; | ||
} | ||
@@ -99,3 +112,5 @@ | ||
const line = (0, (_detectNewline || _load_detectNewline()).default)(comments) || (_os || _load_os()).EOL; | ||
const line = | ||
(0, (_detectNewline || _load_detectNewline()).default)(comments) || | ||
(_os || _load_os()).EOL; | ||
const head = '/**'; | ||
@@ -107,3 +122,7 @@ const start = ' *'; | ||
const printedObject = keys.map(key => printKeyValues(key, pragmas[key])).reduce((arr, next) => arr.concat(next), []).map(keyValue => start + ' ' + keyValue + line).join(''); | ||
const printedObject = keys | ||
.map(key => printKeyValues(key, pragmas[key])) | ||
.reduce((arr, next) => arr.concat(next), []) | ||
.map(keyValue => start + ' ' + keyValue + line) | ||
.join(''); | ||
@@ -120,5 +139,16 @@ if (!comments) { | ||
const printedComments = comments.split(line).map(textLine => `${start} ${textLine}`).join(line) + line; | ||
const printedComments = | ||
comments | ||
.split(line) | ||
.map(textLine => `${start} ${textLine}`) | ||
.join(line) + line; | ||
return head + line + (comments ? printedComments : '') + (comments && keys.length ? start + line : '') + printedObject + tail; | ||
return ( | ||
head + | ||
line + | ||
(comments ? printedComments : '') + | ||
(comments && keys.length ? start + line : '') + | ||
printedObject + | ||
tail | ||
); | ||
} | ||
@@ -128,2 +158,2 @@ | ||
return [].concat(valueOrArray).map(value => `@${key} ${value}`.trim()); | ||
} | ||
} |
{ | ||
"name": "jest-docblock", | ||
"version": "22.4.3", | ||
"version": "23.0.1", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
# jest-docblock | ||
`jest-docblock` is a package that can extract and parse a specially-formatted | ||
comment called a "docblock" at the top of a file. | ||
`jest-docblock` is a package that can extract and parse a specially-formatted comment called a "docblock" at the top of a file. | ||
@@ -93,24 +92,18 @@ A docblock looks like this: | ||
Extracts a docblock from some file contents. Returns the docblock contained in | ||
`contents`. If `contents` did not contain a docblock, it will return the empty | ||
string (`""`). | ||
Extracts a docblock from some file contents. Returns the docblock contained in `contents`. If `contents` did not contain a docblock, it will return the empty string (`""`). | ||
### `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. | ||
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 | string[] }` | ||
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. | ||
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. | ||
### `parseWithComments(docblock: string): { comments: string, pragmas: {[key: string]: string | string[]} }` | ||
Similar to `parse` except this method also returns the comments from the | ||
docblock. Useful when used with `print()`. | ||
Similar to `parse` except this method also returns the comments from the docblock. Useful when used with `print()`. | ||
### `print({ comments?: string, pragmas?: {[key: string]: 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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6979
125
109