Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kind should not assume "global function" #95

Open
ericelliott opened this issue Jan 31, 2019 · 2 comments
Open

kind should not assume "global function" #95

ericelliott opened this issue Jan 31, 2019 · 2 comments
Labels

Comments

@ericelliott
Copy link

ericelliott commented Jan 31, 2019

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
Copy link
Author

ericelliott commented Jan 31, 2019

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
Copy link
Member

75lb commented Mar 25, 2021

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.

@75lb 75lb transferred this issue from jsdoc2md/jsdoc-to-markdown Sep 1, 2024
@75lb 75lb added bug and removed enhancement labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants