Installation
Quick Take
Examples
Idea
In essence,
// aaa
// + bbb (negative offset of 2 means it's pushed to the left by 2 places)
// -----
// = bbbaa
API — overlap()
The main function overlap()
is imported like this:
It’s a function which takes three input arguments:
Input argument | Type | Obligatory | Description |
---|---|---|---|
str1 Type: String Obligatory: yes | |||
str1 | String | yes | The string which will be put “under” str2 |
str2 Type: String Obligatory: yes | |||
str2 | String | yes | The string which will be put “over” str1 |
opts Type: Plain object Obligatory: no | |||
opts | Plain object | no | Optional Options Object. |
The Optional Options Object has the following shape:
Key | Type | Default | Description |
---|---|---|---|
offset Type: Positive or negative integer or zero Default: 0 | |||
offset | Positive or negative integer or zero | 0 | It instructs to offset the top string by this many characters to the right (if a positive number) or to the left (if a negative number). The default value is zero. |
offsetFillerCharacter Type: String Default: " " (a single space) | |||
offsetFillerCharacter | String | " " (a single space) | If the offset value (character amount to push left) pushes the str2 outside the boundaries of str1 and not even there’s no overlap, but there is a gap, this gap is formed out of these characters. The default is a single space. |
Here are all defaults in one place for copying:
The function will return a string.
API — defaults
You can import defaults
:
It's a plain object:
The main function calculates the options to be used by merging the options you passed with these defaults.
API — version
You can import version
:
Edge cases
The algorithm is the following:
- If one and only one of two input strings is zero-long, the other string is returned as a result.
- If both input strings are empty, an empty string is returned.
- If both input strings are non-empty, the result is second string overlaid on the first, considering the offset.