UNPKG

bc-node-sdk

Version:

BetterCommerce's NodeJS SDK encapsulates the base framework for all the Next.js applications.

80 lines (79 loc) 3.38 kB
/** * Class {@link ParseUtil} encapsulates utility methods for parsing data. */ export default abstract class ParseUtil { /** * Parses boolean from string. * @param stringValue * @returns */ static stringToBoolean(stringValue: string | undefined): boolean; /** * Parses number from string. * @param stringValue * @returns */ static stringToNumber(stringValue: string | undefined): number; /** * Checks if two strings are equal. * @param input1 First string to compare * @param input2 Second string to compare * @param ignoreCase If true, ignores case while comparing * @param replaceInput If true, input strings are replaced with the replacement string before comparison * @param replacementRegExp RegExp which is replaced with the replacement string * @param replacement String with which the replacementRegExp is replaced * @returns True if strings are equal, otherwise false */ static matchStrings(input1: string, input2: string, ignoreCase?: boolean, replaceInput?: boolean, replacementRegExp?: RegExp, replacement?: string): boolean; /** * Converts a JSON object into a JSON string. * @param json The JSON object to be converted * @returns The JSON string representation of the JSON object */ static jsonStringify(json: any): string; /** * Attempts to parse a JSON string into a JSON object. * @param input The JSON string to be parsed * @returns The parsed JSON object if successful, otherwise null */ static stringToObject(input: string): any; /** * Attempts to parse a JSON string into a JSON object. * @param json The JSON string to be parsed * @returns The parsed JSON object if successful, otherwise null */ static tryParseJson(json: any): any; /** * Format a given string using the format function from the string-format package. * @param input The string to be formatted * @param data An object containing the key-value pairs used to replace placeholders in the string * @returns The formatted string if the input string is not null or undefined, otherwise an empty string */ static stringFormat(input: string, data: object): any; /** * Determines if a given string is valid JSON. * @param input the string to be validated * @returns true if the string is valid JSON, false otherwise */ static isValidJSON(input: string): boolean; /** * Formats a given byte value into a human-readable format. * @param bytes the value in bytes to be formatted * @param decimals the number of decimal places to round to * @returns the formatted string, e.g. "1.23 KB" */ static formatBytes(bytes: any, decimals?: number): string; /** * Converts a JSON object into a blob, which can be used * to create a file download. * @param {any} json - The JSON object to convert. * @returns {Blob} The blob containing the stringified JSON. */ static jsonToBlob(json: any): Blob; /** * Checks if a given object is empty. * @param obj The object to be checked * @returns true if the object is empty, false otherwise */ static isEmptyObject(obj: object): boolean; }