util.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. }