Mindblown: a blog about philosophy.
-
Word Boundary: \b
The word boundary \b corresponds to positions when one of the sides is a word character, and the other one is not. Word boundaries are especially handy when it is necessary to match a sequence of letters or digits on their own. Or it is useful when you want to ensure that they happen at the start…
-
Multiline Mode of Anchors ^ $, Flag
In this chapter, you will learn when and how to use the multiline mode of the anchors in JavaScript. The multiline property is a read-only property of an individual regexp instance. It specifies whether or not the m flag is applied inside the regexp. So, for enabling the multiline mode the m flag is used. The value of the multiline property is boolean:…
-
Anchors: string start ^ and end $
In JavaScript, the anchors are the caret ^ and the dollar $ characters, having a specific meaning in a regular expression. The caret corresponds at the beginning of the text and the dollar- at the end. For example, let’s check whether the text begins with Welcome: The pattern ^Welcome means that the string starts and then Sarah. In another example, let’s check whether the text ends with…
-
Flag and class
JavaScript applies Unicode encoding for strings. The majority of the characters are encoded with two bytes, but it allows representing at most 65536 characters. However, the range is not large enough for encoding all the possible characters. For that reason, several rare characters are encoded with four bytes. The Unicode values for some characters are represented below: Character…
-
Character Classes
Character classes are used for distinguishing characters like distinguishing between digits and letters. Let’s start from a practical case. Imagine you have a phone number like +3(522) -865-42-76, and wish to turn it into pure numbers (35228654276). To meet that goal, it is necessary to find and remove everything that’s not a number.Character classes are…
-
Patterns and Flags
Regular expressions are the patterns, providing a robust means of searching and replacing in the text. They are available via the Regexp object in JavaScript. Also, they are integrated into the methods of strings. Regular Expressions A regular expression ( or a “regexp”, “regex”, “reg”) encompasses a pattern and optional flags. Two syntaxes (long and short) are used for…
-
Shadow DOM and Events
The main aim of the shadow tree is encapsulating the component’s internal implementation details. The events occurring inside the shadow DOM take the host element as the target once caught out of the component. Here is an example: Once you click the button, the following messages will be shown: Inner target: BUTTON – the internal event handler receives the correct target,…
-
Shadow DOM Styling
Shadow DOM encompasses both <link rel=”stylesheet” href=”…”> and <style>. For the first case, the style sheets are HTTP-cached. Hence, they can’t be re-downloaded for multiple components that apply similar templates. The primary rule is that local styles can operate only within the shadow tree. But, the document styles work out of that tree. Of course, there can be exceptions…
-
Shadow DOM Slots, Composition
Different types of components like menus, tabs, image galleries, and more, need the content for rendering. The <custom-tabs> might wait for the actual tab content to be passed like the <select> expects the <option> items. The code implementing the <custom-menu> is as follows: Then the component above should render it adequately. But it’s essential to know how to perform it. It is possible…
-
Template Element
In this chapter, we cover a built-in template element, serving as a storage for HTML markup templates. Its contents are ignored by the browser. It only checks for syntax validity. However, it can be accessed and used in JavaScript for creating other elements. Now, let’s see what is so unique about the <template>. First and foremost, any valid…
Got any book recommendations?