Skip to content

xsfj/extract-stringtag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

extract-stringtag

A lightweight utility to extract the internal class name (like Function) from a string formatted like [object Function]. This is particularly useful when working with custom objects that implement Symbol.toStringTag or for parsing results from Object.prototype.toString.


Installation

npm install extract-stringtag

Usage

This module identifies if a string follows the standard [object Tag] pattern and returns only the Tag portion. If the input is not a string or doesn't match the pattern, it returns null.

const extractStringTag = require('extract-stringtag');

// Standard built-in tags
extractStringTag('[object Array]')     // 'Array'
extractStringTag('[object Object]')    // 'Object'
extractStringTag('[object Promise]')   // 'Promise'

// Custom tags
extractStringTag('[object MyClass]')   // 'MyClass'

// Invalid inputs
extractStringTag('not a tag')          // null
extractStringTag(123)                  // null
extractStringTag('[object Unclosed')   // null

License

Unlicense

Tests

do a git clone, then run npm test

About

just get "..." from "[object ...]"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •