Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface String

String (Native)

The ThoughtAsylum library includes a set of extensions to the standard String object. These are used to simpify common actions in terms of interrogating and updating strings.

Hierarchy

  • String

Index

Methods

TA_appendWords

  • TA_appendWords(p_strSuffix: string): string
  • Suffix each word in a string with a string of text.

    Parameters

    • p_strSuffix: string

      the text to suffix each word with.

      // Example
      alert("one, two, and three.".TA_appendWords("**"));
      //Displays "one**, two**, and** three**."

    Returns string

TA_capitalise

  • TA_capitalise(): string
  • Capitalise each word in a string based on a word separator being in place. This isn't a perfect implementation (notice the example below using "isn't"), but it is typically good enough, and it does leave existing capital letters in place (again, see the example below).

    // Example
    alert("there isn't I in team, but there is me in tEaM if you look closely".TA_capitalise());
    //Displays "There Isn'T I In Team, But There Is Me In TEaM If You Look Closely"

    Returns string

TA_countLines

  • Counts lines the number of lines in the string.

    // Example
    alert("foo bar".TA_countLines(0));
    // Displays 1

    Parameters

    • Optional p_intBase: TYPE_intCountBase

      Pass in a base of 0 or 1 for how many lines an empty string counts as, defaults to 0.

    Returns number

TA_countWords

  • TA_countWords(): number
  • Counts the number of words in the string

    // Example
    alert("foo bar".TA_countWords());
    // Displays 2

    Returns number

TA_csvToArray

  • TA_csvToArray(): string[]
  • Split a string of comma separated values into an array. Handles whitespace, a mixture of double quoted and non-double quoted elements, and commas within double quoted elements. Returns an array with double quote delimiters removed.

    // Example
    alert(` abc , "def" ,"gh,i"`.TA_csvToArray().join("|"));
    // Displays: abc|def|gh,i

    Returns string[]

TA_deduplicateLines

  • TA_deduplicateLines(): string
  • Deduplicates lines, retaining the original order of first occurrence. Returns the deduplicated string of text lines.

    // Example
    let strTest = "aa\naa\naa\nbb\ncc\naa";
    alert(strTest.TA_deduplicateLines());
    //Returns:
    //aa
    //bb
    //cc

    Returns string

TA_delimitWords

  • TA_delimitWords(p_strDelimit: string): string
  • Delimit each word in a string with a string of text.

    Parameters

    • p_strDelimit: string

      the text to prefix and suffix each word with.

      // Example
      alert("one, two, and three.".TA_delimitWords("*"));
      //Displays "*one*, *two*, *and* *three*."

    Returns string

TA_encodeURI

  • TA_encodeURI(): string
  • Applies a more extensive set of URL encoding to a set of characters than encodeURIComponent(). The function also encodes all characters as per encodeURIComponent(), and in addition, by default, it encodes !, ', *, ~, (, and ). The encoding is defined by the TadLibrary property encodeMap, and is a set of key value pairs - the key being the character to be encoded and the value being it's encoded value. If you should need to extend the range of characters encoded by this function, simply add the necessary key value pairs to your library settings file.

    // Example
    let strText = "Some 100% *AMAZING!* text to (hopefully) encode."
    alert(encodeURIComponent(strText));
    // Displays "Some%20100%25%20*AMAZING!*%20text%20to%20(hopefully)%20encode."
    alert(strText.TA_encodeURI());
    // Displays "Some%20100%25%20%2AAMAZING%21%2A%20text%20to%20%28hopefully%29%20encode."

    Returns string

TA_endsWithRemove

  • TA_endsWithRemove(p_strEndsWith: string): string
  • If a string ends with a specific sub string, this returns the string with that part removed. The original string is otherwise returned unchanged.

    Parameters

    • p_strEndsWith: string

      the sub string to remove from the end of the string if it matches.

      // Example
      alert(`abcd`.TA_endsWithRemove("cd");
      // Displays: ab

    Returns string

TA_fileNameBaseFromPath

  • TA_fileNameBaseFromPath(): string
  • Return the base name of a file from a file path or file name. This is the file name without the file extension.

    // Example
    alert("/Library/Scripts/main.sub.html".TA_fileNameBaseFromPath());
    // returns "main.sub"

    Returns string

TA_fileNameExtensionFromPath

  • TA_fileNameExtensionFromPath(): string
  • Return the file extension of a file from a file path or file name. This is whatever follows the base file name in the file name, excluding the period separator. If the file has no extension, an empty string will be returned.

    // Example
    alert("/Library/Scripts/main.sub.html".TA_fileNameExtensionFromPath());
    // returns "html"
    alert("/Library/Scripts/noext".TA_fileNameExtensionFromPath());
    // returns ""

    Returns string

TA_fileNameFromPath

  • TA_fileNameFromPath(): string
  • Return the file name from a file path. This includes both the base file name and the file extension.

    // Example
    alert("/Library/Scripts/main.sub.html".TA_fileNameFromPath());
    // returns "main.sub.html"

    Returns string

TA_fileNameRemoveExtensionFromPath

  • TA_fileNameRemoveExtensionFromPath(): string
  • Remove the file extension of a file from a file path or file name. The file extension is whatever follows the base file name in the file name, excluding the period separator.

    // Example
    alert("/Library/Scripts/main.sub.html".TA_fileNameRemoveExtensionFromPath());
    // returns "/Library/Scripts/main.sub"

    Returns string

TA_folderPathFromPath

  • TA_folderPathFromPath(): string
  • Return the folder path from a file path. This is the file path without the file name, but including the trailing slash. If you pass a folder path in with no trailing slash, the function will return the parent folder of the final folder in the path.

    // Example
    alert("/Library/Scripts/main.sub.html".TA_folderPathFromPath());
    // returns "/Library/Scripts/"
    alert("/Library/Scripts".TA_folderPathFromPath());
    // returns "/Library/"

    Returns string

TA_formatDraftsActionLinkToRead

  • TA_formatDraftsActionLinkToRead(): string
  • Takes a drafts action URL and converts it into something slightly more human readable. The string is URL decoded, and tab & newl ine markers are replaced with tab and new line characters respectively. The resulting string is returned.

    // Example
    let strURL = "drafts5://action?data=%7B%22uuid%22:%22C52192C1-4CB7-4C54-AE93-B8592D97CE64%22,%22steps%22:%5B%7B%22platforms%22:3,%22data%22:%7B%22template%22:%22%5B%5Bdraft%5D%5D%22%7D,%22type%22:%22clipboard%22,%22isEnabled%22:true,%22uuid%22:%22D7D0D0DB-95B8-4345-B40C-8E3F872D5612%22%7D%5D,%22groupDisposition%22:0,%22shortName%22:%22Copy%22,%22shouldConfirm%22:false,%22disposition%22:3,%22keyCommand%22:%7B%22optionKey%22:false,%22input%22:%22%22,%22controlKey%22:false,%22commandKey%22:false,%22type%22:%22action%22,%22discoverabilityTitle%22:%22Copy%22,%22shiftKey%22:false%7D,%22logLevel%22:2,%22notificationType%22:2,%22tintColor%22:%22none%22,%22actionDescription%22:%22Copy%20draft%20to%20clipboard.%22,%22keyUseIcon%22:false,%22icon%22:%22action_clipboard_filled%22,%22visibility%22:480,%22groupUUID%22:%22A1DEB68B-98DC-498C-9A12-137A9EA8FBF3%22,%22assignTags%22:%5B%5D,%22name%22:%22Copy%22%7D";
    alert(strURL.TA_formatDraftsActionLinkToRead());

    Returns string

TA_frontMatterIncluded

  • TA_frontMatterIncluded(): Boolean
  • Carries out some basic checks to try and establish if there is a front matter section at the start of the string. The function checks to see if the string begins with a triple dash and has a subsequent triple dash line to mark the end of a front matter section. If it does, it checks to ensure that the lines in the section are either a key (text followed by a colon), a list item (a hyphen, followed by a space, followed by some text), or a comment (an octothorpe, followed by a space, followed by some text). Each of these may be preceded by whitespace, and blank lines are also permitted.
    This is a fairly simple function intended only to verify the simplest sets of front matter. Full YAML testing is not carried out, but this may be epanded in the future. Returns true if the criteria are matched, otherwise false.

    // Example
    alert(draft.content.TA_frontMatterIncluded());

    Returns Boolean

TA_frontMatterSimpleKeyValue

  • TA_frontMatterSimpleKeyValue(p_strKey: string): string
  • Retrieves a front matter value from the string for a specified simple key. Here 'simple key' indicates that it is a root-level key and will appear at the start of a line. The returned value for the key is trimmed of any leading whitespace, and if there is no front matter, or no matching key (please note that it is case sensitive), an empty string is returned.

    Parameters

    • p_strKey: string

      the name of the simple key whose value is to be returned.

      // Example
      alert(draft.content.TA_frontMatterSimpleKeyValue("author"));

    Returns string

TA_head

  • TA_head(): string
  • Returns first character of the string.

    // Example
    alert("foo bar".TA_head());
    // Displays "f"

    Returns string

TA_htmlFirstTagContent

  • TA_htmlFirstTagContent(p_strTag: string): string
  • When the string is an HTML string it returns the content between the first instance of the specified tag pair. Returns the string stripped of such content.

    Parameters

    • p_strTag: string

      the name of the tag to locate the first instance of.

      // Example
      let strHTML = "<html><head><title>Foo Bar</title></head><body>Lorem ipsum dolor sit amet</body></html>";
      strPageTitle = strHTML.TA_htmlFirstTagContent("title");
      // Returns `Foo Bar`

    Returns string

TA_htmlTitle

  • TA_htmlTitle(): string
  • When the string is an HTML string it returns the content between the first instance of the title tag pair. Returns the string stripped of such content.

    // Example
    let strHTML = "<html><head><title>Foo Bar</title></head><body>Lorem ipsum dolor sit amet</body></html>";
    strPageTitle = strHTML.TA_htmlTitle();
    // Returns `Foo Bar`

    Returns string

TA_insertAfter0

  • TA_insertAfter0(p_intInsertAfter: number, p_strInsertText: string): string
  • Return the string with the the specified text inserted after the specified 0-based index.

    Parameters

    • p_intInsertAfter: number

      the position index of the character after which the text should be inserted. The first character is at position 0.

    • p_strInsertText: string

      the text to be inserted.

      // Example
      alert("123456789".TA_insertAfter0(3, "qwerty"));
      // Displays "1234qwerty56789"

    Returns string

TA_insertAfter1

  • TA_insertAfter1(p_intInsertAfter: number, p_strInsertText: string): string
  • Return the string with the the specified text inserted after the specified 1-based index.

    Parameters

    • p_intInsertAfter: number

      the position index of the character after which the text should be inserted. The first character is at position 1.

    • p_strInsertText: string

      the text to be inserted.

      // Example
      alert("123456789".TA_insertAfter1(3, "qwerty"));
      // Displays "123qwerty456789"

    Returns string

TA_isJSON

  • TA_isJSON(): Boolean
  • Checks if a string is valid JSON. Returns true only if the string is valid JSON.

    // Example
    let strGoodJSON = '{"foreground" : "white", "background" : "black"}';
    alert(strGoodJSON.TA_isJSON());
    //Displays `true`
    let strBadJSON = '{"foreground" : "white, "background" : "black"}';
    alert(strBadJSON.TA_isJSON());
    //Displays `false`

    Returns Boolean

TA_lengthExclLineBreaks

  • TA_lengthExclLineBreaks(): number
  • Counts the number of characters in the string, but new lines are excluded.

    // Example
    alert("foo bar".TA_lengthExclLineBreaks());

    Returns number

TA_mdCode

  • TA_mdCode(): string
  • Wrap a string in single backticks for a Markdown span of code.

    // Example
    alert(strCode.TA_mdCode());

    Returns string

TA_mdCodeBlock

  • TA_mdCodeBlock(p_strCodeType?: string): string
  • Wrap a string in triple backticks for a Markdown block of code. Accepts an optional parameter to set a code type for syntax highlighting.

    Parameters

    • Optional p_strCodeType: string

      the text to insert after the first set of triple backticks that is used to set syntax highlighting where available. Default is none.

      // Example
      alert(strCode.TA_mdCodeBlock());

    Returns string

TA_mdCodeBlockAS

  • TA_mdCodeBlockAS(): string
  • Wrap a string in triple backticks for a Markdown block of AppleScript.

    // Example
    alert(strCode.TA_mdCodeBlockAS());

    Returns string

TA_mdCodeBlockJS

  • TA_mdCodeBlockJS(): string
  • TA_mdCodeBlockJS(): string
  • Wrap a string in triple backticks for a Markdown block of JavaScript.

    // Example
    alert(strCode.TA_mdCodeBlockJS());

    Returns string

  • Wrap a string in triple backticks for a Markdown block of shell script.

    // Example
    alert(strCode.TA_mdCodeBlockSH());

    Returns string

TA_mdTitleLinks

  • TA_mdTitleLinks(): string
  • Convert all non-linked URLs as Markdown links using the page name as the title. The function finds URLs in the string and uses the prior two characters to determine if it is part of a Markdown link (preceded by ](), or an HTML source (preceded by ="). If it is not preceded by these, the URL will be used to fetch the page title. That title is then used to build a Markdown link which will replace all occurrences in the string of the URL. Note, each unique URL is only fetched once to ensure that the function runs faster. Returns the updated string.

    // Example
    let strTest = `https://getdrafts.com | [Forum Link]](https://forums.getdrafts.com) | (https://scripting.getdrafts.com) <a href="https://docs.getdrafts.com">Docs</a>`
    alert(strTest.TA_mdTitleLinks());
    // Displays: [Drafts | Where Text Starts](https://getdrafts.com) | [Forum Link]](https://forums.getdrafts.com) | ([Drafts Script Reference](https://scripting.getdrafts.com)) <a href="https://docs.getdrafts.com">Docs</a>

    Returns string

TA_mistypeSlip

  • TA_mistypeSlip(p_intOneIn: number, p_jsonSlipDefinition: JSON, p_strShiftable: string): string
  • Mistype a set of characters in the string based on a statistical likelihood and some data driven rules. The function purposefully messes up the typing in a string by potentially mistyping one in every p_intOneIn characters. The lower that value, the more likely a mistype will be. Mistypable characters are defined by being listed in p_strShiftable. All such characters should then be defined as keys in the JSON object, p_jsonSlipDefinition, each having a value listing the characters it could slip to. The chance of slipping to any of the characters is equal. To increase the likelihood of a character, simply repeat it in the string enough times to appropriately weight it for being chosen at random. A mistyped version of the original string is returned.

    Parameters

    • p_intOneIn: number

      the maxiumum random number used for generating a one in N chance of a character being potentially mistyped.

    • p_jsonSlipDefinition: JSON

      a JSON object with keys for each character that can be mistyped and a string of characters randomly chosen to replace it

    • p_strShiftable: string

      a string listing the characters that can be mistyped.

      // Example
      let strTest = `Alan Aardvary attacked Ada Ant.`;
      let jsonSimple = {};
      jsonSimple.a = "qsssz";
      jsonSimple.t = "rry";
      alert(strTest.TA_mistypeSlip(3, jsonSimple, "at"));
      //Example output: Alsn Sardvsry atracked Ada Ant.

    Returns string

TA_mistypeSlipQWERTY

  • TA_mistypeSlipQWERTY(p_intOneIn: number): string
  • Mistype a set of characters in the string based on a basic QWERTY keyboard. The function purposefully messes up the typing in a string by potentially mistyping one in every p_intOneIn characters. The lower that value, the more likely a mistype will be. A mistyped version of the original string is returned.

    Parameters

    • p_intOneIn: number

      the maxiumum random number used for generating a one in N chance of a character being potentially mistyped.

      // Example
      alert("The quick brown fox jumped over the lazy dog.".TA_mistypeSlipQWERTY(5));
      //Example output: Thw quick briwn fox jumped over the lszt dog.

    Returns string

TA_mistypeSwitch

  • TA_mistypeSwitch(p_intOneIn: number): string
  • Mistype a set of characters in a string by transposing every one in N characters with its previous neighbour in the string. The function purposefully messes up the typing in a string by potentially transposing one in every p_intOneIn characters. The lower that value, the more likely a mistype will be. A mistyped version of the original string is returned.

    Parameters

    • p_intOneIn: number

      the maxiumum random number used for generating a one in N chance of a character being potentially mistyped.

      // Example
      alert("The quick brown fox jumped over the lazy dog.".TA_mistypeSwitch(5));
      //Example output: The quikc bornwf o xujmped voe rth eazlyd og.

    Returns string

TA_overwriteRange0

  • TA_overwriteRange0(p_intStart: number, p_intEnd: number, p_strReplacement: string): string
  • Return the string with the specified 0-based range replaced by the specified replacement text.

    Parameters

    • p_intStart: number

      the position index of the first character in the range to be replaced. The first character is at position 0.

    • p_intEnd: number

      the position index of the last character in the range to be replaced. The first character is at position 0.

    • p_strReplacement: string

      the text to use for the replacement.

      // Example
      alert("123456789".TA_overwriteRange0(3, 5, "qwerty"));
      // Displays "123qwerty789"

    Returns string

TA_overwriteRange1

  • TA_overwriteRange1(p_intStart: number, p_intEnd: number, p_strReplacement: string): string
  • Return the string with the specified 1-based range replaced by the specified replacement text.

    Parameters

    • p_intStart: number

      the position index of the first character in the range to be replaced. The first character is at position 1.

    • p_intEnd: number

      the position index of the last character in the range to be replaced. The first character is at position 1.

    • p_strReplacement: string

      the text to use for the replacement.

      // Example
      alert("123456789".TA_overwriteRange1(3, 5, "qwerty"));
      // Displays "12qwerty6789"

    Returns string

TA_pluralise

  • TA_pluralise(p_intCount: number): string
  • Returns the original text with an "s" on the end when the numeric value passed in is not 1. Useful when passing in a count such that if it is greater than 1 it will add the "s".

    // Example
    alert("foo".TA_pluralise(6));
    // Displays "foos"

    Parameters

    • p_intCount: number

      Number related to the string. Greater than 1 will cause an s to be added to the string.

    Returns string

TA_prependWords

  • TA_prependWords(p_strPrefix: string): string
  • Prefix each word in a string with a string of text.

    Parameters

    • p_strPrefix: string

      the text to prefix each word with.

      // Example
      alert("one, two, and three.".TA_prependWords("**"));
      //Displays "**one, **two, **and **three."

    Returns string

TA_randChar

  • TA_randChar(): string
  • Returns a random character from the string.

    // Example
    let strTest = `qwertyuiopasdfghjklzxcvbnm`;
    alert(strTest.TA_randChar());

    Returns string

TA_regexIndexOf

  • TA_regexIndexOf(p_objRegExMatch: RegExp, p_intStartAt?: number): number
  • Searches the string for the first index of a regular expression based match. Returns the zero-based position in the original string (see p_intStartAt). A return of -1 indicates that the no regular expression match was found.

    Parameters

    • p_objRegExMatch: RegExp

      Regular expression to match against.

    • Optional p_intStartAt: number

      Start position from which to begin searching. Defaults to 0.

      // Example
      alert("lorem sit ipsum sit dolor sit amet sit magna lectus".TA_regexIndexOf(/s(.*)t/,18));
      // Displays "26"

    Returns number

TA_regexLastIndexOf

  • TA_regexLastIndexOf(p_objRegExMatch: RegExp, p_intStartAt?: number): number
  • Searches the string for the last index of a regular expression based match. Returns the zero-based position in the original string (see p_intStartAt). A return of -1 indicates that the no regular expression match was found.

    Parameters

    • p_objRegExMatch: RegExp

      Regular expression to match against.

    • Optional p_intStartAt: number

      Start position from which to begin searching backwards. Defaults to end of string.

      // Example
      alert("lorem sit ipsum sit dolor sit amet sit magna lectus".TA_regexLastIndexOf(/s(.*)t/,20));
      // Displays "16"

    Returns number

TA_removeBlankLines

  • TA_removeBlankLines(): string
  • Removes lines containing no content, or whitespace only. Returns the string stripped of such lines.

    // Example
    strCleaned = strTooManyBlanks.TA_removeBlankLines();

    Returns string

TA_removeEmptyLines

  • TA_removeEmptyLines(): string
  • Removes lines containing no content. Returns the string stripped of such lines.

    // Example
    strCleaned = strWithEmptyLines.TA_removeEmptyLines();

    Returns string

TA_removeLinesContaining

  • TA_removeLinesContaining(p_strMatch: string, p_bCaseSensitive?: Boolean): string
  • Remove lines containing a particular string of text. The text to match for removal is passed in along with an optional case sensitivity option. Returns the resulting text.

    Parameters

    • p_strMatch: string

      the string when found in a line constitutes a match for removal.

    • Optional p_bCaseSensitive: Boolean

      when true (the default), text matches will be case sensitive, and when false, the matches will be case insensitive.

      // Example
      let strLines = `apple starts line one
      line two ends with apple
      line three has apple in it
      there are no fruits in line four
      line five has an apple in it
      line six ends with apple
      apple starts line seven
      there are no fruits in line eight`;
      
      app.setClipboard("LINES NOT CONTAINING\n\n" + strLines.TA_removeLinesContaining("apple"));
      // Displays the following:
      // LINES NOT CONTAINING
      //
      // there are no fruits in line four
      // there are no fruits in line eight

    Returns string

TA_removeLinesEnding

  • TA_removeLinesEnding(p_strMatch: string, p_bCaseSensitive?: Boolean): string
  • Remove lines ending with a particular string of text. The text to match for removal is passed in along with an optional case sensitivity option. Returns the resulting text.

    Parameters

    • p_strMatch: string

      the string when found at the end of a line constitutes a match for removal.

    • Optional p_bCaseSensitive: Boolean

      when true (the default), text matches will be case sensitive, and when false, the matches will be case insensitive.

      // Example
      let strLines = `apple starts line one
      line two ends with apple
      line three has apple in it
      there are no fruits in line four
      line five has an apple in it
      line six ends with apple
      apple starts line seven
      there are no fruits in line eight`;
      
      app.setClipboard("LINES NOT ENDING\n\n" + strLines.TA_removeLinesEnding("apple"));
      // Displays the following:
      // LINES NOT ENDING
      //
      // apple starts line one
      // line three has apple in it
      // there are no fruits in line four
      // line five has an apple in it
      // apple starts line seven
      // there are no fruits in line eight

    Returns string

TA_removeLinesNotEnding

  • TA_removeLinesNotEnding(p_strMatch: string, p_bCaseSensitive?: Boolean): string
  • Remove lines not ending with a particular string of text. The text to match for keeping is passed in along with an optional case sensitivity option. Returns the resulting text.

    Parameters

    • p_strMatch: string

      the string when found at the end of a line constitutes a match for keeping.

    • Optional p_bCaseSensitive: Boolean

      when true (the default), text matches will be case sensitive, and when false, the matches will be case insensitive.

      // Example
      let strLines = `apple starts line one
      line two ends with apple
      line three has apple in it
      there are no fruits in line four
      line five has an apple in it
      line six ends with apple
      apple starts line seven
      there are no fruits in line eight`;
      
      app.setClipboard("LINES ENDING\n\n" + strLines.TA_removeLinesNotEnding("apple"));
      // Displays the following:
      // LINES ENDING
      //
      // line two ends with apple
      // line six ends with apple
      //

      Note the blank line at the end is simply because line 6 includes a newline character at the end

    Returns string

TA_removeLinesNotStarting

  • TA_removeLinesNotStarting(p_strMatch: string, p_bCaseSensitive?: Boolean): string
  • Remove lines not starting with a particular string of text. The text to match for keeping is passed in along with an optional case sensitivity option. Returns the resulting text.

    Parameters

    • p_strMatch: string

      the string when found at the start of a line constitutes a match for keeping.

    • Optional p_bCaseSensitive: Boolean

      when true (the default), text matches will be case sensitive, and when false, the matches will be case insensitive.

      // Example
      let strLines = `apple starts line one
      line two ends with apple
      line three has apple in it
      there are no fruits in line four
      line five has an apple in it
      line six ends with apple
      apple starts line seven
      there are no fruits in line eight`;
      
      app.setClipboard("LINES STARTING\n\n" + strLines.TA_removeLinesNotStarting("apple"));
      // Displays the following:
      // LINES STARTING
      //
      // apple starts line one
      // apple starts line seven
      //

      Note the blank line at the end is simply because line 7 includes a newline character at the end

    Returns string

TA_removeLinesStarting

  • TA_removeLinesStarting(p_strMatch: string, p_bCaseSensitive?: Boolean): string
  • Remove lines starting with a particular string of text. The text to match for removal is passed in along with an optional case sensitivity option. Returns the resulting text.

    Parameters

    • p_strMatch: string

      the string when found at the start of a line constitutes a match for removal.

    • Optional p_bCaseSensitive: Boolean

      when true (the default), text matches will be case sensitive, and when false, the matches will be case insensitive.

      // Example
      let strLines = `apple starts line one
      line two ends with apple
      line three has apple in it
      there are no fruits in line four
      line five has an apple in it
      line six ends with apple
      apple starts line seven
      there are no fruits in line eight`;
      
      alert("LINES NOT STARTING\n\n" + strLines.TA_removeLinesStarting("apple"));
      // Displays the following:
      // LINES NOT STARTING
      //
      // line two ends with apple
      // line three has apple in it
      // there are no fruits in line four
      // line five has an apple in it
      // line six ends with apple
      // there are no fruits in line eight

    Returns string

TA_removeMDHeader

  • TA_removeMDHeader(): string
  • Removes any leading Markdown heading string from the start of a line in a string. Markdown expects a space to occur between the octothorpes and the title. This function also expects that. However, if there is a space at the start and no octothorpes, that space will be retaind - i.e. it matches on at least one octothorpe at the start. This is repeated for each line in the string. Returns the string with any leaading Markdown header removed.

    // Example
    alert(">" + "### Hello World".TA_removeMDHeader());
    // Displays: >Hello World

    Returns string

TA_removeSpaceTabLeading

  • TA_removeSpaceTabLeading(): string
  • Removes leading spaces and tabs from the lines of the string. Lines containing only spaces and tabs remain as empty lines. Initially empty lines remain unaffected. Returns the string stripped of such content.

    // Example
    strCleaned = strWithLeading.TA_removeSpaceTabLeading();

    Returns string

TA_removeSpaceTabLeadingTrailing

  • TA_removeSpaceTabLeadingTrailing(): string
  • Removes leading and trailing spaces and tabs from the lines of the string. Lines containing only spaces and tabs remain as empty lines. Initially empty lines remain unaffected. Returns the string stripped of such content.

    // Example
    strCleaned = strWithLeadingAndTrailing.TA_removeSpaceTabLeadingTrailing();

    Returns string

TA_removeSpaceTabTrailing

  • TA_removeSpaceTabTrailing(): string
  • Removes trailing spaces and tabs from the lines of the string. Lines containing only spaces and tabs remain as empty lines. Initially empty lines remain unaffected. Returns the string stripped of such content.

    // Example
    strCleaned = strWithTrailing.TA_removeSpaceTabTrailing();

    Returns string

TA_removeTrailingNewlines

  • TA_removeTrailingNewlines(): string
  • Removes any number of new line characters from the end of the string.

    ```javascript // Example let strLines = ` foo bar

    `; alert(">" + strLines.TA_removeTrailingNewlines() + "<"); // Displays the following: // > // foo // bar<

    Returns string

TA_removeWhitespaceLeading

  • TA_removeWhitespaceLeading(): string
  • Removes leading whitespace from the lines of the string. Empty and lines only containing whitespace are removed. Returns the string stripped of such content.

    // Example
    strCleaned = strWithLeadingWhitespace.TA_removeWhitespaceLeading();

    Returns string

TA_removeWhitespaceTrailing

  • TA_removeWhitespaceTrailing(): string
  • TA_removeWhitespaceTrailing(): string
  • Removes trailing whitespace from the lines of the string. Empty and lines only containing whitespace are removed. Returns the string stripped of such content.

    // Example
    strCleaned = strWithTrailingWhitespace.TA_removeWhitespaceTrailing();

    Returns string

  • Removes leading and trailing whitespace from the lines of the string. Empty and lines only containing whitespace are removed. Returns the string stripped of such content.

    // Example
    strCleaned = strWithWhitespace.TA_removeWhitespaceLeadingTrailing();

    Returns string

TA_replaceAllMap

  • TA_replaceAllMap(p_objReplace: JSON): string
  • Replace all text matching keys with values from the object map passed in. This function takes each key from the passed in object, searches for it in the string, and then replaces each occurrence with the value of that key.

    Parameters

    • p_objReplace: JSON

      object with named properties (key:value) that define each piece of text to find and what to replace it with.

      // Example
      alert("I have a lot of foo, and with that foo I also have some bar.".TA_replaceAllMap({"foo" : "quz", "bar" : "qux"}));
      // Displays "I have a lot of quz, and with that quz I also have some qux."

    Returns string

TA_startsWithRemove

  • TA_startsWithRemove(p_strStartsWith: string): string
  • If a string starts with a specific sub string, this returns the string with that part removed. The original string is otherwise returned unchanged.

    Parameters

    • p_strStartsWith: string

      the sub string to remove from the start of the string if it matches.

      // Example
      alert(`abcd`.TA_startsWithRemove("ab");
      // Displays: cd

    Returns string

TA_stripFinalNewLine

  • TA_stripFinalNewLine(): string
  • Strip any trailing new line from the string. The resulting string is returned.

    // Example
    let strURL = "foo\nbar\n";
    alert(strURL.TA_stripFinalNewLine());
    //Displays "foo\nbar"

    Returns string

TA_tail

  • TA_tail(): string
  • Returns second and subsequent characters of the string.

    // Example
    alert("foo bar".TA_tail());
    // Displays "oo bar"

    Returns string

TA_toCamelCase

  • TA_toCamelCase(): string
  • Normalises (NFC mode) and convert the string to Camel case. Camel case capitalises each word (others being lower cased) other than the first, which is all lower case, and removes spaces

    // Example
    alert("FOO bAr".TA_toCamelCase());
    // Displays "fooBar"

    Returns string

TA_toKebabCase

  • TA_toKebabCase(): string
  • Normalises (NFC mode) and convert the string to Kebab case. Kebab case lower cases each character and substitutes hyphens for spaces

    // Example
    alert("FOO bAr".TA_toKebabCase());
    // Displays "foo-bar"

    Returns string

TA_toLowerCase

  • TA_toLowerCase(): string
  • Normalises (NFC mode) and lower cases the string.

    // Example
    alert("Foo Bar".TA_toLowerCase());
    // Displays "foo bar"

    Returns string

TA_toPascalCase

  • TA_toPascalCase(): string
  • Normalises (NFC mode) and convert the string to Pascal case. Pascal case capitalises each word (others being lower cased), and removes spaces

    // Example
    alert("foo bAr".TA_toPascalCase());
    // Displays "FooBar"

    Returns string

TA_toScreamingSnakeCase

  • TA_toScreamingSnakeCase(): string
  • Normalises (NFC mode) and convert the string to Screaming Snake case. Screaming snake case upper cases each character and substitutes underscores for spaces

    // Example
    alert("FOO bAr".TA_toSnakeCase());
    // Displays "FOO_BAR"

    Returns string

TA_toSentenceCase

  • TA_toSentenceCase(): string
  • Normalises (NFC mode) and convert the string to sentence case.

    // Example
    alert("foo Bar".TA_toSentenceCase());
    // Displays "Foo bar"

    Returns string

TA_toSnakeCase

  • TA_toSnakeCase(): string
  • Normalises (NFC mode) and convert the string to Snake case. Snake case lower cases each character and substitutes underscores for spaces

    // Example
    alert("FOO bAr".TA_toSnakeCase());
    // Displays "foo_bar"

    Returns string

TA_toTitleCase

  • TA_toTitleCase(): string
  • Normalises (NFC mode) and converts a string to title case Please notes that this function is a slightly modified version of To Title Case 2.1

    // Example
    alert("foobar the QUZ qux".TA_toTitleCase());
    // Displays "Foobar the QUZ Qux"

    Related Copyright Information

    To Title Case 2.1 – http://individed.com/code/to-title-case/
    Copyright © 20082013 David Gouch. Licensed under the MIT License.

    Returns string

TA_toTrainCase

  • TA_toTrainCase(): string
  • Normalises (NFC mode) and convert the string to Train case. Train case upper cases each character and substitutes hyphens for spaces

    // Example
    alert("FOO bAr".TA_toTrainCase());
    // Displays "FOO-BAR"

    Returns string

TA_toUpperCase

  • TA_toUpperCase(): string
  • Normalises (NFC mode) and upper cases the string.

    // Example
    alert("Foo Bar".TA_toUpperCase());
    // Displays "FOO BAR"

    Returns string

TA_trimToSnippet

  • TA_trimToSnippet(p_intLength: number): string
  • Returns up to a fixed length of the string, and if the string exceeds, last character will be an ellipsis.

    Parameters

    • p_intLength: number

      the maximum length of the string to be returned.

      // Example
      let strTest = `123456789①123456789②123456789③`;
      alert(strTest.TA_trimToSnippet(23));
      // Displays: 123456789①123456789②12…

    Returns string

TA_wrapWords

  • TA_wrapWords(p_strPrefix: string, p_strSuffix: string): string
  • Prefix and suffix each word in a string with strings of text.

    Parameters

    • p_strPrefix: string

      the text to prefix each word with.

    • p_strSuffix: string

      the text to suffix each word with.

      // Example
      alert("one, two, and three.".TA_wrapWords("<", ">"));
      //Displays "<one>, <two>, <and> <three>."

    Returns string