Skip to content

Commit

Permalink
Merge pull request #72 from andersk/typescript
Browse files Browse the repository at this point in the history
Add TypeScript declarations
  • Loading branch information
eriwen committed Jun 5, 2022
2 parents 4ec577e + 9a29bf2 commit a1b044b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -50,10 +50,12 @@
"url": "https://github.com/stacktracejs/stacktrace-gps/issues"
},
"main": "./stacktrace-gps.js",
"types": "./stacktrace-gps.d.ts",
"files": [
"LICENSE",
"README.md",
"stacktrace-gps.js",
"stacktrace-gps.d.ts",
"dist/",
"node_modules/source-map/"
],
Expand Down
62 changes: 62 additions & 0 deletions stacktrace-gps.d.ts
@@ -0,0 +1,62 @@
import { SourceMapConsumer } from "source-map";
import StackFrame = require("stackframe");

declare namespace StackTraceGPS {
/**
* Options for the StackTraceGPS constructor
*/
interface Options {
/** Pre-populate source cache to avoid network requests */
sourceCache?: { [url: string]: string | Promise<string> };

/** Pre-populate SourceMapConsumer cache to avoid network requests */
sourceMapConsumerCache?: { [sourceMappingUrl: string]: SourceMapConsumer };

/** True to prevent network requests (best effort without sources or source maps) */
offline?: boolean;

/** Function to be used for making X-Domain requests */
ajax?(url: string): Promise<string>;

/** Function to convert base64-encoded strings to their original representation */
atob?(base64: string): string;
}
}

declare class StackTraceGPS {
/**
* @param opts - StackTraceGPS.Options object
*/
constructor(opts?: StackTraceGPS.Options);

/**
* Given a StackFrame, enhance function name and use source maps for
* a better StackFrame.
*
* @param stackframe - StackFrame object
* @returns Promise that resolves with with source-mapped StackFrame
*/
pinpoint(stackframe: StackFrame): Promise<StackFrame>;

/**
* Given a StackFrame, guess function name from location
* information.
*
* @param stackframe - StackFrame object
* @returns Promise that resolves with enhanced StackFrame
*/
findFunctionName(stackframe: StackFrame): Promise<StackFrame>;

/**
* Given a StackFrame, seek source-mapped location and return new
* enhanced StackFrame.
*
* @param stackframe - StackFrame object
* @returns Promise that resolves with enhanced StackFrame
*/
getMappedLocation(stackframe: StackFrame): Promise<StackFrame>;
}

export = StackTraceGPS;

export as namespace StackTraceGPS; // global for non-module UMD users

0 comments on commit a1b044b

Please sign in to comment.