Skip to content

kind should not assume "global function" #95

@ericelliott

Description

@ericelliott

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions