Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TadMiscellaneous

TadMiscellaneous (Library)

This is a class that gathers together a number of miscellaneous library functions.

Hierarchy

  • TadMiscellaneous

Index

Constructors

constructor

  • Creates new instance of TadMiscellaneous class.

    Returns TadMiscellaneous

Methods

TA_JSONArraySorter

  • TA_JSONArraySorter(p_strProperty: string): JSON[]
  • JSON array comparator function for sorting based on a root property of each array item. Each array element's JSON attribute is compared for sorting.

    // Example
    astrBooks = [];
    astrBooks.push({"author" : "Harper Lee", "title" : "To Kill a Mockingbird"});
    astrBooks.push({"author" : "Miguel de Cervantes", "title" : "Don Quixote"});
    astrBooks.push({"author" : "James Joyce", "title" : "Ulysses"});
    astrBooks.sort(tadMisc.TA_JSONArraySorter("title"));
    

    Parameters

    • p_strProperty: string

    Returns JSON[]

TA_actionGroupLink

  • TA_actionGroupLink(p_strActionGroupLink: URL, p_bActions: Boolean, p_bSeparators: Boolean): string[]
  • Converts action group install link to an array of action names and/or separators. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group. The function can extract both the actions and separators, just one, or technically neither, as an array of action/separator names.

    Direct installation URLs begin drafts5://actionGroup?data=.

    Parameters

    • p_strActionGroupLink: URL

      the direct installation URL for an action group.

    • p_bActions: Boolean

      will return action names in the returned array when set to true; defaults to true.

    • p_bSeparators: Boolean

      will return separator names in the returned array when set to true; defaults to false.

      // Example
      // With the action group link copied to the application clipboard, return a list of actions into a variable.
      let astrActionNames = tadMisc.TA_actionGroupLink(app.clipboard(), true, false);
      

    Returns string[]

TA_actionGroupLinkDocument

  • TA_actionGroupLinkDocument(p_strActionGroupLink: string): Draft
  • Converts action group install link to a Markdown draft of basic documentation about the action group. The draft is automatically loaded into the editor. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group.

    Direct installation URLs begin drafts5://actionGroup?data=. Returns the draft created

    Parameters

    • p_strActionGroupLink: string

      the direct installation URL for an action group.

      // Example
      // With the action group link copied to the application clipboard, generate a report.
      tadMisc.TA_actionGroupLinkDocument(app.clipboard());
      

    Returns Draft

TA_actionGroupLinkToActions

  • TA_actionGroupLinkToActions(p_strActionGroupLink: string): string[]
  • Converts action group install link to an array of action names. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group.

    Direct installation URLs begin drafts5://actionGroup?data=.

    Parameters

    • p_strActionGroupLink: string

      the direct installation URL for an action group.

      // Example
      // With the action group link copied to the application clipboard, return a list of actions into a variable.
      let astrActionNames = tadMisc.TA_actionGroupLinkToActions(app.clipboard());
      

    Returns string[]

TA_actionGroupLinkToActionsCount

  • TA_actionGroupLinkToActionsCount(p_strActionGroupLink: string): string[]
  • Converts action group install link to a count of action names. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group.

    Direct installation URLs begin drafts5://actionGroup?data=.

    Parameters

    • p_strActionGroupLink: string

      the direct installation URL for an action group.

      // Example
      // With the action group link copied to the application clipboard, return a list of actions into a variable.
      alert(tadMisc.TA_actionGroupLinkToActionsCount(app.clipboard());
      

    Returns string[]

TA_actionGroupLinkToList

  • TA_actionGroupLinkToList(p_strActionGroupLink: string): string[]
  • Converts action group install link to an array of action and separator names. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group.

    Direct installation URLs begin drafts5://actionGroup?data=.

    Parameters

    • p_strActionGroupLink: string

      the direct installation URL for an action group.

      // Example
      // With the action group link copied to the application clipboard, return a list of actions and separators into a variable.
      let astrNames = tadMisc.TA_actionGroupLinkToList(app.clipboard());
      

    Returns string[]

TA_actionGroupLinkToListCount

  • TA_actionGroupLinkToListCount(p_strActionGroupLink: string): string[]
  • Converts action group install link to a count of action and separator names. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group.

    Direct installation URLs begin drafts5://actionGroup?data=.

    Parameters

    • p_strActionGroupLink: string

      the direct installation URL for an action group.

      // Example
      // With the action group link copied to the application clipboard, return a list of actions and separators into a variable.
      alert(tadMisc.TA_actionGroupLinkToListCount(app.clipboard()));
      

    Returns string[]

TA_actionGroupLinkToSeparators

  • TA_actionGroupLinkToSeparators(p_strActionGroupLink: string): string[]
  • Converts action group install link to an array of separator names. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group.

    Direct installation URLs begin drafts5://actionGroup?data=.

    Parameters

    • p_strActionGroupLink: string

      the direct installation URL for an action group.

      // Example
      // With the action group link copied to the application clipboard, return a list of separators into a variable.
      let astrSeparatorNames = tadMisc.TA_actionGroupLinkToSeparators(app.clipboard());
      

    Returns string[]

TA_actionGroupLinkToSeparatorsCount

  • TA_actionGroupLinkToSeparatorsCount(p_strActionGroupLink: string): string[]
  • Converts action group install link to a count of separator names. The function uses the encoded link URL (not the link to a download page on the Action Directory) to decode the contents of the action group.

    Direct installation URLs begin drafts5://actionGroup?data=.

    Parameters

    • p_strActionGroupLink: string

      the direct installation URL for an action group.

      // Example
      // With the action group link copied to the application clipboard, return a list of separators into a variable.
      alert(tadMisc.TA_actionGroupLinkToSeparatorsCount(app.clipboard()));
      

    Returns string[]

TA_actionKeys

  • TA_actionKeys(p_jsonKey: JSON): Draft
  • Return the keyboard shortcut for an action as a string.

    Parameters

    • p_jsonKey: JSON

      the JSON that defines the keyboard shortcut for an action.

      // Example
      alert(tadMisc.TA_actionKeys(actionMain.keyCommand));
      

    Returns Draft

TA_actionLevelDescription

  • TA_actionLevelDescription(p_intLevel: number): Draft
  • Return the descriptor for an action level. Descriptors apply to notification level and log level as follows:

    1. None.
    2. Errors.
    3. All.

    Parameters

    • p_intLevel: number

      the level of the notification or logging.

      // Example
      alert(tadMisc.TA_actionLevelDescription(actionMain.notificationType));
      

    Returns Draft

TA_addEncodedImages

  • TA_addEncodedImages(p_strHTMLContent: string): string
  • Transform local HTML image links to use pre-encoded Base 64 data URLs. The function scans the HTML content it receives for src attributes (like those used in img tags) that are not specified by an HTTP/HTTPS protocol. Such sources are taken to be local. The function then attempts to locate a Base64 encoded file for the resource specified. The convention is that such files will be co-located at the path of the original resource, but will have an additional suffix to the resource file path of .b64.txt. If the file exists, the content will be transcluded into the source as a suitably structured base 64 source string. Such embedded images can then be rendered into a preview from a local source without the requirement of running a web server alongside.

    Unfortunately, Drafts does not include the file access functionality to process image files and encode them to Base64. However, on the Mac, this is easily achieved from the command line, and on the iPhone and iPad, this can be accomplished using the Shortcuts application. Pre-processing the files also means that time should be saved on each preview run. Utilities to support this are available on the ThoughtAsylum web site.

    Note:
    Originally this function was written to process Markdown links, but the Markdown to HTML transformation engines kept converting embedded HTML content to literals. It proved to be easier, and more reliable, to simply process the resulting HTML instead.

    Parameters

    • p_strHTMLContent: string

      the content string to be scanned for wiki-style links.

      // Example
      alert(tadMisc.TA_addEncodedImages(strHTML));
      

    Returns string

TA_decimalSeparator

  • TA_decimalSeparator(): string
  • Return the decimal separator in use by the operating system. e.g. "." for UK, "," for France

    // Example
    alert(tadMisc.TA_decimalSeparator());
    

    Returns string

TA_definition

  • TA_definition(p_strText: string): void
  • Returns a set of definitions for a specified word (English). This function utilises the datamuse.com API.

    Parameters

    • p_strText: string

      text to lookup the definition for.

      // Example
      tadMisc.TA_definition("draft");
      

    Returns void

TA_definitionDisplay

  • TA_definitionDisplay(p_strText: string): void
  • Displays a set of definitions for a specified word (English). This function utilises the datamuse.com API.

    Parameters

    • p_strText: string

      text to lookup the definition for.

      // Example
      tadMisc.TA_definitionDisplay("draft");
      

    Returns void

TA_definitionOfSelected

  • TA_definitionOfSelected(): void
  • Displays a set of definitions for a selected word (English), or prompts the user for the word to lookup if none is selected. This function utilises the datamuse.com API.

    // Example
    tadMisc.TA_definitionOfSelected();
    

    Returns void

TA_devBeautifyJSDraft

  • TA_devBeautifyJSDraft(): string
  • Reformat the JavaScript content of the current draft. This uses a version of the js-beautifier library. It's a little outdated, but functional for now and may be updated in the future to work with a newer library. Provision has been made for this via the library settings which hold an update location for the library. Default setings will be used unless a JSON file is present (name specified by beautifierSettings library property) in the /Library/Scripts folder in Drafts. If present, those settings will be passed to the beautification function. The default settings are available on GitHub for the js-beautifier information, and en example alternative configuration is shown below. Please note that this function should only be run on drafts containing JavaScript. If this function is run on non-JavaScript, then the results could well be rather unexpected. As well as changing the content of the current draft, the content is also returned by the function.

    {
        "indent_size" : 1,
        "indent_char" : "\t",
        "indent_with_tabs" : true,
        "eol" : "\n",
        "end_with_newline" : false,
        "indent_level" : 0,
        "preserve_newlines" : true,
        "max_preserve_newlines" : 10,
        "space_in_paren" : false,
        "space_in_empty_paren" : false,
        "jslint_happy" : false,
        "space_after_anon_function" : false,
        "brace_style" : "expand",
        "unindent_chained_methods" : false,
        "break_chained_methods" : false,
        "keep_array_indentation" : false,
        "unescape_strings" : false,
        "wrap_line_length" : 0,
        "e4x" : false,
        "comma_first" : false,
        "operator_position" : "before-newline",
        "eval_code" : false,
        "space_before_conditional" : true
        }
    

    // Example
    tadMisc.TA_devBeautifyJSDraft();
    

    Returns string

TA_devExecuteRunCurrentDraft

  • TA_devExecuteRunCurrentDraft(): void
  • Execute the content of the current draft as evaluated JavaScript.

    // Example
    tadMisc.TA_devExecuteRunCurrentDraft();
    

    Returns void

TA_devExecuteRunDraft

  • TA_devExecuteRunDraft(): void
  • Execute the contents of the most recently modified draft configured for execution into the editor. Execution is determined by the presence of a tag matching the library property runTag, and located in the folder specified by runArea.

    // Example
    tadMisc.TA_devExecuteRunDraft();
    

    Returns void

TA_devExecuteRunSelectedLines

  • TA_devExecuteRunSelectedLines(): void
  • Execute the currently selected lines as evaluated JavaScript.

    // Example
    tadMisc.TA_devExecuteRunSelectedLines();
    

    Returns void

TA_devExecuteRunSelection

  • TA_devExecuteRunSelection(): void
  • Execute the current text selection as evaluated JavaScript.

    // Example
    tadMisc.TA_devExecuteRunSelection();
    

    Returns void

TA_devLoadRunDraft

  • TA_devLoadRunDraft(): string
  • Load the most recently modified draft configured for execution into the editor. Execution is determined by the presence of a tag matching the library property runTag, and located in the folder specified by runArea. Returns the UUID of the draft.

    // Example
    tadMisc.TA_devLoadRunDraft();
    

    Returns string

TA_devSetRunDraft

  • TA_devSetRunDraft(): string
  • Set the currently loaded draft for execution. Execution is determined by the presence of a tag matching the library property runTag, and located in the folder specified by runArea. Please note that this function will not set folder, and it is enouraged that scripts for execution are kept in the inbox folder to support ease of creation. The function will set the draft with the required syntax and additional script tag as specified by the runSyntax and runTagScript library properties. Returns the UUID of the draft.

    // Example
    tadMisc.TA_devSetRunDraft();
    

    Returns string

TA_fixPoorDiscourseJavaScriptOnClipboard

  • TA_fixPoorDiscourseJavaScriptOnClipboard(): void
  • Take poorly formatted Discourse JavaScript on the clipboard and fix it on the clipboard. If JavaScript code is posted on a Discourse forum outside of a code block, it will introduce smart quotes and lose formatting. This function will replace smart quotes (all of them, so if the code used them purposefully this needs a manual fix) and apply a JavaScript Beautification function to format the code. The function updates the clipboard with the reformatted code.

    // Example
    tadMisc.TA_fixPoorDiscourseJavaScriptOnClipboard();
    

    Returns void

TA_getTimestampyyyyMMddhhmmss

  • TA_getTimestampyyyyMMddhhmmss(): string
  • Creates a timestamp for this moment. The general format is yyyyMMddhhmmss, but it also includes separators (which could be set to empty strings). The tadLib.separatorDateStamp is inserted after yyyy and MM. The tadLib.separatorDateTimeStamp is inserted after dd. The tadLib.separatorTimeStamp is inserted after hh and mm. The resulting timestamp string is returned.

    // Example
    alert(tadMisc.TA_getTimestampyyyyMMddhhmmss());
    

    Returns string

TA_getTimestampyyyyMMddhhmmssxxx

  • TA_getTimestampyyyyMMddhhmmssxxx(): string
  • Creates a timestamp for this moment. The general format is yyyyMMddhhmmssxxx, but it also includes separators (which could be set to empty strings). The tadLib.separatorDateStamp is inserted after yyyy and MM. The tadLib.separatorDateTimeStamp is inserted after dd. The tadLib.separatorTimeStamp is inserted after hh, mm and ss. The resulting timestamp string is returned.

    // Example
    alert(tadMisc.TA_getTimestampyyyyMMddhhmmssxxx());
    

    Returns string

TA_logToDraft

  • TA_logToDraft(p_strUUID: string, p_strTextToLog: string, p_strMode?: string, p_strPrefix?: string, p_strSuffix?: string, p_strDTFormat?: string): string
  • Generic logging function. Allows a variety of ways to "log" text to a draft. This can be by passing text in or triggering a dictation. The text can be appended to the end of a draft, prefixed to the start, or simply inserted at the current cursor position in the draft being edited. A date/time stamp can also be included along with any text-based prefix/suffix you wish. Returns the text being logged (including any date/time stamp, prefix and suffix);

    Parameters

    • p_strUUID: string

      the unique ID of the draft to log to.

    • p_strTextToLog: string

      the text to log. If empty, this will trigger a dictation.

    • Optional p_strMode: string

      the mode (prepend, cursor, append) to determine whether to prepend the log to the start, place at the cursor position of the current draft, or append to the end of the draft. Defaults to append.

    • Optional p_strPrefix: string

      the text to include before the passed in or dictated text. Defaults to an empty string.

    • Optional p_strSuffix: string

      the text to include after the passed in or dictated text. Defaults to an empty string.

    • Optional p_strDTFormat: string

      the strftime format string to determine the format of the date/time. If an empty string, no date time will be included. Defaults to being en empty string.

      // Example
      tadMisc.TA_logToDraft("DC2B3FBB-CD9E-4B98-B10B-0D4311735C58", "Carried out code check.", "append", " - ", "\n\n", "%Y-%m-%d-%H.%M.%S");
      

    Returns string

TA_logToDraftCurrent

  • TA_logToDraftCurrent(p_strTextToLog: string, p_strMode?: string, p_strPrefix?: string, p_strSuffix?: string, p_strDTFormat?: string): string
  • Generic logging function for the currently edited draft. Allows a variety of ways to "log" text to a draft. This can be by passing text in or triggering a dictation. The text can be appended to the end of the draft, prefixed to the start, or simply inserted at the current cursor position. A date/time stamp can also be included along with any text-based prefix/suffix you wish. Returns the text being logged (including any date/time stamp, prefix and suffix);

    Parameters

    • p_strTextToLog: string

      the text to log. If empty, this will trigger a dictation.

    • Optional p_strMode: string

      the mode (prepend, cursor, append) to determine whether to prepend the log to the start, place at the cursor position of the current draft, or append to the end of the draft. Defaults to append.

    • Optional p_strPrefix: string

      the text to include before the passed in or dictated text. Defaults to an empty string.

    • Optional p_strSuffix: string

      the text to include after the passed in or dictated text. Defaults to an empty string.

    • Optional p_strDTFormat: string

      the strftime format string to determine the format of the date/time. If an empty string, no date time will be included. Defaults to being en empty string.

      // Example
      tadMisc.TA_logToDraftCurrent("Carried out code sanitisation.", "prepend", " ยป ", "\n\n", "%Y-%m-%d-%H.%M.");
      

    Returns string

TA_ordinalDay

  • TA_ordinalDay(p_intNumber: number): string
  • Return the ordinal term for a day of the month. e.g. 3 => 'third'. Fractional parts of any index number passed to the function are dropped, not rounded. The function will return the ordinal value for any number between 1 and 31 inclusive. Indicies outside this range will have their numeric value returned (as a string).

    Parameters

    • p_intNumber: number

      the day of the month to return the ordinal term for.

      // Example
      alert(tadMisc.TA_ordinalDay(4));
      //Displays "fourth"
      

    Returns string

TA_playSoundPath

  • TA_playSoundPath(p_strSoundFilePath: string): Boolean
  • TA_playSoundPath(p_strSoundB64: string): Boolean
  • Play a local sound file using a shell script call. This function will only work on the Mac because it relies on a shell script. Returns true if executed successfully, otherwise false.

    Parameters

    • p_strSoundFilePath: string

      the path to the audio file to play.

      // Example
      tadMisc.TA_playSoundPath("/System/Library/Sounds/Purr.aiff");
      

    Returns Boolean

  • Play MP3 audio encoded in base64. This function will only work on the Mac because iOS and iPadOS do not support auto play of Audio in Safari view controllers, which is what is used to playback the audio. Returns false if the prompt window was cancelled, otherwise true.

    Parameters

    • p_strSoundB64: string

      the string of base64 encoded MP3 data.

      // Example
      let objHTTP = HTTP.create();
      let strAudio = objHTTP.TA_getContent("https://gist.githubusercontent.com/sylumer/ec77169034aa7ffd9b75b88e3af4ad49/raw/d138ba1908503e7b8805f4e6fed49441d541f64b/MP3_Audio_Example_B64.txt");
      tadMisc.TA_playMP3Data(strAudio);
      

    Returns Boolean

TA_random128BitKey

  • TA_random128BitKey(): string
  • Return a random string of 32 hexadecimal characters; a 128-bit key. The string of hexadecimal characters is generated by random.org who generate truly random numbers. This function utilises random.org for generation of the key.

    // Example
    alert(tadMisc.TA_random128BitKey());
    

    Returns string

TA_random192BitKey

  • TA_random192BitKey(): string
  • Return a random string of 48 hexadecimal characters; a 192-bit key. The string of hexadecimal characters is generated by random.org who generate truly random numbers. This function utilises random.org for generation of the key.

    // Example
    alert(tadMisc.TA_random192BitKey());
    

    Returns string

TA_random256BitKey

  • TA_random256BitKey(): string
  • Return a random string of 64 hexadecimal characters; a 256-bit key. The string of hexadecimal characters is generated by random.org who generate truly random numbers. This function utilises random.org for generation of the key.

    // Example
    alert(tadMisc.TA_random256BitKey());
    

    Returns string

TA_randomInteger

  • TA_randomInteger(p_intNumberOfIntegers: number, p_intMin: number, p_intMax: number, p_intBase?: number, p_bHTML?: Boolean, p_strMethod?: string): string
  • Return a random integer generated by random.org. The function will fetch a set of integers as specified by the parameters, the (API) maximum integer size being +/- 1e9. The integers are then concatenated to make a single string of integer characters. If you cannot generate a large enough integer in one result, you should simply generate that many single digits. The function/API will accommodate up to 10,000 digits byt doing that. The function allws you to specify what base (2,8, 10 or 16) to generate the output in, but for convenience, the default is set to decimal. The function also has options for output type and generation method, but unless you have very specific needs, these should be left as the default values.

    random.org generate truly random numbers, not pseudo-random numbers. They provide an API on which this function is based. The function should be suitable for personal purposes of creating truly random numbers, but please note that random.org apply an IP address-based quota restruction on the generation of random content. The quote is very generous, but if you try to use this function for mass generation, then you are likely to hit the quote limit.

    Parameters

    • p_intNumberOfIntegers: number

      the number of integers to generate. This can be specified in the range of 1 to 1e4.

    • p_intMin: number

      the smallest integer (as a decimal) to generate. This can be specified in the range of +/- 1e9.

    • p_intMax: number

      the largest integer (as a decimal) to generate. This can be specified in the range of +/- 1e9.

    • Optional p_intBase: number

      this can be set to 2 to generate binary numbers, 8 to generate octal numbers, 10, to generate decimal numbers (the default), and 16 to generate hexadecimal numbers.

    • Optional p_bHTML: Boolean

      when true, the output will be HTML. When false, the output will be plain text. The default is false.

    • Optional p_strMethod: string

      this is set to new by default, but other options are available - please see the API integer generation documentation for details.

      // Examples
      //Display a 9 digit, decimal number
      alert(tadMisc.TA_randomInteger(1, 0, 999999999));
      
      //Display a 50 digit, hexadecimal number
      alert(tadMisc.TA_randomInteger(50, 0, 15, 16));
      

    Returns string

TA_randomStrings

  • TA_randomStrings(p_intNumberOfStrings: number, p_intStringLength: number, p_bAllowDigits?: Boolean, p_bAllowUpperCase?: Boolean, p_bAllowLowerCase?: Boolean, p_bUnique?: Boolean, p_bHTML?: Boolean, p_strMethod?: string): string
  • Return a string of random characters generated by random.org The function will fetch a set of sub-strings as specified by the parameters, the (API) maximum length of a sub-string being 20 characters. The sub-strings are then concatenated to make a single string. If you require a prime number of characters in excess of 20, you will need to truncate the resulting string. The function allows character inclusion options to be set. These include being able to include/exclude numerical digits, being able to include/ exclude upper case characters, and being able to include/exclude lower case characters. Accented characters and symbols will not be generated by this function. The function also has an option to ensure that every sub-string is unique, though since this function is intended to generate a single combined result, this should generally have no reason to be changed from the default, but is included in case you wich to decompose the resulting string back to the individual sub-strings. The function also has options for output type and generation method, but again, unless you have very specific needs, these should be left as the default values.

    random.org generate truly random numbers, not pseudo-random numbers. They provide an API on which this function is based. The function should be suitable for personal purposes of creating truly random characters, but please note that random.org apply an IP address-based quota restruction on the generation of random content. The quote is very generous, but if you try to use this function for mass generation, then you are likely to hit the quote limit.

    Parameters

    • p_intNumberOfStrings: number

      the number of sub-strings to generate.

    • p_intStringLength: number

      the length of the sub-strings to be generated : between 1 and 20 characters inclusive.

    • Optional p_bAllowDigits: Boolean

      when true, the string may contain numeric digits, when false, it will not. The default is true.

    • Optional p_bAllowUpperCase: Boolean

      when true, the string may contain upper case alphabetic characters, when false, it will not. The default is true.

    • Optional p_bAllowLowerCase: Boolean
    • Optional p_bUnique: Boolean

      when true, the generated sub-strings will be unique. The default is false.

    • Optional p_bHTML: Boolean

      when true, the output will be HTML. When false, the output will be plain text. The default is false.

    • Optional p_strMethod: string

      this is set to new by default, but other options are available - please see the API string generation documentation for details.

      // Example
      //Display a 100 character string
      alert(tadMisc.TA_randomStrings(5, 20));
      

    Returns string

TA_randomorgQuotaCheck

  • TA_randomorgQuotaCheck(): string
  • Returns the remaining API quota in bits for the current IP address from random.org. For further quota details, please see random.org's API quota information.

    // Example
    alert(tadMisc.TA_randomorgQuotaCheck());
    

    Returns string

TA_repeatEvaluation

  • TA_repeatEvaluation(p_strToEvaluate: string, p_intTimes: number): void
  • Evaluate a string of JavaScript several times.

    Parameters

    • p_strToEvaluate: string

      the JavaScript to be evaluated;

    • p_intTimes: number

      the number of times to evaluate the JavaScript;

      // Example
      let intTemp = 2;
      tadMisc.TA_repeatEvaluation('intTemp = intTemp * intTemp;', 6);
      alert(intTemp);
      

    Returns void

TA_sleep

  • TA_sleep(p_intSecs: number): void
  • Pause doing anything else until a specified number of seconds has elapsed. This should only be used for delays where precise timing is not required, and is really just a convenience function for TA_sleepMS.

    Parameters

    • p_intSecs: number

      the number of seconds to pause for.

      // Example
      alert("Go to sleep when you select dismiss.")
      tadMisc.TA_sleep(4.5);
      alert("Approximately 4.5 seconds have elapsed since you dismissed the previous alert.")
      

    Returns void

TA_sleepMS

  • TA_sleepMS(p_intms: number): void
  • Pause doing anything else until a specified number of milliseconds has elapsed. While the pause is specified in milliseconds, this function is not accurate to the millisecond. This should only be used for delays where precise timing is not required.

    Parameters

    • p_intms: number

      the number of milliseconds to pause for.

      // Example
      alert("Go to sleep when you select dismiss.")
      tadMisc.TA_sleepMS(4250);
      alert("Approximately 4.25 seconds have elapsed since you dismissed the previous alert.")
      

    Returns void

TA_sleepMSDisplay

  • TA_sleepMSDisplay(p_intSecs: number, p_intDisplayms: number, p_strPrefix?: string, p_strSuffix?: string): void
  • Pause doing anything else until a specified number of milliseconds has elapsed while displaying a counter. This is very similar to the TA_sleepMS function except that it also allows you to use a display information call to pop up details of how long the sleep has lasted. This should only be used for delays where precise timing is not required, and is even less accurate than the TA_sleepMS function. But it does allow you some feedback on longer pauses so you can be sure that something is happening. The visual display uses the number of seconds elapsed, and bounds this by a prefix and suffix string, specified as parameters of the function.

    Parameters

    • p_intSecs: number
    • p_intDisplayms: number

      the number of milliseconds gap between visual updates.

    • Optional p_strPrefix: string

      the text preceding the count of seconds elapsed in the visual update. Defaults to an empty string.

    • Optional p_strSuffix: string

      the text following the count of seconds elapsed in the visual update. Defaults to an empty string. p_intDisplayms

      // Example
      alert("Start");
      tadMisc.TA_sleepMSDisplay(12000, 5000, "=> ", " seconds elapsed.");
      alert("Stop");
      //Pauses for 12 seconds and displays an update message on every 5 seconds elapsed (approximately).
      // e.g. "=> 10 seconds elapsed".
      

    Returns void

TA_synonymInsert

  • TA_synonymInsert(p_intMax?: number): string
  • Inserts a user selected synonym for a selected word/phrase, or if none selected, prompts the user to enter a word/phrase to lookup. This function utilises the datamuse.com API. Returns the synonym selected by the user, or void if no valid selection is made.

    Parameters

    • Optional p_intMax: number

      the maximum number of words to be returned. Defaults to 25.

      // Example
      tadMisc.TA_synonymInsert(20);
      

    Returns string

TA_synonymOfSelected

  • TA_synonymOfSelected(p_intMax?: number): string
  • Presents a user with a list of synonyms to select from for a selected word/phrase, or if none selected, prompts the user to enter a word/phrase to lookup. This function utilises the datamuse.com API. Returns the synonym selected by the user, or void if no valid selection is made.

    Parameters

    • Optional p_intMax: number

      the maximum number of words to be returned. Defaults to 25.

      // Example
      alert(tadMisc.TA_synonymOfSelected(15));
      

    Returns string

TA_synonymSelect

  • TA_synonymSelect(p_strText: string, p_intMax?: number): string
  • Presents a user with a list of synonyms to select from for a specified word/phrase. This function utilises the datamuse.com API. Returns the synonym selected by the user, or undefined if no selection is made.

    Parameters

    • p_strText: string

      the word or phrase to be looked up.

    • Optional p_intMax: number

      the maximum number of words to be returned. Defaults to 25.

      // Example
      alert(tadMisc.TA_synonymSelect("draft", 10));
      

    Returns string

TA_transcludeWikiLinks

  • TA_transcludeWikiLinks(p_strContent: string): string
  • Expand Drafts wiki-style links in a string of content, including d and u type links. The function is passed a set of content which is searched for links of the form [[u:01234567-89AB-CDEF-0123-4567890ABCDE]], [[d:xyz]] and [[xyz]]. Wherever these are found, the function queries Drafts to identify a matching draft. When a matching draft is found, the content is transcluded. When no match is found, the link is left intact. Note that the content for this does not need to be the content of a draft, you can pass it any content string you like.

    Parameters

    • p_strContent: string

      the content string to be scanned for wiki-style links.

      // Example
      alert(tadMisc.TA_transcludeWikiLinks(draft.content));
      

    Returns string

TA_transcludeWikiLinks_$

  • TA_transcludeWikiLinks_$(p_strContent: string): string
  • Expand Drafts wiki-style links in a string of content. The function is passed a set of content which is searched for links of the form [[xyz]]. Wherever these are found, the function searches Drafts to find a draft with a matching title. If no matching title is found, the link is left untouched. If an exact title match (accounting for # based heading variations only) is found, the content of the matching draft is inserted into the string of content, replacing the wiki-style link. The function returns the content string with any matched wiki-style links transcluded. Note that the content for this does not need to be the content of a draft, you can pass it any content string you like.

    Parameters

    • p_strContent: string

      the content string to be scanned for wiki-style links.

      // Example
      alert(tadMisc.TA_transcludeWikiLinks_$(draft.content));
      

    Returns string

TA_transcludeWikiLinks_d

  • TA_transcludeWikiLinks_d(p_strContent: string): string
  • Expand Drafts d-wiki-style links in a string of content. The function is passed a set of content which is searched for links of the form [[d:xyz]]. Wherever these are found, the function searches Drafts to find a draft with a matching title. If no matching title is found, the link is left untouched. If an exact title match (accounting for # based heading variations only) is found, the content of the matching draft is inserted into the string of content, replacing the d-wiki-style link. The function returns the content string with any matched d-wiki-style links transcluded. Note that the content for this does not need to be the content of a draft, you can pass it any content string you like.

    Parameters

    • p_strContent: string

      the content string to be scanned for d-wiki-style links.

      // Example
      alert(tadMisc.TA_transcludeWikiLinks_d(draft.content));
      

    Returns string

TA_transcludeWikiLinks_u

  • TA_transcludeWikiLinks_u(p_strContent: string): string
  • Expand Drafts u-wiki-style links in a string of content. The function is passed a set of content which is searched for links of the form [[u:01234567-89AB-CDEF-0123-4567890ABCDE]]. Wherever these are found, the function queries Drafts to find a draft with a matching UUID. If no matching UUID is found, the link is left untouched. If a match is found, the content of the matching draft is inserted into the string of content, replacing the u-wiki-style link. The function returns the content string with any matched u-wiki-style links transcluded. Note that the content for this does not need to be the content of a draft, you can pass it any content string you like.

    Parameters

    • p_strContent: string

      the content string to be scanned for u-wiki-style links.

      // Example
      alert(tadMisc.TA_transcludeWikiLinks_u(draft.content));
      

    Returns string

TA_uuidv4

  • TA_uuidv4(a: any, b: any): string
  • Generate a v4 UUID. Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, where each x is replaced with a random hexadecimal digit from 0 to f, and y is replaced with a random hexadecimal digit from 8 to b.

    Parameters

    • a: any

      placeholder, do not populate.

    • b: any

      placeholder, do not populate.

      // Example
      alert(tadMisc.TA_uuidv4());
      

    Returns string