Introduction

Text on the template with replaceable tags.

Idea

The package was created on the idea of having the ability to create a short text on a changeable template with ease-replaceable tags inside it.

Some of its elements are based on primitive wrapper objects, exactly the string object, which is immutable. They were built as general objects with intuitive names, unique and most important features for their names, and in a simple ease-extendable form. One of the pros of this approach is the functionality follows the type because these objects can be used as the types, which results in fewer typescript types.

There are two ways using the method of an instance, the method do actions on the instance or the method use the instance to do some action. Because of the immutable nature of the primitive wrapper objects there are often method uses instance to do some action.

Elements

Let's deep dive into the elements of the text package. From the bottom of the build hierarchy, there's a Wrap string object that represents a two-character wrap with its main ability to wrap a specified text. This wrap result in a Wrapped string object of the wrapped text.

To create a Wrap object there is a need to use a new operator, and in addition to this, there's an object Wrapper, which helps create it with predefined allowed characters and also wrap the specified text with the use of predefined Wrap. So, it is simply a configurable "machine" to build a wrap in a restricted range of characters.

Of course, the Wrap object gives a possibility to create a new object with additional features by simply extending it. And by this way string object named Tag was created with its main ability to build a tag of a specified name and wrap(e.g. like an HTML tag), which is used to tag a specified text with an opening tag and an automatically created the closing tag.

The last two in the build hierarchy are respectively the Template and Text, where the first is a string object that contains tags and its equivalent Tag objects, and the second is an object consisting of string text and string object Template to replace the tags with real words.

What are the benefits of this approach? Read the next section.

Last updated