severnway / is-function-spec

Specification of function type detection.
MIT No Attribution
0 stars 0 forks source link

Package: kind-of #2

Open gowpen opened 6 years ago

gowpen commented 6 years ago

The kind-of package uses typeof 'function', with generator functions excluded, to detect normal functions.

  var type = typeof val;
  if (type === 'boolean') return 'boolean';
  if (type === 'string') return 'string';
  if (type === 'number') return 'number';
  if (type === 'symbol') return 'symbol';
  if (type === 'function') {
    return isGeneratorFn(val) ? 'generatorfunction' : 'function';
  }
gowpen commented 6 years ago

The isGeneratorFn() function checks the constructor name property to detect generator functions.

function isGeneratorFn(name, val) {
  return ctorName(name) === 'GeneratorFunction';
}