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

Function from

docs/app/js/sanddance-app.js:112939–112952  ·  view source on GitHub ↗
(value, encodingOrOffset, length)

Source from the content-addressed store, hash-verified

112937Buffer.poolSize = 8192 // not used by this implementation
112938;
112939function from(value, encodingOrOffset, length) {
112940 if (typeof value === "string") return fromString(value, encodingOrOffset);
112941 if (ArrayBuffer.isView(value)) return fromArrayView(value);
112942 if (value == null) throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
112943 if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) return fromArrayBuffer(value, encodingOrOffset, length);
112944 if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) return fromArrayBuffer(value, encodingOrOffset, length);
112945 if (typeof value === "number") throw new TypeError('The "value" argument must not be of type number. Received type number');
112946 var valueOf = value.valueOf && value.valueOf();
112947 if (valueOf != null && valueOf !== value) return Buffer.from(valueOf, encodingOrOffset, length);
112948 var b = fromObject(value);
112949 if (b) return b;
112950 if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") return Buffer.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length);
112951 throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value);
112952}
112953/**
112954 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
112955 * if value is a number.

Callers 2

BufferFunction · 0.70
sanddance-app.jsFile · 0.70

Calls 7

fromStringFunction · 0.70
fromArrayViewFunction · 0.70
isInstanceFunction · 0.70
fromArrayBufferFunction · 0.70
fromObjectFunction · 0.70
valueOfMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected