How to use callsites - 2 common examples

To help you get started, we’ve selected a few callsites examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / ow / source / index.ts View on Github external
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);
};
github andywer / threads.js / src / master / implementation.node.ts View on Github external
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
}

callsites

Get callsites from the V8 stack trace API

MIT
Latest version published 5 months ago

Package Health Score

77 / 100
Full package analysis

Popular callsites functions