MCPcopy Create free account
hub / github.com/SocketCluster/socketcluster / from

Function from

app/public/socketcluster-client.js:2733–2779  ·  view source on GitHub ↗
(value, encodingOrOffset, length)

Source from the content-addressed store, hash-verified

2731Buffer.poolSize = 8192 // not used by this implementation
2732
2733function from (value, encodingOrOffset, length) {
2734 if (typeof value === 'string') {
2735 return fromString(value, encodingOrOffset)
2736 }
2737
2738 if (ArrayBuffer.isView(value)) {
2739 return fromArrayLike(value)
2740 }
2741
2742 if (value == null) {
2743 throw TypeError(
2744 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
2745 'or Array-like Object. Received type ' + (typeof value)
2746 )
2747 }
2748
2749 if (isInstance(value, ArrayBuffer) ||
2750 (value && isInstance(value.buffer, ArrayBuffer))) {
2751 return fromArrayBuffer(value, encodingOrOffset, length)
2752 }
2753
2754 if (typeof value === 'number') {
2755 throw new TypeError(
2756 'The "value" argument must not be of type number. Received type number'
2757 )
2758 }
2759
2760 var valueOf = value.valueOf && value.valueOf()
2761 if (valueOf != null && valueOf !== value) {
2762 return Buffer.from(valueOf, encodingOrOffset, length)
2763 }
2764
2765 var b = fromObject(value)
2766 if (b) return b
2767
2768 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
2769 typeof value[Symbol.toPrimitive] === 'function') {
2770 return Buffer.from(
2771 value[Symbol.toPrimitive]('string'), encodingOrOffset, length
2772 )
2773 }
2774
2775 throw new TypeError(
2776 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
2777 'or Array-like Object. Received type ' + (typeof value)
2778 )
2779}
2780
2781/**
2782 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError

Callers 2

BufferFunction · 0.85

Calls 6

fromStringFunction · 0.85
fromArrayLikeFunction · 0.85
isInstanceFunction · 0.85
fromArrayBufferFunction · 0.85
fromObjectFunction · 0.85
fromArrayViewFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…