UNPKG

4.23 kBTypeScriptView Raw
1// Type definitions for convert-source-map 1.5
2// Project: https://github.com/thlorenz/convert-source-map
3// Definitions by: Andrew Gaspar <https://github.com/AndrewGaspar>, Melvin Groenhoff <https://github.com/mgroenhoff>, TeamworkGuy2 <https://github.com/TeamworkGuy2>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/**
7 * Converts a source-map from/to different formats and allows adding/changing properties.
8 * (documentation based on project's README file)
9 */
10export interface SourceMapConverter {
11 /** The parsed sourcemap object */
12 sourcemap: any;
13
14 /** Returns a copy of the underlying source map */
15 toObject(): any;
16
17 /** Converts source map to json string. If space is given (optional), this will be passed to JSON.stringify when the JSON string is generated */
18 toJSON(space?: string | number): string;
19
20 /** Converts source map to base64 encoded json string */
21 toBase64(): string;
22
23 /**
24 * Converts source map to an inline comment that can be appended to the source-file.
25 * By default, the comment is formatted like: //# sourceMappingURL=..., which you would normally see in a JS source file.
26 * When options.multiline == true, the comment is formatted like: /*# sourceMappingURL=... *\/, which you would find in a CSS source file
27 */
28 toComment(options?: { multiline?: boolean | undefined }): string;
29
30 /** Adds given property to the source map. Throws an error if property already exists */
31 addProperty(key: string, value: any): SourceMapConverter;
32
33 /** Sets given property to the source map. If property doesn't exist it is added, otherwise its value is updated */
34 setProperty(key: string, value: any): SourceMapConverter;
35
36 /** Gets given property of the source map */
37 getProperty(key: string): any;
38}
39
40/** Returns source map converter from given object */
41export function fromObject(obj: any): SourceMapConverter;
42
43/** Returns source map converter from given json string */
44export function fromJSON(json: string): SourceMapConverter;
45
46/** Returns source map converter from given base64 encoded json string */
47export function fromBase64(base64: string): SourceMapConverter;
48
49/** Returns source map converter from given base64 encoded json string prefixed with //# sourceMappingURL=... */
50export function fromComment(comment: string): SourceMapConverter;
51
52/**
53 * Returns source map converter from given filename by parsing //# sourceMappingURL=filename.
54 * filename must point to a file that is found inside the mapFileDir. Most tools store this file right next to the generated file, i.e. the one containing the source map.
55 */
56export function fromMapFileComment(comment: string, commentFileDir: string): SourceMapConverter;
57
58/**
59 * Finds last sourcemap comment in file and returns source map converter or returns null if no source map comment was found.
60 */
61export function fromSource(content: string): SourceMapConverter | null;
62
63/**
64 * Finds last sourcemap comment in file and returns source map converter or returns null if no source map comment was found.
65 * The sourcemap will be read from the map file found by parsing # sourceMappingURL=file comment. For more info see fromMapFileComment.
66 */
67export function fromMapFileSource(content: string, commentFileDir: string): SourceMapConverter | null;
68
69/** Returns src with all source map comments removed */
70export function removeComments(src: string): string;
71
72/** Returns src with all source map comments pointing to map files removed */
73export function removeMapFileComments(src: string): string;
74
75/** Returns a new regex used to find source map comments */
76export const commentRegex: RegExp;
77
78/** Returns a new regex used to find source map comments pointing to map files */
79export const mapFileCommentRegex: RegExp;
80
81/**
82 * Returns a comment that links to an external source map via file.
83 * By default, the comment is formatted like: //# sourceMappingURL=..., which you would normally see in a JS source file.
84 * When options.multiline == true, the comment is formatted like: /*# sourceMappingURL=... *\/, which you would find in a CSS source file.
85 */
86export function generateMapFileComment(file: string, options?: { multiline?: boolean | undefined }): string;