jest-docblock
Advanced tools
Comparing version 22.2.0 to 22.2.2
@@ -24,2 +24,4 @@ 'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports. | ||
extract = extract;exports. | ||
@@ -39,5 +41,5 @@ | ||
parseWithComments = parseWithComments;exports. | ||
parseWithComments = parseWithComments;exports. | ||
@@ -74,2 +76,8 @@ | ||
print = print;var _detectNewline;function _load_detectNewline() {return _detectNewline = _interopRequireDefault(require('detect-newline'));}var _os;function _load_os() {return _os = require('os');}function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
@@ -84,3 +92,3 @@ * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
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, '').replace(ltrimNewlineRe, '').replace(rtrimRe, '');let match;while (match = propertyRe.exec(docblock)) {// strip linecomments from pragmas | ||
result[match[1]] = match[2].replace(lineCommentRe, '');}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 nextPragma = match[2].replace(lineCommentRe, '');if (typeof result[match[1]] === 'string' || Array.isArray(result[match[1]])) {result[match[1]] = [].concat(result[match[1]], nextPragma);} else {result[match[1]] = nextPragma;}}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 = ' *'; | ||
@@ -92,3 +100,5 @@ const tail = ' */'; | ||
const printedObject = keys. | ||
map(key => start + ' ' + printKeyValue(key, pragmas[key]) + line). | ||
map(key => printKeyValues(key, pragmas[key])). | ||
reduce((arr, next) => arr.concat(next), []). | ||
map(keyValue => start + ' ' + keyValue + line). | ||
join(''); | ||
@@ -100,4 +110,5 @@ | ||
} | ||
if (keys.length === 1) { | ||
return `${head} ${printKeyValue(keys[0], pragmas[keys[0]])}${tail}`; | ||
if (keys.length === 1 && !Array.isArray(pragmas[keys[0]])) { | ||
const value = pragmas[keys[0]]; | ||
return `${head} ${printKeyValues(keys[0], value)[0]}${tail}`; | ||
} | ||
@@ -122,4 +133,4 @@ } | ||
function printKeyValue(key, value) { | ||
return `@${key} ${value}`.trim(); | ||
function printKeyValues(key, valueOrArray) { | ||
return [].concat(valueOrArray).map(value => `@${key} ${value}`.trim()); | ||
} |
{ | ||
"name": "jest-docblock", | ||
"version": "22.2.0", | ||
"version": "22.2.2", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
@@ -102,3 +102,3 @@ # jest-docblock | ||
### `parse(docblock: string): {[key: string]: string}` | ||
### `parse(docblock: string): {[key: string]: string | string[] }` | ||
@@ -108,3 +108,3 @@ Parses the pragmas in a docblock string into an object whose keys are the pragma | ||
### `parseWithComments(docblock: string): { comments: string, pragmas: {[key: string]: string} }` | ||
### `parseWithComments(docblock: string): { comments: string, pragmas: {[key: string]: string | string[]} }` | ||
@@ -114,5 +114,5 @@ Similar to `parse` except this method also returns the comments from the | ||
### `print({ comments?: string, pragmas?: {[key: string]: string} }): string` | ||
### `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. |
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
8915
54