"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/request/lib/helpers.js" (7 Feb 2017, 1463 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 
    3 var jsonSafeStringify = require('json-stringify-safe')
    4   , crypto = require('crypto')
    5 
    6 var defer = typeof setImmediate === 'undefined'
    7   ? process.nextTick
    8   : setImmediate
    9 
   10 function paramsHaveRequestBody(params) {
   11   return (
   12     params.body ||
   13     params.requestBodyStream ||
   14     (params.json && typeof params.json !== 'boolean') ||
   15     params.multipart
   16   )
   17 }
   18 
   19 function safeStringify (obj, replacer) {
   20   var ret
   21   try {
   22     ret = JSON.stringify(obj, replacer)
   23   } catch (e) {
   24     ret = jsonSafeStringify(obj, replacer)
   25   }
   26   return ret
   27 }
   28 
   29 function md5 (str) {
   30   return crypto.createHash('md5').update(str).digest('hex')
   31 }
   32 
   33 function isReadStream (rs) {
   34   return rs.readable && rs.path && rs.mode
   35 }
   36 
   37 function toBase64 (str) {
   38   return (new Buffer(str || '', 'utf8')).toString('base64')
   39 }
   40 
   41 function copy (obj) {
   42   var o = {}
   43   Object.keys(obj).forEach(function (i) {
   44     o[i] = obj[i]
   45   })
   46   return o
   47 }
   48 
   49 function version () {
   50   var numbers = process.version.replace('v', '').split('.')
   51   return {
   52     major: parseInt(numbers[0], 10),
   53     minor: parseInt(numbers[1], 10),
   54     patch: parseInt(numbers[2], 10)
   55   }
   56 }
   57 
   58 exports.paramsHaveRequestBody = paramsHaveRequestBody
   59 exports.safeStringify         = safeStringify
   60 exports.md5                   = md5
   61 exports.isReadStream          = isReadStream
   62 exports.toBase64              = toBase64
   63 exports.copy                  = copy
   64 exports.version               = version
   65 exports.defer                 = defer