angular-package
TwitterGitHub
Text
Text
  • Introduction
  • Benefits
  • Getting started
    • General concepts
    • Skeleton
    • Installation
    • Public API
  • Wrapper
    • Basic concepts
    • Wrap
      • Generic type variables
      • Instance accessors
      • Instance properties
      • Static methods
      • Wrap() constructor
      • Instance methods
      • Examples
    • Wrapper
      • Generic type variables
      • Static properties
      • Instance accessors
      • Static methods
      • Wrapper() constructor
      • Instance methods
      • Examples
    • Wrapped
      • Generic type variables
      • Instance accessors
      • Instance properties
      • Static methods
      • Wrapped() constructor
      • Instance methods
      • Types
      • Examples
  • Tag
    • Basic concepts
    • Tag
      • Generic type variables
      • Static accessors
      • Static properties
      • Instance accessors
      • Instance properties
      • Static methods
      • Tag() constructor
      • Instance methods
      • Types
      • Examples
    • BBCodeTag
      • Static methods
      • BBCodeTag() constructor
    • HtmlTag
      • Generic type variables
      • HtmlTag() constructor
    • Tags
    • Tagged
  • Main
    • AllowedChars
    • Attribute
      • Generic type variables
      • Instance accessors
      • Instance properties
      • Static methods
      • Attribute() constructor
      • Instance methods
    • Attributes
    • Template
    • Text
  • Legend
    • Property tags
  • Other
    • Contact
    • Sponsor
  • More versions
Powered by GitBook
On this page
  • Public
  • Wrapped.isWrapped()
  • Wrapped.template()

Was this helpful?

  1. Wrapper
  2. Wrapped

Static methods

PreviousInstance propertiesNextWrapped() constructor

Last updated 3 years ago

Was this helpful?

Public

Wrapped.isWrapped()

The static method checks whether the provided value of any type is an instance of .

wrapped.class.ts
public static isWrapped<
  Text extends string,
  Opening extends string = string,
  Closing extends string = string
>(
  value: any,
  opening?: Opening,
  closing?: Closing
): value is Wrapped<Text, Opening, Closing> {
  return isInstance(value, Wrapped)
    ? isStringType(opening) && isStringType(closing)
      ? closing === value.closing && opening === value.opening
      : isStringType(opening)
      ? opening === value.opening
      : isStringType(closing)
      ? closing === value.closing
      : true
    : false;
}
Generic type variables

Text extends string

Opening extends string

Closing extends string

Parameters

Name: type
Description

value: any

opening?: Opening

An optional opening of the wrap to check if the given value contains.

closing?: Closing

An optional closing of the wrap to check if the given value contains.

Returns

Return type

value is Wrapped<Text, Opening, Closing>

Example usage

// Example usage.
import { Wrap, Wrapped } from '@angular-package/text';

// Define the wrapped.
const wrapped = new Wrapped(`[Oh no, I am wrapped]`, new Wrap('[', ']'));

// Returns `true`
Wrapped.isWrapped(wrapped, new Wrap('[', ']'));

Wrapped.template()

wrapped.class.ts
public static template(
  template: TemplateStringsArray,
  ...values: any[]
): string {
  let text, wrap;
  return (
    ([text, wrap] = values),
    `${Wrap.isWrap(wrap) ? wrap.opening : ''}${template[0]}${text || ''}${
      Wrap.isWrap(wrap) ? wrap.closing : ''
    }`
  );
}

Parameters

Name: type
Description

template: TemplateStringsArray

An array of string values where the first element is a text between opening and closing.

...values: any[]

Returns

The return value is a string the wrapped text, or an empty string if elements of the provided values are not string.

Example usage

// Example usage.
import { Wrap, Wrapped } from '@angular-package/text';

// Define.
const wrap = new Wrap('[[[[', ']]]]');

// Returns [[[[prefix-text to be wrapped]]]]
Wrapped.template`prefix-${'text to be wrapped'}${wrap}`;

​A generic type variable constrained by a indicates the text type of in the return type.

A generic type variable constrained by the , by default of the value captured from the provided opening indicates the opening type of a checked instance.

A generic type variable constrained by the , by default of the value captured from the provided closing indicates the closing type of a checked instance.

The value of any type to test against the instance.

The return type is a boolean indicating the value parameter is an instance of that takes a generic type variable Opening and Closing of the wrap and Text of the wrapped text.

The return value is a indicating whether the value is the instance of any or given wrap.

The static "tag" method builds the wrapped text of a string type on the template literal. It consists of a text and an instance of .

A rest parameter of expressions, where the first element is the text and the second is an instance of .

Wrapped
boolean
Wrapped
Wrap
string
Wrapped
string
Wrapped
string
Wrapped
Wrapped
Wrapped
Wrap