jsdoc-to-markdown
jsdoc-to-markdown copied to clipboard
kind should not assume "global function"
Given this input:
import { pipe, toLower, split, join, filter } from 'ramda';
const randomChars = n =>
Math.random().toString(36).split('').slice(-(n)).join('');
const stripInvalid = str => str.replace(/[^a-zA-Z0-9-]/g, '');
const removeDashes = x => x !== '–' && x !== '-';
const exists = x => x !== undefined && x !== null;
const toString = s => exists(s) ? `${ s }` : randomChars(7);
/**
* toSlug
* Takes a string and converts it into a URL-safe string,
* replacing spaces with dashes, removing capitalized letters, and
* stripping unsafe characters out.
*
* @param {(string|number)} s A string to slugify
* @return {string} A slugified string
*/
const toSlug = s => pipe(
toString,
toLower,
split(' '),
filter(removeDashes),
join('-'),
stripInvalid
)(s);
export default toSlug;
I get the following output:
toSlug(s) ⇒ string
toSlug Takes a string and converts it into a URL-safe string, replacing spaces with dashes, removing capitalized letters, and stripping unsafe characters out.
Kind: global function
Returns: string - A slugified string
| Param | Type | Description |
|---|---|---|
| s | string | number |
A string to slugify |
Clearly, the kind should not be global function because the function is not global. It's scoped within a module. If I add module to the top of the file, it gets worse: Now it assumes it's a method. It's not. It's just a function. Not a global, not a method, not a class. Just a function. If I annotate it with @kind function it still says, Kind: global function.
Workaround:
jsdoc2md src/lib/to-slug/index.js | sed '/\*\*Kind\*\*/d'
Produces:
toSlug(s) ⇒ string
toSlug takes a string and converts it into a URL-safe string, replacing spaces with dashes, removing capitalized letters, and stripping unsafe characters out.
Returns: string - A slugified string
| Param | Type | Description |
|---|---|---|
| s | string | number |
A string to slugify |
True, that function is module scope, not global. In which case you should have a @module tag defined but as you say, the module-scope function is then described as a "method" which it is not.
I think the "method" text is a legacy thing stemming from the old days when functions were exported by attaching them as a method to the Node.js global exports object. Before ES Modules, functions were literally exported as a method in Node.js.
Either way, yes this needs correcting.