@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
124 lines (123 loc) • 6.63 kB
TypeScript
import { DateFormatsType, DateTimeFormatsType } 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", "mm-dd-yyyy", "dd.mm.yyyy", "dd/mm/yyyy", "yyyymmdd", "yyyy/mm/dd",
* "yyyy.mm.dd", "yyyy-mm-dd", "dd.mm.yyyy.hh.mm", "mmm dd, yyyy", "mmm d, yyyy", "g.yy.mm.dd", "g/yy/mm/dd", "g-yy-mm-dd" "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;
/**
* @function formatDateWithTime
* @memberOf util.formatter
* @description formats date with time.
* @param {Date} date - The date object to be formatted.
* @param {String} format - The expected format ("datetime", "object", "mm/dd/yyyy HH\:mm:ss", "dd.mm.yyyy h\:mm:ss a", "dd/mm/yyyy HH\:mm:ss z", "yyyymmdd h\:mm:ss a z", "yyyy/mm/dd HH\:mm", "mmm dd, yyyy h\:mm a", "mmm d, yyyy HH", "mmm d, yyyy h a", etc.).<br>
* See the `format` argument of the {@link common.date.calculateWithTime} function for more details on the available formats.
* @param {String} [locale="en-US"] - The locale format of the date. E.g. "en-US", "de-DE", etc.
* @returns {String|Date} The formatted date with time as string or date object.
* @example const date = new Date(2020, 0, 17, 15, 30, 45);
* const formattedDate = util.formatter.formatDateWithTime(date, "mm/dd/yyyy HH:mm:ss");
* // returns "01/17/2020 15:30:45"
* @example const date = new Date(2022, 3, 12, 9, 5, 0);
* const formattedDate = util.formatter.formatDateWithTime(date, "mmm dd, yyyy h:mm:ss a");
* // returns "Apr 12, 2022 9:05:00 AM"
* @example const date = new Date(2022, 3, 12, 9, 5, 0);
* const formattedDate = util.formatter.formatDateWithTime(date, "dd/mm/yyyy HH:mm:ss z");
* // returns "12/04/2022 09:05:00 GMT+02:00"
* @example const date = new Date(2022, 3, 12, 9, 5, 0);
* const formattedDate = util.formatter.formatDateWithTime(date, "yyyy/mm/dd HH:mm");
* // returns "2022/04/12 09:05"
* @example const date = new Date(2022, 3, 12, 9, 5, 0);
* const formattedDate = util.formatter.formatDateWithTime(date, "mmm dd, yyyy h:mm a");
* // returns "Apr 12, 2022 9:05 AM"
*/
formatDateWithTime(date: Date, format?: DateTimeFormatsType, locale?: string): string | Date;
private _validateDateFormat;
private _containsTimeInDateFormat;
private _formatTime;
private _replaceTimeFormatToken;
private _formatTimeOffset;
}
declare const _default: Formatter;
export default _default;