util.d.ts 1.7 KB

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