MCPcopy
hub / github.com/reduxjs/redux / miniKindOf

Function miniKindOf

src/utils/kindOf.ts:2–38  ·  view source on GitHub ↗
(val: any)

Source from the content-addressed store, hash-verified

1// Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of
2export function miniKindOf(val: any): string {
3 if (val === void 0) return 'undefined'
4 if (val === null) return 'null'
5
6 const type = typeof val
7 switch (type) {
8 case 'boolean':
9 case 'string':
10 case 'number':
11 case 'symbol':
12 case 'function': {
13 return type
14 }
15 }
16
17 if (Array.isArray(val)) return 'array'
18 if (isDate(val)) return 'date'
19 if (isError(val)) return 'error'
20
21 const constructorName = ctorName(val)
22 switch (constructorName) {
23 case 'Symbol':
24 case 'Promise':
25 case 'WeakMap':
26 case 'WeakSet':
27 case 'Map':
28 case 'Set':
29 return constructorName
30 }
31
32 // other
33 return Object.prototype.toString
34 .call(val)
35 .slice(8, -1)
36 .toLowerCase()
37 .replace(/\s/g, '')
38}
39
40function ctorName(val: any): string | null {
41 return typeof val.constructor === 'function' ? val.constructor.name : null

Callers 1

kindOfFunction · 0.85

Calls 3

isDateFunction · 0.85
isErrorFunction · 0.85
ctorNameFunction · 0.85

Tested by

no test coverage detected