Skip to content

Commit

Permalink
src: Inline util.promisify
Browse files Browse the repository at this point in the history
Here we implement the feature without adding an extra
dependency.
  • Loading branch information
Raynos committed Dec 19, 2019
1 parent 882ec6b commit 1adc998
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ bom = require './bom'
processors = require './processors'
setImmediate = require('timers').setImmediate
defaults = require('./defaults').defaults
promisify = require 'util.promisify'

# Underscore has a nice function for this, but we try to go without dependencies
isEmpty = (thing) ->
Expand Down Expand Up @@ -255,7 +254,12 @@ class exports.Parser extends events
throw err

parseStringPromise: (str) =>
promisify(@parseString) str
new Promise (resolve, reject) =>
@parseString str, (err, value) =>
if err
reject err
else
resolve value

exports.parseString = (str, a, b) ->
# let's determine what we got as arguments
Expand Down
9 changes: 7 additions & 2 deletions test/parser.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ util = require 'util'
assert = require 'assert'
path = require 'path'
os = require 'os'
promisify = require 'util.promisify'

fileName = path.join __dirname, '/fixtures/sample.xml'

readFilePromise = promisify fs.readFile
readFilePromise = (fileName) ->
new Promise (resolve, reject) =>
fs.readFile fileName, (err, value) =>
if err
reject err
else
resolve value

skeleton = (options, checks) ->
(test) ->
Expand Down

0 comments on commit 1adc998

Please sign in to comment.