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 value into a molecule buffer.
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.
Parse a compatible input. Return a result instead of throwing.
Unpack the value from the molecule buffer.
Optional
strict: booleanwhehter to allow unknown fields in the buffer. True to enable. It is off by default.
Readonly
innerReadonly
nameName of this codec used to export .mol file.
Readonly
tagReadonly
tagGenerated 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.