Skip to content

Documentation / @sw-file-lib/xml / xml-schema / BooleanSchema

Class: BooleanSchema ​

ts
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 ​

Constructors ​

Constructor ​

ts
new BooleanSchema(): BooleanSchema;

Returns ​

BooleanSchema

Properties ​

name ​

ts
readonly name: "boolean" = "boolean";

Defined in: packages/xml/src/xml-schema/classes/boolean.ts:27

Implementation of ​

Schema.name

Methods ​

safeParseValue() ​

ts
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 ​

ParameterType
inputSchemaInput
_ctxSchemaParseContext
_options?SchemaParseOptions

Returns ​

Result<boolean, SchemaError>

Implementation of ​

Schema.safeParseValue


parseValue() ​

ts
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 ​

ParameterType
inputSchemaInput
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

boolean

Throws ​

SchemaError when the value does not match the schema.

Implementation of ​

Schema.parseValue


safeParseField() ​

ts
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 ​

ParameterType
parentSwXmlNode
keystring
ctxSchemaParseContext
options?SchemaParseOptions

Returns ​

SchemaParseFieldAttributeResult<boolean>

Implementation of ​

Schema.safeParseField


serializeField() ​

ts
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 ​

ParameterType
valueunknown

Returns ​

SchemaSerializeResult

Implementation of ​

Schema.serializeField


optional() ​

ts
optional(): OptionalSchema<BooleanSchema>;

Defined in: packages/xml/src/xml-schema/classes/boolean.ts:85

Returns a schema that accepts undefined values.

Returns ​

OptionalSchema<BooleanSchema>

Implementation of ​

Schema.optional