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