mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
* Add --ts-undefined-for-optionals command line option # Details - Fixes #7656 - Added a new `--ts-undefined-for-optionals` command line option for `flatc`. - If enabled, generated TypeScript code uses `undefined` for optional fields rather than `null`. * Also add TS generated test files * Run `sh scripts/clang-format-git.sh` * also add tests/ts/lalala-options.ts to the repo * move new tests to tests/ts/optional_values dir * add tests/ts/optional_values/optional_values_generated.cjs to the repo * reuse existing optional_scalars.fbs and add new test * add comma * sh scripts/clang-format-git.sh * remove comma * sh scripts/clang-format-git.sh * trying things * sh scripts/clang-format-git.sh * done * address feedback * sh scripts/clang-format-git.sh * run `sh scripts/clang-format-git.sh` * remove uneeded `eslint-disable @typescript-eslint/no-namespace` line --------- Co-authored-by: José Luis Millán <jmillan@aliax.net>
29 lines
677 B
TypeScript
29 lines
677 B
TypeScript
import {Builder} from './flexbuffers/builder.js';
|
|
import {toReference} from './flexbuffers/reference.js';
|
|
export {toReference} from './flexbuffers/reference.js';
|
|
|
|
export function builder(): Builder {
|
|
return new Builder();
|
|
}
|
|
|
|
export function toObject(buffer: ArrayBuffer): unknown {
|
|
return toReference(buffer).toObject();
|
|
}
|
|
|
|
export function encode(
|
|
object: unknown,
|
|
size = 2048,
|
|
deduplicateStrings = true,
|
|
deduplicateKeys = true,
|
|
deduplicateKeyVectors = true,
|
|
): Uint8Array {
|
|
const builder = new Builder(
|
|
size > 0 ? size : 2048,
|
|
deduplicateStrings,
|
|
deduplicateKeys,
|
|
deduplicateKeyVectors,
|
|
);
|
|
builder.add(object);
|
|
return builder.finish();
|
|
}
|