UNPKG

1 kBPlain TextView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4import { RpcTypedData } from '@azure/functions-core';
5
6export function toRpcTypedData(data: unknown): RpcTypedData | null | undefined {
7 if (data === null || data === undefined) {
8 return data;
9 } else if (typeof data === 'string') {
10 return { string: data };
11 } else if (Buffer.isBuffer(data)) {
12 return { bytes: data };
13 } else if (ArrayBuffer.isView(data)) {
14 const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
15 return { bytes: bytes };
16 } else if (data instanceof ArrayBuffer) {
17 const bytes = new Uint8Array(data);
18 return { bytes: bytes };
19 } else if (typeof data === 'number') {
20 if (Number.isInteger(data)) {
21 return { int: data };
22 } else {
23 return { double: data };
24 }
25 } else {
26 return { json: JSON.stringify(data) };
27 }
28}