util.d.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { Document } from './index'
  2. import { CST } from './parse-cst'
  3. import { AST, Pair, Scalar, Schema } from './types'
  4. export function findPair(items: any[], key: Scalar | any): Pair | undefined
  5. export function parseMap(doc: Document, cst: CST.Map): AST.BlockMap
  6. export function parseMap(doc: Document, cst: CST.FlowMap): AST.FlowMap
  7. export function parseSeq(doc: Document, cst: CST.Seq): AST.BlockSeq
  8. export function parseSeq(doc: Document, cst: CST.FlowSeq): AST.FlowSeq
  9. export function stringifyNumber(item: Scalar): string
  10. export function stringifyString(
  11. item: Scalar,
  12. ctx: Schema.StringifyContext,
  13. onComment?: () => void,
  14. onChompKeep?: () => void
  15. ): string
  16. export function toJSON(
  17. value: any,
  18. arg?: any,
  19. ctx?: Schema.CreateNodeContext
  20. ): any
  21. export enum Type {
  22. ALIAS = 'ALIAS',
  23. BLANK_LINE = 'BLANK_LINE',
  24. BLOCK_FOLDED = 'BLOCK_FOLDED',
  25. BLOCK_LITERAL = 'BLOCK_LITERAL',
  26. COMMENT = 'COMMENT',
  27. DIRECTIVE = 'DIRECTIVE',
  28. DOCUMENT = 'DOCUMENT',
  29. FLOW_MAP = 'FLOW_MAP',
  30. FLOW_SEQ = 'FLOW_SEQ',
  31. MAP = 'MAP',
  32. MAP_KEY = 'MAP_KEY',
  33. MAP_VALUE = 'MAP_VALUE',
  34. PLAIN = 'PLAIN',
  35. QUOTE_DOUBLE = 'QUOTE_DOUBLE',
  36. QUOTE_SINGLE = 'QUOTE_SINGLE',
  37. SEQ = 'SEQ',
  38. SEQ_ITEM = 'SEQ_ITEM'
  39. }
  40. interface LinePos {
  41. line: number
  42. col: number
  43. }
  44. export class YAMLError extends Error {
  45. name:
  46. | 'YAMLReferenceError'
  47. | 'YAMLSemanticError'
  48. | 'YAMLSyntaxError'
  49. | 'YAMLWarning'
  50. message: string
  51. source?: CST.Node
  52. nodeType?: Type
  53. range?: CST.Range
  54. linePos?: { start: LinePos; end: LinePos }
  55. /**
  56. * Drops `source` and adds `nodeType`, `range` and `linePos`, as well as
  57. * adding details to `message`. Run automatically for document errors if
  58. * the `prettyErrors` option is set.
  59. */
  60. makePretty(): void
  61. }
  62. export class YAMLReferenceError extends YAMLError {
  63. name: 'YAMLReferenceError'
  64. }
  65. export class YAMLSemanticError extends YAMLError {
  66. name: 'YAMLSemanticError'
  67. }
  68. export class YAMLSyntaxError extends YAMLError {
  69. name: 'YAMLSyntaxError'
  70. }
  71. export class YAMLWarning extends YAMLError {
  72. name: 'YAMLWarning'
  73. }