Sha256: 50f1b86132ea1a7acda9b48b69016c7623660efad2c79b554bd30c78286f3bf5

Contents?: true

Size: 1.38 KB

Versions: 38

Compression:

Stored size: 1.38 KB

Contents

'use strict'

var jsonSafeStringify = require('json-stringify-safe')
var crypto = require('crypto')
var Buffer = require('safe-buffer').Buffer

var defer = typeof setImmediate === 'undefined'
  ? process.nextTick
  : setImmediate

function paramsHaveRequestBody (params) {
  return (
    params.body ||
    params.requestBodyStream ||
    (params.json && typeof params.json !== 'boolean') ||
    params.multipart
  )
}

function safeStringify (obj, replacer) {
  var ret
  try {
    ret = JSON.stringify(obj, replacer)
  } catch (e) {
    ret = jsonSafeStringify(obj, replacer)
  }
  return ret
}

function md5 (str) {
  return crypto.createHash('md5').update(str).digest('hex')
}

function isReadStream (rs) {
  return rs.readable && rs.path && rs.mode
}

function toBase64 (str) {
  return Buffer.from(str || '', 'utf8').toString('base64')
}

function copy (obj) {
  var o = {}
  Object.keys(obj).forEach(function (i) {
    o[i] = obj[i]
  })
  return o
}

function version () {
  var numbers = process.version.replace('v', '').split('.')
  return {
    major: parseInt(numbers[0], 10),
    minor: parseInt(numbers[1], 10),
    patch: parseInt(numbers[2], 10)
  }
}

exports.paramsHaveRequestBody = paramsHaveRequestBody
exports.safeStringify = safeStringify
exports.md5 = md5
exports.isReadStream = isReadStream
exports.toBase64 = toBase64
exports.copy = copy
exports.version = version
exports.defer = defer

Version data entries

38 entries across 31 versions & 14 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/request/lib/helpers.js
disco_app-0.18.0 test/dummy/node_modules/request/lib/helpers.js
disco_app-0.18.2 test/dummy/node_modules/request/lib/helpers.js
tang-0.2.1 spec/tang_app/node_modules/request/lib/helpers.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/request/lib/helpers.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/request/lib/helpers.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/request/lib/helpers.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/request/lib/helpers.js
tang-0.2.0 spec/tang_app/node_modules/request/lib/helpers.js
tang-0.1.0 spec/tang_app/node_modules/request/lib/helpers.js
tang-0.0.9 spec/tang_app/node_modules/request/lib/helpers.js
enju_library-0.3.8 spec/dummy/node_modules/request/lib/helpers.js
ilog-0.4.1 node_modules/node-gyp/node_modules/request/lib/helpers.js
ilog-0.4.1 node_modules/node-sass/node_modules/request/lib/helpers.js
ilog-0.4.0 node_modules/node-gyp/node_modules/request/lib/helpers.js
ilog-0.4.0 node_modules/node-sass/node_modules/request/lib/helpers.js
ilog-0.3.3 node_modules/node-sass/node_modules/request/lib/helpers.js
ilog-0.3.3 node_modules/node-gyp/node_modules/request/lib/helpers.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/request/lib/helpers.js
jester-data-8.0.0 node_modules/request/lib/helpers.js