index.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Transform } from "stream";
  2. type JsonArray = boolean[] | number[] | string[] | JsonMap[] | Date[]
  3. type AnyJson = boolean | number | string | JsonMap | Date | JsonArray | JsonArray[]
  4. interface JsonMap {
  5. [key: string]: AnyJson;
  6. }
  7. interface ParseOptions {
  8. /**
  9. * The amount text to parser per pass through the event loop. Defaults to 40kb (`40000`).
  10. */
  11. blocksize: number
  12. }
  13. interface FuncParse {
  14. /**
  15. * Synchronously parse a TOML string and return an object.
  16. */
  17. (toml: string): JsonMap
  18. /**
  19. * Asynchronously parse a TOML string and return a promise of the resulting object.
  20. */
  21. async (toml: string, options?: ParseOptions): Promise<JsonMap>
  22. /**
  23. * Given a readable stream, parse it as it feeds us data. Return a promise of the resulting object.
  24. */
  25. stream (readable: NodeJS.ReadableStream): Promise<JsonMap>
  26. stream (): Transform
  27. }
  28. interface FuncStringify {
  29. /**
  30. * Serialize an object as TOML.
  31. *
  32. * If an object `TOML.stringify` is serializing has a `toJSON` method
  33. * then it will call it to transform the object before serializing it.
  34. * This matches the behavior of JSON.stringify.
  35. *
  36. * The one exception to this is that `toJSON` is not called for `Date` objects
  37. * because JSON represents dates as strings and TOML can represent them natively.
  38. *
  39. * `moment` objects are treated the same as native `Date` objects, in this respect.
  40. */
  41. (obj: JsonMap): string
  42. /**
  43. * Serialize a value as TOML would. This is a fragment and not a complete valid TOML document.
  44. */
  45. value (any: AnyJson): string
  46. }
  47. export const parse: FuncParse
  48. export const stringify: FuncStringify