UNPKG

appium-xcuitest-driver

Version:

Appium driver for iOS using XCUITest for backend

104 lines 3.24 kB
"use strict"; // TODO(appium server 3.4.1+): Replace local helpers with imports from `appium/support` // once this driver declares that minimum server version. Object.defineProperty(exports, "__esModule", { value: true }); exports.isEmpty = isEmpty; exports.escapeRegExp = escapeRegExp; exports.isPlainObject = isPlainObject; exports.assignDefaults = assignDefaults; exports.mergeDeep = mergeDeep; exports.truncateString = truncateString; exports.upperFirst = upperFirst; exports.capitalize = capitalize; /** * Returns true when the value has no elements/properties. * * @param value - Value to check * @returns `true` if the value is empty */ function isEmpty(value) { if (value == null) { return true; } if (typeof value === 'string' || Array.isArray(value) || Buffer.isBuffer(value)) { return value.length === 0; } if (value instanceof Map || value instanceof Set) { return value.size === 0; } if (typeof value === 'object' || typeof value === 'function') { return Object.keys(value).length === 0; } return true; } /** * Escapes RegExp special characters in a string. * * @param value - Input string * @returns Escaped string safe for RegExp source */ function escapeRegExp(value) { return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } /** * Returns true when `value` is a plain object (including objects with a null prototype). */ function isPlainObject(value) { if (typeof value !== 'object' || value === null || Array.isArray(value)) { return false; } const proto = Object.getPrototypeOf(value); return proto === null || proto === Object.prototype; } /** * Assigns own enumerable properties of `source` onto `target` only where `target[key] === undefined` * (lodash `defaults` semantics). */ function assignDefaults(target, source) { for (const key of Object.keys(source)) { if (target[key] === undefined) { target[key] = source[key]; } } } /** * Deep-merges own enumerable properties of each `source` into `target` (lodash `merge` semantics). */ function mergeDeep(target, ...sources) { for (const source of sources) { for (const key of Object.keys(source)) { const sourceValue = source[key]; const targetValue = target[key]; if (isPlainObject(sourceValue) && isPlainObject(targetValue)) { mergeDeep(targetValue, sourceValue); } else { target[key] = sourceValue; } } } return target; } /** * Truncates a string to `length` characters (lodash-compatible default omission). */ function truncateString(value, { length, omission = '...' }) { if (value.length <= length) { return value; } const end = Math.max(0, length - omission.length); return `${value.slice(0, end)}${omission}`; } /** * Uppercases the first character of a string. */ function upperFirst(value) { return value ? value[0].toUpperCase() + value.slice(1) : value; } /** * Capitalizes the first character and lowercases the rest. */ function capitalize(value) { return value ? upperFirst(value.toLowerCase()) : value; } //# sourceMappingURL=lang.js.map