Skip to content

Commit 031b184

Browse files
committed
feat(doc): describe how to use in readme
1 parent 0825f32 commit 031b184

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,43 @@
88
[![semantic-release][semantic-image] ][semantic-url]
99
[![js-standard-style][standard-image]][standard-url]
1010

11+
## Install
12+
13+
```
14+
npm install -S stack-sites
15+
```
16+
17+
```js
18+
const stackSites = require('stack-sites')
19+
function foo () {
20+
const sites = stackSites()
21+
// sites[0] - stackSites itself
22+
// sites[1] - this file
23+
// sites[2] - caller to this function
24+
const caller = sites[2]
25+
console.log('I got called from %s line %d column %d',
26+
caller.filename, caller.line, caller.column
27+
)
28+
}
29+
module.exports = foo
30+
```
31+
32+
## Why?
33+
34+
V8 stack API does not return accurate source locations if the source file
35+
has been transpiled on load, see
36+
[Accurate call sites](https://glebbahmutov.com/blog/accurate-call-sites/)
37+
blog post. Exception stack on the other hand can take source maps into
38+
the account, producing correct line and column information.
39+
1140
### Small print
1241

1342
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2017
1443

15-
1644
* [@bahmutov](https://twitter.com/bahmutov)
1745
* [glebbahmutov.com](http://glebbahmutov.com)
1846
* [blog](http://glebbahmutov.com/blog)
1947

20-
2148
License: MIT - do anything with the code, but don't blame me if it does not work.
2249

2350
Support: if you find any problems with this module, email / tweet /

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@
6767
"nsp": "2.6.2",
6868
"pre-git": "3.12.0",
6969
"standard": "8.6.0"
70+
},
71+
"dependencies": {
72+
"check-more-types": "2.23.0",
73+
"lazy-ass": "1.5.0"
7074
}
7175
}

0 commit comments

Comments
 (0)