Documentation / @sw-file-lib/xml / xml-schema / NumberSchema
Class: NumberSchema
class NumberSchema {
constructor();
readonly name: "number";
safeParseValue(input: SchemaInput, _ctx: SchemaParseContext, options?: SchemaParseOptions): Result<number, SchemaError>;
parseValue(input: SchemaInput, ctx: SchemaParseContext, options?: SchemaParseOptions): number;
safeParseField(parent: SwXmlNode, key: string, ctx: SchemaParseContext, options?: SchemaParseOptions): SchemaParseFieldAttributeResult<number>;
serializeField(value: unknown): SchemaSerializeResult;
optional(): OptionalSchema<NumberSchema>;
}Defined in: packages/xml/src/xml-schema/classes/number.ts:26
A schema that parses XML attribute values as numbers.
Values are parsed with JavaScript's Number conversion. NaN is rejected unless SchemaParseOptions.allowNaN is enabled.
Implements
Schema<number>
Constructors
Constructor
new NumberSchema(): NumberSchema;Returns
NumberSchema
Properties
name
readonly name: "number" = "number";Defined in: packages/xml/src/xml-schema/classes/number.ts:27
Implementation of
Methods
safeParseValue()
safeParseValue(
input: SchemaInput,
_ctx: SchemaParseContext,
options?: SchemaParseOptions): Result<number, SchemaError>;Defined in: packages/xml/src/xml-schema/classes/number.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<number, SchemaError>
Implementation of
parseValue()
parseValue(
input: SchemaInput,
ctx: SchemaParseContext,
options?: SchemaParseOptions): number;Defined in: packages/xml/src/xml-schema/classes/number.ts:56
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
number
Throws
SchemaError when the value does not match the schema.
Implementation of
safeParseField()
safeParseField(
parent: SwXmlNode,
key: string,
ctx: SchemaParseContext,
options?: SchemaParseOptions): SchemaParseFieldAttributeResult<number>;Defined in: packages/xml/src/xml-schema/classes/number.ts:60
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<number>
Implementation of
serializeField()
serializeField(value: unknown): SchemaSerializeResult;Defined in: packages/xml/src/xml-schema/classes/number.ts:77
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<NumberSchema>;Defined in: packages/xml/src/xml-schema/classes/number.ts:85
Returns a schema that accepts undefined values.
Returns
OptionalSchema<NumberSchema>