@eclipse-scout/core
Version:
Eclipse Scout runtime
171 lines • 8.01 kB
TypeScript
import { PlainTextEncoderOptions } from '../index';
export declare const strings: {
/**
* @param [encodeHtml] defaults to true
*/
nl2br(text: string, encodeHtml?: boolean): string;
insertAt(text: string, insertText: string, position: number): string;
/**
* @returns true if the given string contains any non-space characters
*/
hasText(text: string): boolean;
/**
* Inverse operation of hasText(string). Used because empty(s) is more readable than !hasText(s).
* @returns true if the given string is not set or contains only white-space characters.
*/
empty(text: string): boolean;
repeat(pattern: string, count: number): string;
padZeroLeft(string: string | number, padding: number): string;
contains(string: string, searchFor: string): boolean;
startsWith(fullString: string, startString: string): boolean;
endsWith(fullString: string, endString: string): boolean;
/**
* Returns the number of occurrences of 'separator' in 'string'
*/
count(string: string, separator: string): number;
/**
* Returns the HTML encoded text. Example: 'Foo<br>Bar' returns 'Foo&lt;br&gt;Bar'.
* If the argument is or undefined, the same value is returned.
* @param text plain text to encode
* @returns HTML encoded text
*/
encode(text: string): string;
/**
* Returns the plain text of the given html string using simple tag replacement.<p>
* Tries to preserve the new lines. Since it does not consider the style, it won't be right in any cases.
* A div for example always generates a new line, even if display style is not set to block.
*/
plainText(text: string, options?: PlainTextEncoderOptions): string;
/**
* Joins a list of strings to a single string using the given separator. Elements that are
* not defined or have zero length are ignored. The default return value is the empty string.
*
* @param separator String to use as separator
* @param args list of strings to join. Can be an array or individual arguments
*/
join(separator: string, ...args: string[]): string;
/**
* If the given 'string' has text, it is returned with the 'prefix' and 'suffix'
* prepended and appended, respectively. Otherwise, the empty string is returned.
*/
box(prefix: string, string: string, suffix?: string): string;
/**
* Quotes a string for use in a regular expression, i.e. escapes all characters with special meaning.
*/
quote(string: string): string;
/**
* If the given input is not of type string, it is converted to a string (using the standard
* JavaScript "String()" function). Inputs 'null' and 'undefined' are returned as they are.
*/
asString(input: any): string;
/**
* This is a shortcut for <code>scout.nvl(string, '')</code>.
* @param string String to check
* @returns Empty string '' when given string is null or undefined.
*/
nvl(string: string): string;
/**
* Null-safe version of <code>String.prototype.length</code>.
* If the argument is null or undefined, 0 will be returned.
* A non-string argument will be converted to a string.
*/
length(string: string): number;
/**
* Null-safe version of <code>String.prototype.trim</code>.
* If the argument is null or undefined, the same value will be returned.
* A non-string argument will be converted to a string.
*/
trim(string: string): string;
/**
* Null-safe version of <code>String.prototype.toUpperCase</code>.
* If the argument is null or undefined, the same value will be returned.
* A non-string argument will be converted to a string.
*/
toUpperCase(string: string): string;
/**
* Null-safe version of <code>String.prototype.toLowerCase</code>.
* If the argument is null or undefined, the same value will be returned.
* A non-string argument will be converted to a string.
*/
toLowerCase(string: string): string;
/**
* Returns the given string, with the first character converted to upper case and the remainder unchanged.
* If the argument is null or undefined, the same value will be returned.
* A non-string argument will be converted to a string.
*/
toUpperCaseFirstLetter(string: string): string;
/**
* Returns the given string, with the first character converted to lower case and the remainder unchanged.
* If the argument is null or undefined, the same value will be returned.
* A non-string argument will be converted to a string.
*/
toLowerCaseFirstLetter(string: string): string;
/**
* Returns the number of unicode characters in the given string.
* As opposed to the string.length property, astral symbols are
* counted as one single character.
*
* Example: <code>'\uD83D\uDC4D'.length</code> returns 2, whereas
* <code>countCodePoints('\uD83D\uDC4D')</code> returns 1.
*
* (\uD83D\uDC4D = unicode character U+1F44D 'THUMBS UP SIGN')
*/
countCodePoints(string: string): number;
/**
* Splits the given 'string' at 'separator' while returning at most 'limit' elements.
* Unlike String.prototype.split(), this function does not discard elements if more than
* 'limit' elements are found. Instead, the surplus elements are joined with the last element.
*
* Example:
* <ul>
* <li>'a-b-c'.split('-', 2) ==> ['a', 'b']
* <li>splitMax('a-b-c', '-', 2) ==> ['a', 'b-c']
* </ul>
*/
splitMax(string: string, separator: string, limit: number): string[];
nullIfEmpty(string: string): string;
/**
* Null safe case-sensitive comparison of two strings.
*
* @param [ignoreCase] optional flag to perform case-insensitive comparison
*/
equals(a: string, b: string, ignoreCase?: boolean): boolean;
equalsIgnoreCase(a: string, b: string): boolean;
/**
* Adds the given prefix to the start of the given string and returns the result.
* If either of the given arguments is null or empty, the original string is returned unchanged, i.e. without prefix.
*/
addPrefix(string: string, prefix: string): string;
/**
* Adds the given suffix to the end of the given string and returns the result.
* If either of the given arguments is null or empty, the original string is returned unchanged, i.e. without suffix.
*/
addSuffix(string: string, suffix: string): string;
/**
* If the given string starts with the given prefix, the prefix is removed and the remaining string is returned.
* Otherwise, the string is returned unchanged. This method is case-sensitive and null-safe.
*/
removePrefix(string: string, prefix: string): string;
/**
* If the given string ends with the given suffix, the suffix is removed and the remaining string is returned.
* Otherwise, the string is returned unchanged. This method is case-sensitive and null-safe.
*/
removeSuffix(string: string, suffix: string): string;
/**
* Truncates the given text and appends '...' so it fits into the given horizontal space.
*
* @param text the text to be truncated
* @param horizontalSpace the horizontal space the text needs to fit into
* @param measureText a function that measures the span of a text, it needs to return an object containing a 'width' property.
* If not provided, the width corresponds to the number of characters.
* @returns the truncated text
*/
truncateText(text: string, horizontalSpace: number, measureText?: (text: string) => {
width: number;
}): string;
/**
* @returns `true` or `false` if the given string is either `'true'` or `'false'` (ignoring case). Otherwise, `undefined` is returned.
*/
parseBoolean(value: string): boolean;
};
//# sourceMappingURL=strings.d.ts.map