Skip to content

Commit f622aca

Browse files
committed
Docs: Add example and API (closes #2)
1 parent 6ff3070 commit f622aca

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,37 @@ Gulp plugin for mapping sources of a sourcemap.
77
## Example
88

99
```js
10-
// TODO
10+
var mapSources = require('@gulp-sourcemaps/map-sources');
11+
12+
gulp.src(...)
13+
.pipe(sourcemaps.init())
14+
.pipe(mapSources(function(sourcePath, file) {
15+
return '../' + sourcePath;
16+
}))
17+
.pipe(sourcemaps.write())
18+
.pipe(gulp.dest(...))
1119
```
1220

1321
## API
1422

15-
### `TODO`
23+
### `mapSources(mapFn)`
24+
25+
Takes a map function as the only argument. Returns an `objectMode` Transform stream.
26+
27+
#### `mapFn(sourcePath, file)`
28+
29+
The map function is called once per value of the `sources` array of a `sourceMap` attached to each [`Vinyl`][vinyl-url] object passed through the stream. The map function is called with the `sourcePath` string from the `sources` array and the `file` object it originated from. The return value replaces the original value in the array.
30+
31+
If a `Vinyl` object doesn't have a `sourceMap` or `sourceMap.sources` property, the file is passed through the stream without having the `mapFn` called.
32+
33+
All `sources` are normalized to use `/` instead of `\\` as path separators.
1634

1735
## License
1836

1937
MIT
2038

39+
[vinyl-url]: https://github.com/gulpjs/vinyl
40+
2141
[downloads-image]: http://img.shields.io/npm/dm/@gulp-sourcemaps/map-sources.svg
2242
[npm-url]: https://npmjs.org/package/@gulp-sourcemaps/map-sources
2343
[npm-image]: http://img.shields.io/npm/v/@gulp-sourcemaps/map-sources.svg

0 commit comments

Comments
 (0)