Sha256: a8ac40dd3c7279c6d7f859fcf3f3b73584f810ddc98da15d72baadf5c1a4b534

Contents?: true

Size: 1.22 KB

Versions: 35

Compression:

Stored size: 1.22 KB

Contents

var util = require('../core').util;

function typeOf(data) {
  if (data === null && typeof data === 'object') {
    return 'null';
  } else if (data !== undefined && isBinary(data)) {
    return 'Binary';
  } else if (data !== undefined && data.constructor) {
    return util.typeName(data.constructor);
  } else if (data !== undefined && typeof data === 'object') {
    // this object is the result of Object.create(null), hence the absence of a
    // defined constructor
    return 'Object';
  } else {
    return 'undefined';
  }
}

function isBinary(data) {
  var types = [
    'Buffer', 'File', 'Blob', 'ArrayBuffer', 'DataView',
    'Int8Array', 'Uint8Array', 'Uint8ClampedArray',
    'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array',
    'Float32Array', 'Float64Array'
  ];
  if (util.isNode()) {
    var Stream = util.stream.Stream;
    if (util.Buffer.isBuffer(data) || data instanceof Stream) {
      return true;
    }
  }

  for (var i = 0; i < types.length; i++) {
    if (data !== undefined && data.constructor) {
      if (util.isType(data, types[i])) return true;
      if (util.typeName(data.constructor) === types[i]) return true;
    }
  }

  return false;
}

module.exports = {
  typeOf: typeOf,
  isBinary: isBinary
};

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
sumomo-0.10.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.10.4 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.10.3 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.10.2 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.10.1 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.10.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.9.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.22 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.21 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.20 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.17 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.16 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.15 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.14 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.13 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.12 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.11 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.10 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.9 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js
sumomo-0.8.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/types.js