Skip to content

Function: toRawType()

toRawType(value): string

Extracts the raw type name from a value (e.g., 'Object', 'Array', 'Date'). This removes the '[object ' prefix and ']' suffix from Object.prototype.toString output.

Parameters

value

unknown

The value to get the raw type for

Returns

string

The raw type name as a string

Example

typescript
console.log(toRawType({}))        // 'Object'
console.log(toRawType([]))        // 'Array'
console.log(toRawType(new Date())) // 'Date'
console.log(toRawType(null))      // 'Null'

Released under the MIT License.