jsdoc2md / dmd

The default output template for jsdoc2md
MIT License
39 stars 49 forks source link

kind should not assume "global function" #95

Open ericelliott opened 5 years ago

ericelliott commented 5 years ago

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.

ericelliott commented 5 years ago

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

75lb commented 3 years ago

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.