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
  • Wrap.isWrap()
  • Wrap.template()

Was this helpful?

  1. Wrapper
  2. Wrap

Static methods

The static methods of `Wrap` the string object.

PreviousInstance propertiesNextWrap() constructor

Last updated 3 years ago

Was this helpful?

Public

Wrap.isWrap()

The method checks if the value of any type is the instance of any or given opening and closing.

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

Opening extends string

Closing extends string

Parameters

Name: type
Description

value: any

The value of any type to test against the Wrap instance of any or given opening and closing.

opening?: Opening

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

closing?: Closing

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

Returns

Return type

value is Wrap<Opening, Closing>

Example usage

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

const tagWrap = new Wrap(`[`, `]`);

// Returns true confirming the type Wrap<string, string>
Wrap.isWrap(tagWrap);

// Returns true confirming the type Wrap<"[", "]">
Wrap.isWrap(tagWrap, ['[', ']']);

// Returns true confirming the type Wrap<"[", "]">
Wrap.isWrap<'[', ']'>(tagWrap, ['[', ']']);

// Returns false by denying the value is Wrap<"(", ")">
Wrap.isWrap(tagWrap, ['(', ')']);

// Returns false by denying the value is Wrap<"[", "]">
Wrap.isWrap<'[', ']'>(null as any);

// Returns false by denying the value is Wrap<"[", "]">
Wrap.isWrap(null as any, ['[', ']']);

Wrap.template()

wrap.class.ts
public static template(
  template: TemplateStringsArray,
  ...values: string[]
): string {
  let opening, closing;
  if (areString(...values).every()) {
    return (
      ([opening, closing] = values), `${opening}${template[0]}${closing}`
    );
  }
  return ``;
}

Parameters

Name: type
Description

template: TemplateStringsArray

...values: string[]

Returns

Example usage

import { Wrap } from '@angular-package/text';

// Returns {{inside}}
Wrap.template`inside${'{{'}${'}}'}`;

A generic type variable constrained by the , by default of the value captured from the provided wrap indicates the Opening type of the instance via the return type.

A generic type variable constrained by the , by default of the value captured from the provided wrap indicates the Closing type of the instance via the return type.

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

The return value is a type indicating whether the value is an instance of Wrap of any or given opening and closing.

The static "tag" method builds the wrap of a type on the template. With the added string before the expressions, it returns a wrapped string.

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

A rest parameter of expressions, where the first element is the and the second is the of the wrap.

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

Wrap
boolean
string
string
string
Wrap
string
Wrap
Wrap
opening
closing
opening
closing