Internal
import { mol } from "@ckb-cobuild/molecule";
const ByteOpt = mol.option("ByteOpt", mol.byte);
const BooleanOpt = ByteOpt.around({
safeParse: (input: boolean | null) => mol.parseSuccess(input),
willPack: (input: boolean | null) =>
input !== null ? (input ? 1 : 0) : null,
didUnpack: (value: number | null) => (value !== null ? value !== 0 : null),
});
Chain a parse
method before.
import { mol } from "@ckb-cobuild/molecule";
const ByteCoerce = mol.byte.beforeParse((input: any) => Number(input));
Chain a safeParse
method before.
import { mol } from "@ckb-cobuild/molecule";
const ByteCoerce = mol.byte.beforeSafeParse((input: any) => {
const result = parseInt(input);
if (!Number.isNaN(result)) {
return mol.parseSuccess(result);
}
return mol.parseError("Not a number");
});
Direct dependencies of this codec.
Pack the value and append the buffer to the provided writer.
Take the advantage of writer and append the buffer as blocks. The writer can concatenate all blocks into one buffer for the final result.
Parse a compatible input. Return a result instead of throwing.
Readonly
innerReadonly
nameName of this codec used to export .mol file.
Generated using TypeDoc
Create a new codec which shares the same underlying molecule type but with different JavaScript type.
This is useful to create a different view wrapper.