Repository URL to install this package:
|
Version:
2.0.1 ▾
|
import { isNull, isUndefined } from '../primitive/nil'
import toObjStringTag from './toObjStringTag'
import { Kindof } from '../../../typings'
/**
* @name toKindOf
* @since 5.0.0-beta.9
*
* @param {*} x any
* @return {string} objectToStringTag but lowercased & stripped of brackets
*
* @see is/toS
*
* {@link https://github.com/ramda/ramda/blob/master/src/type.js ramda-type}
* @see {@link ramda-type}
*
* @example toKindOf('stringy') //=> 'String'
*/
const toKindOf = (x: any, allLowerCase = undefined): Kindof => {
const tag = isNull(x)
? 'Null'
: isUndefined(x)
? 'Undefined'
: toObjStringTag(x).slice(8, -1)
return allLowerCase === true ? tag.toLowerCase() : tag
// toObjStringTag(x).replace(/\[|\]|\s+|Object/gim, '').toLowerCase()
// let asTag = toObjStringTag(x)
// .replace('[', '')
// .replace(']', '')
// .replace('object', '')
// .replace('Object', '')
// .replace(/\s+/, '')
// // then was [object Object]
// if (asTag === '') asTag = 'Object'
// if (allLowerCase === true) asTag = asTag.toLowerCase()
// return asTag
}
export { toKindOf }
export default toKindOf