@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
92 lines (91 loc) • 4.48 kB
TypeScript
import { DateFormatsType } from "./types/formatter.types";
/**
* @class formatter
* @memberof util
*/
export declare class Formatter {
private ErrorHandler;
/**
* @function sliceStringAt
* @memberOf util.formatter
* @description Slices the given string beginning at a specific substring.
* @param {String} input - The input string to slice.
* @param {String} slicePoint - The substring at which the input string is being sliced.
* @param {number} length - The required length of the returning string (starting at the index of the passed slice point).
* @returns {String} The sliced string.
* @example const sliced = util.formatter.sliceStringAt("prefixNR12345postfix", "NR", 7);
* // returns "NR12345"
*/
sliceStringAt(input: string, slicePoint: string, length: number): string;
/**
* @function sliceStringAfter
* @memberOf util.formatter
* @description Slices the given string after a specific substring.
* @param {String} input - The input string to slice.
* @param {String} slicePoint - The substring after which the input string is being sliced.
* @param {number} length - The required length of the returning string (starting at the index after the passed slice point).
* @returns {String} The sliced string.
* @example const sliced = util.formatter.sliceStringAfter("prefixNR12345postfix", "NR", 5);
* // returns "12345"
*/
sliceStringAfter(input: string, slicePoint: string, length: number): string;
/**
* @function trimString
* @memberOf util.formatter
* @description Removes whitespace from both sides of the given string.
* @param {String} input - The input string to trim.
* @example const trimmed = util.formatter.trimString(" value ");
* // returns "value"
*/
trimString(input: string): string;
/**
* @function extractNumberFromString
* @memberOf util.formatter
* @description Extracts all numbers from a string.
* @param {String} input - The input string to extract the number.
* @param {number} [index=0] - If there are multiple numbers in the string you can pass an index to return a specific number.
* @returns {String} The extracted number.
* @example const extracted = util.formatter.extractNumberFromString("prefixNR12345postfix");
* // returns "12345"
* @example const extracted = util.formatter.extractNumberFromString("first12345 someText second 20 abc", 1);
* // returns "20"
*/
extractNumberFromString(input: string, index?: number): string;
/**
* @function stringifyJSON
* @memberOf util.formatter
* @description Converts a JSON object to string.
* @param {Object} object - The JSON to be converted.
* @returns {String} The converted JSON object.
* @example console.log(`Printing the current selector: ${util.formatter.stringifyJSON(selector)}`);
*/
stringifyJSON(object: object): string;
/**
* @function addRemoveLeadingZeros
* @memberOf util.formatter
* @description Adds or removes leading zeros to the passed number to format it to the required length.
* @param {String} number - The number to be formatted.
* @param {Number} length - The required length of the number.
* @returns {String} The formatted number.
* @example const itemNumber = util.formatter.addRemoveLeadingZeros(10, 5);
*/
addRemoveLeadingZeros(number: string, length: number): string;
/**
* @function formatDate
* @memberOf util.formatter
* @description formats date.
* @param {Date} date - The date object to be formatted.
* @param {String} format - The expected format ("mm/dd/yyyy", "dd.mm.yyyy", "dd/mm/yyyy", "yyyymmdd", "yyyy/mm/dd", "mmm dd, yyyy", "mmm d, yyyy", "datetime", "object").
* @param {String} [locale="en-US"] - The locale format of the date. E.g. "en-US", "de-DE", etc.
* @returns {String} The formatted date as string.
* @example const date = new Date(2020, 0, 17);
* const formattedDate = util.formatter.formatDate(date, "mm/dd/yyyy");
* // returns "01/17/2020"
* @example const date = new Date(2022, 3, 12);
* const formattedDate = util.formatter.formatDate(date, "mmm dd, yyyy");
* // returns "Apr 03, 2022"
*/
formatDate(date: Date, format: DateFormatsType, locale?: string): string | Date;
}
declare const _default: Formatter;
export default _default;