-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit allows asynchronous transformations by returning a promise. * Updates source files to add async functionality * Adds es6-promise dependency * Updates outdated dependencies * Updates README.md
- Loading branch information
Showing
10 changed files
with
147 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/coverage/ | ||
/lib/ | ||
/node_modules/ | ||
/npm-debug.log | ||
/npm-debug.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/coverage/ | ||
/src/ | ||
/test/ | ||
/.babelrc | ||
/.editorconfig | ||
/.eslintrc.yml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import {isBuffer, isString} from 'lodash'; | ||
import {Promise} from 'es6-promise'; | ||
import {isBuffer} from 'lodash'; | ||
import {err} from './err'; | ||
|
||
export function transform(fn, contents, file, opts) { | ||
let encoded = opts.encoding ? contents.toString(opts.encoding) : contents; | ||
return Promise.resolve(fn.call(opts.thisArg, encoded, file)) | ||
.then(function(transformed) { | ||
return isBuffer(transformed) ? transformed : | ||
isString(transformed) ? new Buffer(transformed) : | ||
err('transformFn must return a string or a Buffer'); | ||
}) | ||
export function transform(fn, contents, file, {encoding, thisArg}) { | ||
let decoded = encoding ? contents.toString(encoding) : contents; | ||
let transformed = fn.call(thisArg, decoded, file); | ||
|
||
return Promise.resolve(transformed).then(toBuffer); | ||
} | ||
|
||
function toBuffer(contents) { | ||
if (isBuffer(contents)) { | ||
return contents; | ||
} else if (contents != null) { | ||
return new Buffer(String(contents)); | ||
} else { | ||
err('transformFn may not return or resolve to null or undefined'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters