@applitools/utils
Advanced tools
Comparing version 1.3.10 to 1.3.11
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pluralize = exports.toString = exports.toJSON = exports.sleep = exports.jwtDecode = exports.guid = exports.getEnvValue = void 0; | ||
exports.pluralize = exports.extend = exports.wrap = exports.batchify = exports.cachify = exports.absolutizeUrl = exports.toUriEncoding = exports.toUnAnchoredUri = exports.toString = exports.toJSON = exports.sleep = exports.jwtDecode = exports.guid = exports.getEnvValue = void 0; | ||
const types = __importStar(require("./types")); | ||
@@ -35,4 +35,4 @@ function getEnvValue(name, type) { | ||
return; | ||
if (type === 'boolean' && types.isBoolean(value)) | ||
return (value === 'true'); | ||
if (type === 'boolean') | ||
return ['true', true, '1', 1].includes(value); | ||
if (type === 'number') | ||
@@ -80,2 +80,64 @@ return Number(value); | ||
exports.toString = toString; | ||
function toUnAnchoredUri(url) { | ||
var _a; | ||
const [, result = url] = (_a = url.match(/(^[^#]*)/)) !== null && _a !== void 0 ? _a : []; | ||
return result === null || result === void 0 ? void 0 : result.replace(/\?\s*$/, '?'); | ||
} | ||
exports.toUnAnchoredUri = toUnAnchoredUri; | ||
function toUriEncoding(url) { | ||
return url.replace(/(\\[0-9a-fA-F]{1,6}\s?)/g, s => { | ||
return String.fromCodePoint(Number.parseInt(s.substring(1).trim(), 16)); | ||
}); | ||
} | ||
exports.toUriEncoding = toUriEncoding; | ||
function absolutizeUrl(url, baseUrl) { | ||
return new URL(url, baseUrl).href; | ||
} | ||
exports.absolutizeUrl = absolutizeUrl; | ||
function cachify(func, getKey) { | ||
const cache = new Map(); | ||
const funcWithCache = ((...args) => { | ||
var _a; | ||
const key = JSON.stringify((_a = getKey === null || getKey === void 0 ? void 0 : getKey(args)) !== null && _a !== void 0 ? _a : args, (_, t) => (typeof t === 'function' ? t.toString() : t)); | ||
let value = cache.get(key); | ||
if (!value) { | ||
value = func(...args); | ||
cache.set(key, value); | ||
} | ||
return value; | ||
}); | ||
funcWithCache.clearCache = () => cache.clear(); | ||
funcWithCache.getCachedValues = () => Array.from(cache.values()); | ||
return funcWithCache; | ||
} | ||
exports.cachify = cachify; | ||
function batchify(func, { timeout }) { | ||
let pendingInputs = new Map(); | ||
let throttleTimer = false; | ||
return function (input) { | ||
return new Promise(async (resolve, reject) => { | ||
pendingInputs.set(input, { resolve, reject }); | ||
if (!throttleTimer) { | ||
throttleTimer = true; | ||
setTimeout(() => { | ||
func(Array.from(pendingInputs.entries())); | ||
pendingInputs = new Map(); | ||
throttleTimer = false; | ||
}, timeout); | ||
} | ||
}); | ||
}; | ||
} | ||
exports.batchify = batchify; | ||
function wrap(func, wrapper) { | ||
return ((...args) => wrapper(func, ...args)); | ||
} | ||
exports.wrap = wrap; | ||
function extend(target, extension) { | ||
return Object.defineProperties({}, { | ||
...Object.getOwnPropertyDescriptors(target), | ||
...Object.getOwnPropertyDescriptors(extension), | ||
}); | ||
} | ||
exports.extend = extend; | ||
function pluralize(object, config) { | ||
@@ -82,0 +144,0 @@ const count = types.isArray(object) ? object.length : object; |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withPadding = exports.divide = exports.equals = exports.contains = exports.isIntersected = exports.intersect = exports.offsetNegative = exports.offset = exports.scale = exports.rotate = exports.floor = exports.ceil = exports.round = exports.isEmpty = exports.region = exports.size = exports.location = void 0; | ||
exports.padding = exports.divide = exports.equals = exports.contains = exports.isIntersected = exports.intersect = exports.offsetNegative = exports.offset = exports.scale = exports.rotate = exports.floor = exports.ceil = exports.round = exports.isEmpty = exports.region = exports.size = exports.location = void 0; | ||
const types = __importStar(require("./types")); | ||
@@ -248,3 +248,3 @@ const guard = __importStar(require("./guard")); | ||
exports.divide = divide; | ||
function withPadding(region, padding) { | ||
function padding(region, padding) { | ||
var _a, _b, _c, _d; | ||
@@ -268,2 +268,2 @@ if (types.isNumber(padding)) { | ||
} | ||
exports.withPadding = withPadding; | ||
exports.padding = padding; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sh = exports.executeProcess = exports.executeAndControlProcess = void 0; | ||
exports.execute = exports.sh = exports.executeProcess = exports.executeAndControlProcess = void 0; | ||
const child_process_1 = require("child_process"); | ||
@@ -70,1 +70,11 @@ const fs_1 = require("fs"); | ||
exports.sh = sh; | ||
async function execute(command, options) { | ||
return new Promise(resolve => { | ||
(0, child_process_1.exec)(command, options, (error, stdout, stderr) => { | ||
if (error) | ||
resolve({ stdout, stderr, code: error.code }); | ||
resolve({ stdout, stderr, code: 0 }); | ||
}); | ||
}); | ||
} | ||
exports.execute = execute; |
"use strict"; | ||
/* eslint {"@typescript-eslint/ban-types": ["error", {"types": {"Function": false}}]} */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.instanceOf = exports.has = exports.isEnumValue = exports.isFunction = exports.isEmpty = exports.isPlainObject = exports.isObject = exports.isArray = exports.isInteger = exports.isNumber = exports.isBase64 = exports.isString = exports.isBoolean = exports.isNull = exports.isDefined = exports.isNotDefined = void 0; | ||
exports.instanceOf = exports.has = exports.isEnumValue = exports.isFunction = exports.isEmpty = exports.isPlainObject = exports.isObject = exports.isArray = exports.isInteger = exports.isNumber = exports.isHttpUrl = exports.isBase64 = exports.isString = exports.isBoolean = exports.isNull = exports.isDefined = exports.isNotDefined = void 0; | ||
function isNotDefined(value) { | ||
@@ -30,2 +30,12 @@ return (isNull(value) || | ||
exports.isBase64 = isBase64; | ||
function isHttpUrl(value) { | ||
try { | ||
const url = new URL(value); | ||
return url.protocol === 'http:' || url.protocol === 'https:'; | ||
} | ||
catch { | ||
return false; | ||
} | ||
} | ||
exports.isHttpUrl = isHttpUrl; | ||
function isNumber(value) { | ||
@@ -32,0 +42,0 @@ return typeof value === 'number' || value instanceof Number; |
{ | ||
"name": "@applitools/utils", | ||
"version": "1.3.10", | ||
"version": "1.3.11", | ||
"keywords": [ | ||
@@ -65,3 +65,3 @@ "applitools", | ||
"devDependencies": { | ||
"@applitools/bongo": "^2.1.6", | ||
"@applitools/bongo": "^2.2.0", | ||
"@types/mocha": "^9.1.1", | ||
@@ -68,0 +68,0 @@ "@types/node": "12", |
@@ -21,2 +21,17 @@ export declare function getEnvValue<T extends 'boolean' | 'number' | 'string' = 'string'>(name: string, type?: T): T extends 'boolean' ? boolean : T extends 'number' ? number : string; | ||
export declare function toString(object: Record<PropertyKey, any>): string; | ||
export declare function toUnAnchoredUri(url: string): string; | ||
export declare function toUriEncoding(url: string): string; | ||
export declare function absolutizeUrl(url: string, baseUrl: string): string; | ||
export declare function cachify<TFunc extends (...args: any[]) => any>(func: TFunc, getKey?: (args: Parameters<TFunc>) => any): TFunc & { | ||
clearCache(): void; | ||
getCachedValues(): ReturnType<TFunc>[]; | ||
}; | ||
export declare function batchify<TFunc extends (batch: [TInput, { | ||
resolve(result?: TResult): void; | ||
reject(reason?: any): void; | ||
}][]) => Promise<void>, TInput = Parameters<TFunc>[0][number][0], TResult = Parameters<Parameters<TFunc>[0][number][1]['resolve']>[0]>(func: TFunc, { timeout }: { | ||
timeout: number; | ||
}): (input: Parameters<TFunc>[0][number][0]) => Promise<TResult>; | ||
export declare function wrap<TFunc extends (...args: any[]) => any>(func: TFunc, wrapper: (func: TFunc, ...args: Parameters<TFunc>) => ReturnType<TFunc>): TFunc; | ||
export declare function extend<TTarget extends Record<PropertyKey, any>, TExtension extends Record<PropertyKey, any>>(target: TTarget, extension: TExtension): TTarget & TExtension; | ||
export declare function pluralize(object: [] | number, config?: [manyCase: string, singleCase: string]): string; |
@@ -50,3 +50,3 @@ declare type Location = { | ||
}): Region[]; | ||
export declare function withPadding(region: Region, padding: number | { | ||
export declare function padding(region: Region, padding: number | { | ||
top?: number; | ||
@@ -53,0 +53,0 @@ right?: number; |
/// <reference types="node" /> | ||
import { SpawnOptions } from 'child_process'; | ||
import { ExecOptions, SpawnOptions } from 'child_process'; | ||
export declare function executeAndControlProcess(command: string, args?: any[], options?: { | ||
@@ -18,1 +18,6 @@ spawnOptions?: SpawnOptions; | ||
}): Promise<unknown>; | ||
export declare function execute(command: string, options?: ExecOptions): Promise<{ | ||
stdout: string; | ||
stderr: string; | ||
code: number; | ||
}>; |
@@ -7,2 +7,3 @@ export declare function isNotDefined(value: any): boolean; | ||
export declare function isBase64(value: any): value is string; | ||
export declare function isHttpUrl(value: any): value is string; | ||
export declare function isNumber(value: any): value is number; | ||
@@ -9,0 +10,0 @@ export declare function isInteger(value: any): value is number; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65598
1141