MCPcopy Create free account
hub / github.com/microsoft/SandDance / fromObject

Function fromObject

docs/tests/v2/es6/js/sanddance.js:78654–78682  ·  view source on GitHub ↗
(that, obj)

Source from the content-addressed store, hash-verified

78652}
78653
78654function fromObject (that, obj) {
78655 if (Buffer.isBuffer(obj)) {
78656 var len = checked(obj.length) | 0
78657 that = createBuffer(that, len)
78658
78659 if (that.length === 0) {
78660 return that
78661 }
78662
78663 obj.copy(that, 0, 0, len)
78664 return that
78665 }
78666
78667 if (obj) {
78668 if ((typeof ArrayBuffer !== 'undefined' &&
78669 obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
78670 if (typeof obj.length !== 'number' || isnan(obj.length)) {
78671 return createBuffer(that, 0)
78672 }
78673 return fromArrayLike(that, obj)
78674 }
78675
78676 if (obj.type === 'Buffer' && isArray(obj.data)) {
78677 return fromArrayLike(that, obj.data)
78678 }
78679 }
78680
78681 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
78682}
78683
78684function checked (length) {
78685 // Note: cannot use `length < kMaxLength()` here because that fails when

Callers 1

fromFunction · 0.70

Calls 6

isnanFunction · 0.85
checkedFunction · 0.70
createBufferFunction · 0.70
fromArrayLikeFunction · 0.70
isArrayFunction · 0.70
copyMethod · 0.45

Tested by

no test coverage detected