Documentation / @sw-file-lib/xml / xml-schema / BooleanSchema
Class: BooleanSchema
class BooleanSchema {
constructor();
readonly name: "boolean";
safeParseValue(input: SchemaInput, _ctx: SchemaParseContext, _options?: SchemaParseOptions): Result<boolean, SchemaError>;
parseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): boolean;
safeParseField(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions): SchemaParseFieldAttributeResult<boolean>;
serializeField(value: unknown): SchemaSerializeResult;
optional(): OptionalSchema<BooleanSchema>;
}Defined in: packages/xml/src/xml-schema/classes/boolean.ts:26
A schema that parses XML attribute values as booleans.
The XML strings "true" and "false" are accepted. Serialization writes booleans back as those same strings.
Implements
Schema<boolean>
Constructors
Constructor
new BooleanSchema(): BooleanSchema;Returns
BooleanSchema
Properties
name
readonly name: "boolean" = "boolean";Defined in: packages/xml/src/xml-schema/classes/boolean.ts:27
Implementation of
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
_ctx: SchemaParseContext,
_options?: SchemaParseOptions): Result<boolean, SchemaError>;Defined in: packages/xml/src/xml-schema/classes/boolean.ts:29
Parses a Stormworks XML node or attribute value without throwing schema errors.
This is a low-level operation used by schema implementations. For parsing a full XML tree, prefer ElementSchema.safeParse.
Parameters
| Parameter | Type |
|---|---|
input | SchemaInput |
_ctx | SchemaParseContext |
_options? | SchemaParseOptions |
Returns
Result<boolean, SchemaError>
Implementation of
parseValue()
parseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): boolean;Defined in: packages/xml/src/xml-schema/classes/boolean.ts:53
Parses a Stormworks XML node or attribute value.
This is a low-level operation used by schema implementations. For parsing a full XML tree, prefer ElementSchema.parse.
Parameters
| Parameter | Type |
|---|---|
input | SchemaInput |
ctx | SchemaParseContext |
options? | SchemaParseOptions |
Returns
boolean
Throws
SchemaError when the value does not match the schema.
Implementation of
safeParseField()
safeParseField(
parent: SwXmlNode,
key: string,
ctx: SchemaParseContext,
options?: SchemaParseOptions): SchemaParseFieldAttributeResult<boolean>;Defined in: packages/xml/src/xml-schema/classes/boolean.ts:57
Parses one field from an XML record node.
Primitive schemas read attributes. Element schemas read child elements.
This is primarily intended for schema implementations. Most callers should use ElementSchema.safeParse on a top-level element schema instead.
Parameters
| Parameter | Type |
|---|---|
parent | SwXmlNode |
key | string |
ctx | SchemaParseContext |
options? | SchemaParseOptions |
Returns
SchemaParseFieldAttributeResult<boolean>
Implementation of
serializeField()
serializeField(value: unknown): SchemaSerializeResult;Defined in: packages/xml/src/xml-schema/classes/boolean.ts:74
Serializes one field without throwing.
This is primarily intended for schema implementations. Most callers should use ElementSchema.safeSerialize or ElementSchema.serialize on a top-level element schema instead.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
Implementation of
optional()
optional(): OptionalSchema<BooleanSchema>;Defined in: packages/xml/src/xml-schema/classes/boolean.ts:85
Returns a schema that accepts undefined values.
Returns
OptionalSchema<BooleanSchema>