Skip to content

Commit

Permalink
function implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Escalante committed Jun 15, 2016
1 parent f7d75d5 commit f858103
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @module SpikeUtils
*/

const url = require('url')
const glob = require('glob')
const path = require('path')
const micromatch = require('micromatch')
Expand Down Expand Up @@ -140,4 +141,15 @@ module.exports = class SpikeUtils {
matchGlobs () {
return micromatch.apply(micromatch, arguments)
}

/**
* Given a loader context, resolves the path of the current file and returns
* a `File` object containing both the absolute and relative paths.
* @param {Object} context - `this` from a webpack loader
* @return {File} file object containing absolute and relative paths
*/
filePathFromLoader (loaderContext) {
const f = url.parse(loaderContext.request.split('!').slice(-1)[0]).pathname
return new File(loaderContext.context, f)
}
}

0 comments on commit f858103

Please sign in to comment.