[d24f17c] | 1 | import { ErrorCode } from '../errors.js';
|
---|
| 2 | import { Range } from '../nodes/Node.js';
|
---|
| 3 | import type { Scalar } from '../nodes/Scalar.js';
|
---|
| 4 | import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.js';
|
---|
| 5 | /**
|
---|
| 6 | * If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
|
---|
| 7 | * Otherwise, return `null`.
|
---|
| 8 | */
|
---|
| 9 | export declare function resolveAsScalar(token: FlowScalar | BlockScalar, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
|
---|
| 10 | value: string;
|
---|
| 11 | type: Scalar.Type | null;
|
---|
| 12 | comment: string;
|
---|
| 13 | range: Range;
|
---|
| 14 | };
|
---|
| 15 | export declare function resolveAsScalar(token: Token | null | undefined, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
|
---|
| 16 | value: string;
|
---|
| 17 | type: Scalar.Type | null;
|
---|
| 18 | comment: string;
|
---|
| 19 | range: Range;
|
---|
| 20 | } | null;
|
---|
| 21 | /**
|
---|
| 22 | * Create a new scalar token with `value`
|
---|
| 23 | *
|
---|
| 24 | * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
|
---|
| 25 | * as this function does not support any schema operations and won't check for such conflicts.
|
---|
| 26 | *
|
---|
| 27 | * @param value The string representation of the value, which will have its content properly indented.
|
---|
| 28 | * @param context.end Comments and whitespace after the end of the value, or after the block scalar header. If undefined, a newline will be added.
|
---|
| 29 | * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
|
---|
| 30 | * @param context.indent The indent level of the token.
|
---|
| 31 | * @param context.inFlow Is this scalar within a flow collection? This may affect the resolved type of the token's value.
|
---|
| 32 | * @param context.offset The offset position of the token.
|
---|
| 33 | * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
|
---|
| 34 | */
|
---|
| 35 | export declare function createScalarToken(value: string, context: {
|
---|
| 36 | end?: SourceToken[];
|
---|
| 37 | implicitKey?: boolean;
|
---|
| 38 | indent: number;
|
---|
| 39 | inFlow?: boolean;
|
---|
| 40 | offset?: number;
|
---|
| 41 | type?: Scalar.Type;
|
---|
| 42 | }): BlockScalar | FlowScalar;
|
---|
| 43 | /**
|
---|
| 44 | * Set the value of `token` to the given string `value`, overwriting any previous contents and type that it may have.
|
---|
| 45 | *
|
---|
| 46 | * Best efforts are made to retain any comments previously associated with the `token`,
|
---|
| 47 | * though all contents within a collection's `items` will be overwritten.
|
---|
| 48 | *
|
---|
| 49 | * Values that represent an actual string but may be parsed as a different type should use a `type` other than `'PLAIN'`,
|
---|
| 50 | * as this function does not support any schema operations and won't check for such conflicts.
|
---|
| 51 | *
|
---|
| 52 | * @param token Any token. If it does not include an `indent` value, the value will be stringified as if it were an implicit key.
|
---|
| 53 | * @param value The string representation of the value, which will have its content properly indented.
|
---|
| 54 | * @param context.afterKey In most cases, values after a key should have an additional level of indentation.
|
---|
| 55 | * @param context.implicitKey Being within an implicit key may affect the resolved type of the token's value.
|
---|
| 56 | * @param context.inFlow Being within a flow collection may affect the resolved type of the token's value.
|
---|
| 57 | * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
|
---|
| 58 | */
|
---|
| 59 | export declare function setScalarValue(token: Token, value: string, context?: {
|
---|
| 60 | afterKey?: boolean;
|
---|
| 61 | implicitKey?: boolean;
|
---|
| 62 | inFlow?: boolean;
|
---|
| 63 | type?: Scalar.Type;
|
---|
| 64 | }): void;
|
---|