Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ow = (value: T, labelOrPredicate: unknown, predicate?: BasePredicate) => {
if (!isPredicate(labelOrPredicate) && typeof labelOrPredicate !== 'string') {
throw new TypeError(`Expected second argument to be a predicate or a string, got \`${typeof labelOrPredicate}\``);
}
if (isPredicate(labelOrPredicate)) {
// If the second argument is a predicate, infer the label
const stackFrames = callsites();
test(value, () => inferLabel(stackFrames), labelOrPredicate);
return;
}
test(value, labelOrPredicate, predicate as BasePredicate);
};
function rebaseScriptPath(scriptPath: string, ignoreRegex: RegExp) {
const parentCallSite = getCallsites().find((callsite: CallSite) => {
const filename = callsite.getFileName()
return Boolean(filename && !filename.match(ignoreRegex) && !filename.match(/[\/\\]master[\/\\]implementation/))
})
const callerPath = parentCallSite ? parentCallSite.getFileName() : null
const rebasedScriptPath = callerPath ? path.join(path.dirname(callerPath), scriptPath) : scriptPath
return rebasedScriptPath
}