summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/init-package-json/test/lib/common.js
blob: de45089f9b2b32f2355505eed2c90b311030882f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module.exports.drive = drive

var semver = require('semver')

function drive (input) {
  var stdin = process.stdin
  function emit (chunk, ms) {
    setTimeout(function () {
      stdin.emit('data', chunk)
    }, ms)
  }
  if (semver.gte(process.versions.node, '0.11.0')) {
    input.forEach(function (chunk) {
      stdin.push(chunk)
    })
  } else {
    stdin.once('readable', function () {
      var ms = 0
      input.forEach(function (chunk) {
        emit(chunk, ms += 50)
      })
    })
  }
}