Skip to content
Nicholas Berlette edited this page Jun 19, 2025 · 1 revision

@nick/is/tagged

isTagged

Signature

function isTagged<O = {}, T extends string = string>(it: O): it is O & {
  readonly [Symbol.toStringTag]: NormalizeTag<T>;
};

Checks if a given value has a Symbol.toStringTag property, and optionally checks if the value of that property matches the given tag.

Parameters
Name Info
it The value to check.
tag The value to check against.
Returns

true if the value has a Symbol.toStringTag property that matches the given tag (if provided), otherwise false.

Category

Objects

normalizeTag

Signature

function normalizeTag<T extends string>(tag: T): NormalizeTag<T>;

Normalizes a given toStringTag value, removing any leading and trailing whitespace and any leading [object and trailing ], if present.

normalizeTag

Signature

function normalizeTag(tag: string): string;

normalizeTag

Signature

function normalizeTag(tag: string): string;

NormalizeTag

Signature

export type NormalizeTag<T extends string> = Trim<
  T extends `[object ${infer U}]` ? U : T
>;
Type Parameters
  • T extends string

Clone this wiki locally