source: trip-planner-front/node_modules/source-list-map/README.md@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1# source-list-map
2
3## API
4
5### Example
6
7``` js
8var SourceListMap = require("source-list-map").SourceListMap;
9
10// Create a new map
11var map = new SourceListMap();
12
13// Add generated code that is map line to line to some soure
14map.add("Generated\ncode1\n", "source-code.js", "Orginal\nsource");
15
16// Add generated code that isn't mapped
17map.add("Generated\ncode2\n");
18
19// Get SourceMap and generated source
20map.toStringWithSourceMap({ file: "generated-code.js" });
21// {
22// source: 'Generated\ncode1\nGenerated\ncode2\n',
23// map: {
24// version: 3,
25// file: 'generated-code.js',
26// sources: [ 'source-code.js' ],
27// sourcesContent: [ 'Orginal\nsource' ],
28// mappings: 'AAAA;AACA;;;'
29// }
30// }
31
32// Convert existing SourceMap into SourceListMap
33// (Only the first mapping per line is preserved)
34var fromStringWithSourceMap = require("source-list-map").fromStringWithSourceMap;
35var map = fromStringWithSourceMap("Generated\ncode", { version: 3, ... });
36
37```
38
39### `new SourceListMap()`
40
41### `SourceListMap.prototype.add`
42
43``` js
44SourceListMap.prototype.add(generatedCode: string)
45SourceListMap.prototype.add(generatedCode: string, source: string, originalSource: string)
46SourceListMap.prototype.add(sourceListMap: SourceListMap)
47```
48
49Append some stuff.
50
51### `SourceListMap.prototype.prepend`
52
53``` js
54SourceListMap.prototype.prepend(generatedCode: string)
55SourceListMap.prototype.prepend(generatedCode: string, source: string, originalSource: string)
56SourceListMap.prototype.prepend(sourceListMap: SourceListMap)
57```
58
59Prepend some stuff.
60
61### `SourceListMap.prototype.toString()`
62
63Get generated code.
64
65### `SourceListMap.prototype.toStringWithSourceMap`
66
67``` js
68SourceListMap.prototype.toStringWithSourceMap(options: object)
69```
70
71Get generated code and SourceMap. `options` can contains `file` property which defines the `file` property of the SourceMap.
72
73### `SourceListMap.prototype.mapGeneratedCode`
74
75``` js
76SourceListMap.prototype.mapGeneratedCode(fn: function) : SourceListMap
77```
78
79Applies `fn` to each generated code block (per line). The returned value is set as new generated code. Returns a new SourceListMap.
80
81Removing and adding lines is supported. The SourceMap complexity will increase when doing this.
82
83## Test
84
85[![Build Status](https://travis-ci.org/webpack/source-list-map.svg)](https://travis-ci.org/webpack/source-list-map)
86
87## License
88
89Copyright (c) 2017 JS Foundation
90
91MIT (http://www.opensource.org/licenses/mit-license.php)
Note: See TracBrowser for help on using the repository browser.