Bluestep JS Documentation
    Preparing search index...

    Class Text

    TODO

    TODO
    
    Index

    Constructors

    Properties

    BASE64_DEFAULT_DICT: ByteArray

    Used with base64 methods to specify how bytes are encode to Base64. This is the default encoding.See [[B.fromBase64]], [[B.toBase64]]

    BASE64_URL_DICT: ByteArray

    Used with base64 methods to specify how bytes are encode to Base64. This is used to encode a url parameter. See RFC 4648. See [[B.fromBaseUrl64]], [[B.toBaseUrl64]]

    Methods

    • A [[Java.ChoiceFormat]] based on the format string

      Parameters

      • newPattern: number
      • Optionalzone: ZoneId

      Returns ChoiceFormat

    • A [[Java.ChoiceFormat]] based on limits and formats

      Parameters

      • limits: number[]
      • formats: string[]
      • Optionalzone: ZoneId

      Returns ChoiceFormat

    • The csv functions are used to read data in a "comma separated values" format (CSV) or other related format such as tab delimited values. These data formats are used to represent data in rows and columns such as a spread sheet or a single database table. See [[CSV]] for more details.

      Parameters

      • input: string

        Input to be parsed.

      Returns CSV

      [[IO.csv]]

      Assume a CSV file exported from a spreadsheet like this one:

      First Last Birthday
      Betsy Ross 01 - Jan - 1735
      Alexander Hamilton 11 - Jan - 1755
      Benjamin Franklin 17 - Jan - 1706
      Daniel Webster 18 - Jan - 1782

      If we assume the CSV document is available on the internet at http://somedomain.com/birthdays.csv and we want to read it and convert it to a list on an html page we could write:
      const fetcher = B.net.fetch("http://somedomain.com/birthdays.csv");
      const out = "<ul>";
      B.text.csv(fetcher, fetcher.charset)
      .forEach(row => {
      out += "<li>" + row[0] + " " + row[1] + ": " + row[2] + "</li>";
      });
      out += "</ul>";
      inputStream.close();

      The out variable now contains an HTML snippet that looks like this:

      • First Last: Birthday
      • Betsy Ross: 01 - Jan - 1735
      • Alexander Hamilton: 11 - Jan - 1755
      • Benjamin Franklin: 17 - Jan - 1706
      • Daniel Webster: 18 - Jan - 1782

      A field delimeter and text delimeter can also be specifed for other types of files. For example a tab delimeted file:

      B.text.csv(tsvText)
      .fieldDelimeter('\n') //default but specified here as an example
      .textDelimeter('\t');
      .forEach(row => {
      //process row
      });
    • A [[Java.DecimalFormat]] based on the format string

      Parameters

      • format: string

        How to format the number

      Returns DecimalFormat

      const price = B.text.decimalFormat("$#,##0.00;$(#,##0.00)").format(45.50);
      
    • Used to find the difference between two strings and highlights those differences. See [[DiffBuilder]] and [[Diff]] for details.

      Returns DiffBuilder

      const diff = B.text.diff('sample','s@mple')
      .sensitivity(0.5)
      .noLineDiff()
      .sample(0)
      .find();
      const originalDifferences = diff.originalDiff;
      const originalMatchedPercent = diff.originalMatchedPercent;
      const currentDifferences = diff.currentDiff;
      const currentMatchedPercent = diff.currentMatchedPercent;
      const matchCharCount = diff.matchCharCount;
      const original = diff.original;
      const current = diff.current;
    • Returns a string of escaped HTML.

      Parameters

      • value: string

      Returns string

    • Returns a string that can be used inside Javascript quotes.

      Parameters

      • value: string

      Returns string

    • Returns a strings that can be used inside a JavaScript which is inside a tag attribute.

      Parameters

      • value: string

      Returns string

    • A [[Java.FieldPosition]] used by java's formatters

      Parameters

      • position: number

      Returns FieldPosition

    • Decodes a string formatted as Base64 to a [[Java.ByteArray]]

      Parameters

      • input: string

        String to be decoded.

      • OptionalcustomDictionary: string | ByteArray

        If provided, use customDictionary as the decoding dictionary for the method. If not provided, [[BASE64_DEFAULT_DICT]] is used.

      Returns ByteArray

    • Decodes a string formatted as Base64 using [[BASE64_URL_DICT]] to a [[Java.ByteArray]]

      Parameters

      • input: string

      Returns ByteArray

    • Generates a random string of the specified length. You may optionally pass a string of characters to use as the source of characters in the the random string, however the default is to use the full set of alphanumeric characters. Throws IllegalArgumentException if the chars string length is not between 1 and 256

      Parameters

      • length: number
      • Optionalchars: string

        Characters to use in the random string. Length must be between 1 and 256. Default is "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".

      Returns string

    • Convert a string formatted as a hex string to a [[Java.ByteArray]]

      Parameters

      • hexString: string

      Returns ByteArray

      [[toHex]]

    • Converts JSON to an XML string. The images of this method and its' sister method lie in one another's pre-image. Which is to say, for all valid XML strings A, and all xml-representative JSON B:

      // both of these statements are true
      xmlToJson(jsonToXml(xmlToJson(A))) == xmlToJson(A)
      jsonToXml(xmlToJson(jsonToXml(B))) == jsonToXml(B)

      Parameters

      • jsonStr: string

        Value representing text as JSON.

      Returns string

    • A [[Java.MessageFormat]] based on the format string

      Parameters

      • format: string

        String to be formatted

      • Optionalzone: ZoneId

        If absent use the user's time zone to be used by formatter

      Returns Bluestep.MessageFormat

      const planet = 7;
      const event = "a disturbance in the Force";
      const messageFormat = B.text.messageFormat(
      "At {1,time} on {1,date}, there was {2} on planet {0,number,integer} planet");
      const result = messageFormat.format(new Date().getMilliseconds(), event);

      The value of result is:

      At 12:30 PM on Jul 3, 2020, there was a disturbance in the Force on planet 7

      Using an embedded [[Java.ChoiceFormat]] as a pattern:

      const fileCount = 1273;
      const diskName = "Disk A";
      const messageFormat = B.text.messageFormat(
      "The disk \"{1}\" contains {0,choice,0#no files|1#one file|1<{0,number,integer} files");
      const result = messageFormat.format(fileCount, diskName);

      The value of result for different values of fileCount is:

      The disk "Disk A" contains no files
      The disk "Disk A" contains one file
      The disk "Disk A" contains 1273 files

      Using parsing:

      const forParsing = "x, y, z";
      const messageFormat = B.text.messageFormat("{0}, {0}, {0}";)
      const results = messageFormat.parse(forParsing);
      results.forEach(e => {});
    • This method is for backwards compatiblity. It uses SHA1 algorithm and a server provided salt to create the hash. The purpose of this method is to determine if data has changed.

      For instance, imagine a form with ten fields. Let's imagine that four of the fields are critical and the remaining six are less important. What if someone wanted to be notified when any of the four critical fields change, but doesn't want to be bothered when a change only effects the six less important fields. How can the changed fields be identified, since Relate does not provide any way of knowing? The answer is the secureHash() function.

      Here is how it is done: First, create another text field on the form and use the "Field Locking and Hiding" features to make it hidden on the form. Then write a formula that combines the values from each of the four critical fields into a single large String value. Since any type of data can be converted to a String this will work with any type of field. Have the formula compute a secureHash() from the combined values and store it into the new hidden text field. Now, whenever the form is saved, the formula can re-compute the combined String value and the secure hash value and, before storing the new result into the text field, the formula can compare the new hash to the previous hash. If the hash values are different then the formula should send the notification. If they are the same, then none of the critical fields have been changed. See also [[hash]].

      Parameters

      • input: string

      Returns string

    • Convert a string to a [[Java.ByteArray]]

      Parameters

      • source: string
      • Optionalcharset: string

      Returns ByteArray

    • Converts a [[Java.ByteArray]] to a Base64 encode string.

      Parameters

      • bytes: ByteArray
      • OptionalcustomDictionary: string | ByteArray

        If provided use the customDictionary as the dictionary to encode the string. If not provided, this method uses [[BASE64_DEFAULT_DICT]]

      Returns string

    • Converts a [[Java.ByteArray]] to a Base64 encode string using [[BASE64_URL_DICT]].

      Parameters

      Returns string

    • Converts a [[Java.ByteArray]] to a hex string.

      Parameters

      Returns string

    • Makes a copy of a string value converting it from plain text to formatted HTML

      Parameters

      • string: string

      Returns string

    • Makes a copy of a string value, converting it from formatted HTML to plain text

      Parameters

      • value: string

      Returns string

    • This method makes a copy of a string value, attempting to capitalize it as it would be if it were the title of something

      Parameters

      • value: string

      Returns string

    • Validates an XML string against an XSD schema. Returns true if the XML doc validates, returns false otherwise.

      Parameters

      • xml: string

        A string representation of an XML document

      • xsd: string

        A string representation of an XSD schema

      Returns boolean

      const {validateXML} = B.text;
      B.out = validateXML(xml,xsd) ? 'XML satisfies XSD constraints' : 'Improperly formatted XML'
    • Validates an XML string against an XSD schema. Returns true if the XML doc validates, returns false otherwise.

      Parameters

      • xml: InputStream

        An InputStream representation of an XML document

      • xsd: InputStream

        An InputStream representation of an XSD schema

      Returns boolean

      const {validateXML} = B.text;
      B.out = validateXML(xml,xsd) ? 'XML satisfies XSD constraints' : 'Improperly formatted XML'
    • Validates an XML string against an XSD schema. Returns true if the XML doc validates, returns false otherwise.

      Parameters

      • xml: Reader

        A Reader representation of an XML document

      • xsd: Reader

        A Reader representation of an XSD schema

      Returns boolean

      const {validateXML} = B.text;
      B.out = validateXML(xml,xsd) ? 'XML satisfies XSD constraints' : 'Improperly formatted XML'
    • Converts an XML string to JSON. The images of this method and its' sister method lie in one another's pre-image. Which is to say, for all valid XML strings A, and all xml-representative JSON B:

      // both of these statements are true
      xmlToJson(jsonToXml(xmlToJson(A))) == xmlToJson(A)
      jsonToXml(xmlToJson(jsonToXml(B))) == jsonToXml(B)

      Parameters

      • xml: string

        Value representing text as XML.

      Returns string

    • Make a piece of HTML text XSS safe.

      Parameters

      • text: string

        HTML text to be made XSS safe.

      Returns string

      const xml = B.text.xssHtmlSafe('<html></html>');
      
    • Make a string XSS safe.

      Parameters

      • html: string

        Text to be made XSS safe.

      Returns string

      const xml = B.text.xxsSafe('<xml></xml>');