MCPcopy Create free account
hub / github.com/RubyLouvre/anu / fromObject

Function fromObject

test/babel.js:45980–46007  ·  view source on GitHub ↗
(that, obj)

Source from the content-addressed store, hash-verified

45978 }
45979
45980 function fromObject(that, obj) {
45981 if (Buffer.isBuffer(obj)) {
45982 var len = checked(obj.length) | 0;
45983 that = createBuffer(that, len);
45984
45985 if (that.length === 0) {
45986 return that;
45987 }
45988
45989 obj.copy(that, 0, 0, len);
45990 return that;
45991 }
45992
45993 if (obj) {
45994 if (typeof ArrayBuffer !== 'undefined' && obj.buffer instanceof ArrayBuffer || 'length' in obj) {
45995 if (typeof obj.length !== 'number' || isnan(obj.length)) {
45996 return createBuffer(that, 0);
45997 }
45998 return fromArrayLike(that, obj);
45999 }
46000
46001 if (obj.type === 'Buffer' && isArray(obj.data)) {
46002 return fromArrayLike(that, obj.data);
46003 }
46004 }
46005
46006 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.');
46007 }
46008
46009 function checked(length) {
46010 // Note: cannot use `length < kMaxLength()` here because that fails when

Callers 1

fromFunction · 0.85

Calls 5

checkedFunction · 0.85
createBufferFunction · 0.85
isnanFunction · 0.85
fromArrayLikeFunction · 0.85
isArrayFunction · 0.85

Tested by

no test coverage detected