Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

comment-parser

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comment-parser - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# v0.6.1
- adjust strigifier indentation
# v0.6.0

@@ -2,0 +5,0 @@ - soft-drop node@6 support

2

package.json
{
"name": "comment-parser",
"version": "0.6.0",
"version": "0.6.1",
"description": "Generic JSDoc-like comment parser. ",

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

@@ -163,2 +163,17 @@ # comment-parser

## Stringifying
One may also convert `comment-parser` JSON structures back into strings using
the `stringify` method (`stringify(o:(Object|Array) [, opts:Object]):String`).
This method accepts the JSON as its first argument and an optional options
object with an `indent` property set to either a string or a number that
will be used to determine the number of spaces of indent. The indent of the
start of the doc block will be one space less than the indent of each line of
asterisks for the sake of alignment as per usual practice.
The `stringify` export delegates to the specialized methods `stringifyBlocks`,
`stringifyBlock`, and `stringifyTag`, which are available on the `stringify`
function object.
## Packaging

@@ -165,0 +180,0 @@

@@ -7,2 +7,17 @@ 'use strict'

module.exports = exports = function stringify (arg, opts) {
if (Array.isArray(arg)) {
return stringifyBlocks(arg, opts)
}
if (arg && typeof arg === 'object') {
if ('tag' in arg) {
return stringifyTag(arg, opts)
}
if ('tags' in arg) {
return stringifyBlock(arg, opts)
}
}
throw new TypeError('Unexpected argument passed to `stringify`.')
}
const stringifyBlocks = exports.stringifyBlocks = function stringifyBlocks (

@@ -14,3 +29,3 @@ blocks, { indent = '' } = {}

return s + stringifyBlock(block, { indent })
}, '/**\n') + indnt + '*/'
}, (indnt ? indnt.slice(0, -1) : '') + '/**\n') + indnt + '*/'
}

@@ -23,3 +38,3 @@

const indnt = getIndent(indent)
return indnt + '* ' + block.description + '\n' + indnt + '*\n' +
return (block.description ? `${indnt}* ${block.description}\n${indnt}*\n` : '') +
block.tags.reduce((s, tag) => {

@@ -46,16 +61,1 @@ return s + stringifyTag(tag, { indent })

}
module.exports = function stringify (arg, opts) {
if (Array.isArray(arg)) {
return stringifyBlocks(arg, opts)
}
if (arg && typeof arg === 'object') {
if ('tag' in arg) {
return stringifyTag(arg, opts)
}
if ('tags' in arg) {
return stringifyBlock(arg, opts)
}
}
throw new TypeError('Unexpected argument passed to `stringify`.')
}

@@ -29,3 +29,3 @@ 'use strict'

it('should stringify indented doc block with description', function () {
const expected = `/**
const expected = ` /**
* Singleline or multiline description text. Line breaks are preserved.

@@ -50,3 +50,3 @@ *

it('should stringify numeric indented doc block with description', function () {
const expected = `/**
const expected = ` /**
* Singleline or multiline description text. Line breaks are preserved.

@@ -69,2 +69,15 @@ *

})
it('should stringify numeric indented doc block without description', function () {
const expected = ` /**
* @param Foo
*/`
const parsed = parser(expected)
expect(parsed).to.be.an('array')
const stringified = parser.stringify(parsed, { indent: 4 })
expect(stringified).to.eq(expected)
})
})
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