isWrapper()
Wrapper.isWrapper()
Wrapper.isWrapper()
The method checks if the value
of any type is an instance of the Wrapper
of any, or given opening
, closing
chars, and text
.
public static isWrapper<
Opening extends string,
Closing extends string,
Text extends string = string
>(
value: any,
opening?: Opening,
closing?: Closing,
text?: Text
): value is Wrapper<Opening, Text, Closing> {
return (
typeof value === 'object' &&
value instanceof this &&
super.isWrap(value, opening, closing, text)
);
}
Generic type variables
Opening
extends
string
Opening
extends
string
A generic type variable constrained by the string
, by default of the value captured from the provided opening
indicates the type of the opening in the Wrapper
via return type.
Closing
extends
string
Closing
extends
string
A generic type variable constrained by the string
, by default of the value captured from the provided closing
indicates the type of the closing in the Wrapper
via return type.
Text
extends
string
=
string
Text
extends
string
=
string
A generic type variable constrained by the string
, by default of the value captured from the provided text
indicates the type of the text in the Wrapper
via return type.
Parameters
value: any
value: any
The value of any type to test against the instance of Wrapper
.
opening?: Opening
opening?: Opening
Optional opening chars of a generic type variable Opening
to check if the given value
contains.
closing?: Closing
closing?: Closing
Optional closing chars of a generic type variable Closing
to check if the given value
contains.
text?: Text
text?: Text
An optional text of generic type variable Text
to check if the given value
contains.
Return type
value is Wrapper<Opening, Text, Closing>
The return type is a boolean that indicates the value
is the Wrapper
instance.
Returns
The return value is a boolean
type indicating whether the value
is an instance of Wrapper
of any, or the given opening
, closing
chars, and text
.
Example usage
Returns true
true
// Example usage.
import { Wrapper } from '@angular-package/wrapper';
const tagWrapper = new Wrapper('[', ']', 'quote');
// Returns true confirming the type Wrapper<string, string, string>
Wrapper.isWrapper(tagWrapper);
// Returns true confirming the type Wrapper<"[", string, string>
Wrapper.isWrapper(tagWrapper, '[');
// Returns true confirming the type Wrapper<"[", string, "]">
Wrapper.isWrapper(tagWrapper, '[', ']');
// Returns true confirming the type Wrapper<"[", "quote", "]">
Wrapper.isWrapper(tagWrapper, '[', ']', 'quote');
// Returns true confirming the type Wrapper<string, "quote", "]">
Wrapper.isWrapper(tagWrapper, undefined, ']', 'quote');
// Returns true confirming the type Wrapper<"[", "quote", string>
Wrapper.isWrapper(tagWrapper, '[', undefined, 'quote');
// Returns true confirming the type Wrapper<string, "quote", string>
Wrapper.isWrapper(tagWrapper, undefined, undefined, 'quote');
// Returns true confirming the type Wrapper<string, string, "]">
Wrapper.isWrapper(tagWrapper, undefined, ']');
// Returns true confirming the type Wrapper<"[", string, "]">
Wrapper.isWrapper<'[', ']'>(tagWrapper);
Return false
false
// Example usage.
import { Wrapper } from '@angular-package/wrapper';
const tagWrapper = new Wrapper('[', ']', 'quote');
// Returns false denying the type Wrapper<"<", string, string>
Wrapper.isWrapper(tagWrapper, '<');
// Returns false denying the type Wrapper<"<", string, ">">
Wrapper.isWrapper(tagWrapper, '<', '>');
// Returns false denying the type Wrapper<"<", "quote", ">">
Wrapper.isWrapper(tagWrapper, '<', '>', 'quote');
// Returns false denying the type Wrapper<string, "quote", ">">
Wrapper.isWrapper(tagWrapper, undefined, '>', 'quote');
// Returns false denying the type Wrapper<"<", "quote", string>
Wrapper.isWrapper(tagWrapper, '<', undefined, 'quote');
// Returns false denying the type Wrapper<string, "no-quote", string>
Wrapper.isWrapper(tagWrapper, undefined, undefined, 'no-quote');
// Returns false denying the type Wrapper<string, string, ">">
Wrapper.isWrapper(tagWrapper, undefined, '>');
// Returns false denying the type Wrapper<"[", "", "]">
Wrapper.isWrapper<'[', ']'>(null as any);
Confirms the wrong type
// Example usage.
import { Wrapper } from '@angular-package/wrapper';
const tagWrapper = new Wrapper('[', ']', 'quote');
// Returns true confirming the type Wrapper<"<", string, ">">
Wrapper.isWrapper<'<', '>'>(tagWrapper);
Last updated
Was this helpful?