All Projects → xpl → get-source

xpl / get-source

Licence: MIT license
Fetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to get-source

reverse-enginnering
open source repository
Stars: ✭ 29 (+11.54%)
Mutual labels:  source, source-code
android-source-codes
⚙️ Code analysis of common Android projects and components.
Stars: ✭ 59 (+126.92%)
Mutual labels:  source-code, source-code-analysis
Django Source
django 源码剖析
Stars: ✭ 20 (-23.08%)
Mutual labels:  source, source-code
babel-plugin-source-map-support
A Babel plugin which automatically makes stack traces source-map aware
Stars: ✭ 41 (+57.69%)
Mutual labels:  sourcemaps, sourcemap
objc-runtime-CN
Objective-C Runtime Analysis (Objective-C运行时分析)
Stars: ✭ 28 (+7.69%)
Mutual labels:  source-code, source-code-analysis
Joustmania
Raspberry Pi Jousting at its finest
Stars: ✭ 91 (+250%)
Mutual labels:  source
Windowsxp
This is the leaked source code of Windows XP Service Pack 1
Stars: ✭ 164 (+530.77%)
Mutual labels:  source
Openwallet Android
The first truly free, libre, and open source light wallet for multiple cryptocurrencies (Bitcoin, Ethereum, Ripple, etc).
Stars: ✭ 86 (+230.77%)
Mutual labels:  source
Bob
🚰 binary data "streams+" via data producers, data consumers, and pull flow.
Stars: ✭ 68 (+161.54%)
Mutual labels:  source
opensource
Collection of Open Source packages by Otherwise
Stars: ✭ 21 (-19.23%)
Mutual labels:  source
Pubg mobile memory hacking examples
Pubg Mobile Emulator Gameloop Memory Hacking C++ code examples. Ex: Name, Coord, Bones, Weapons, Items, Box, Drop etc.
Stars: ✭ 224 (+761.54%)
Mutual labels:  source
Lapidus
Stream your PostgreSQL, MySQL or MongoDB databases anywhere, fast.
Stars: ✭ 145 (+457.69%)
Mutual labels:  source
Shellfuncs
Python API to execute shell functions as they would be Python functions
Stars: ✭ 96 (+269.23%)
Mutual labels:  source
Mongo Kafka
MongoDB Kafka Connector
Stars: ✭ 166 (+538.46%)
Mutual labels:  source
Async Gamequery Lib
A high-performance java game query library designed for steam/source based games and others
Stars: ✭ 88 (+238.46%)
Mutual labels:  source
Gradle License Plugin
Gradle plugin that provides a task to generate a HTML license report of your project.
Stars: ✭ 246 (+846.15%)
Mutual labels:  source
Montreal
A directory of companies, people, and projects that are Open Source and from Montréal.
Stars: ✭ 77 (+196.15%)
Mutual labels:  source
Coc Sources
Additional common sources of coc.nvim
Stars: ✭ 135 (+419.23%)
Mutual labels:  source
Develop Source
Open source for developer.(开发资源整理:Java,Android,算法,iOS,MacOS等等)
Stars: ✭ 219 (+742.31%)
Mutual labels:  source
Ffmpeg
Automated scripts for installation of ffmpeg and its most popular libraries from source under Ubuntu and a detailed wiki containing a lot of hints and tricks for ffmpeg.
Stars: ✭ 126 (+384.62%)
Mutual labels:  source

get-source

Build Status Coverage Status npm

Fetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.

npm install get-source

Features

  • Allows to read source code files in Node and browsers
  • Full sourcemap support (path resolving, external/embedded/inline linking, and long chains)
  • Synchronous API — good for CLI tools (e.g. logging). Works in browsers!
  • Asynchronous API — good for everything web!
  • Built-in cache

What For

Usage (Synchronous)

import getSource from 'get-source'
file = getSource ('./scripts/index.min.js')

Will read the file synchronously (either via XHR or by filesystem API, depending on the environment) and return it's cached representation. Result will contain the following fields:

file.path  // normalized file path
file.text  // text contents
file.lines // array of lines

And the resolve method:

file.resolve ({ line: 1, column: 8 }) // indexes here start from 1 (by widely accepted convention). Zero indexes are invalid.

It will look through the sourcemap chain, returning following:

{
   line:       <original line number>,
   column:     <original column number>,
   sourceFile: <original source file object>,
   sourceLine: <original source line text>
}

In that returned object, sourceFile is the same kind of object that getSource returns. So you can access its text, lines and path fields to obtain the full information. And the sourceLine is returned just for the convenience, as a shortcut.

Usage (Asynchronous)

Pretty much the same as synchronous, except it's getSource.async. It returns awaitable promises:

file     = await getSource.async ('./scripts/index.min.js')
location = await file.resolve ({ line: 1, column: 8 })

Error Handling

In synchronous mode, it never throws (due to backward compatibility reasons with existing code):

nonsense = getSource ('/some/nonexistent/file')

nonsense.text  // should be '' (so it's safe to access without checking)
nonsense.error // should be an Error object, representing an actual error thrown during reading/parsing
resolved = nonsense.resolve ({ line: 5, column: 0 })

resolved.sourceLine // empty string (so it's safe to access without checking)
resolved.error      // should be an Error object, representing an actual error thrown during reading/parsing

In asychronous mode, it throws an error:

try { 
   file     = await getSource.async ('/some/file')
   location = await file.resolve ({ line: 5, column: 0 })
} catch (e) {
   ...
}

Resetting Cache

E.g. when you need to force-reload files:

getSource.resetCache ()        // sync cache
getSource.async.resetCache ()  // async cache

Also, viewing cached files:

getSource.getCache ()        // sync cache
getSource.async.getCache ()  // async cache
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].