版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

55 wiersze
1.4 KiB

  1. /**
  2. * @since 2.10.0
  3. */
  4. import { Either } from './Either'
  5. /**
  6. * @since 2.10.0
  7. */
  8. export declare type Json = boolean | number | string | null | JsonArray | JsonRecord
  9. /**
  10. * @since 2.10.0
  11. */
  12. export interface JsonRecord {
  13. readonly [key: string]: Json
  14. }
  15. /**
  16. * @since 2.10.0
  17. */
  18. export interface JsonArray extends ReadonlyArray<Json> {}
  19. /**
  20. * Converts a JavaScript Object Notation (JSON) string into a `Json` type.
  21. *
  22. * @example
  23. * import * as J from 'fp-ts/Json'
  24. * import * as E from 'fp-ts/Either'
  25. * import { pipe } from 'fp-ts/function'
  26. *
  27. * assert.deepStrictEqual(pipe('{"a":1}', J.parse), E.right({ a: 1 }))
  28. * assert.deepStrictEqual(pipe('{"a":}', J.parse), E.left(new SyntaxError('Unexpected token } in JSON at position 5')))
  29. *
  30. * @since 2.10.0
  31. */
  32. export declare const parse: (s: string) => Either<unknown, Json>
  33. /**
  34. * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
  35. *
  36. * @example
  37. * import * as E from 'fp-ts/Either'
  38. * import * as J from 'fp-ts/Json'
  39. * import { pipe } from 'fp-ts/function'
  40. *
  41. * assert.deepStrictEqual(J.stringify({ a: 1 }), E.right('{"a":1}'))
  42. * const circular: any = { ref: null }
  43. * circular.ref = circular
  44. * assert.deepStrictEqual(
  45. * pipe(
  46. * J.stringify(circular),
  47. * E.mapLeft(e => e instanceof Error && e.message.includes('Converting circular structure to JSON'))
  48. * ),
  49. * E.left(true)
  50. * )
  51. *
  52. * @since 2.10.0
  53. */
  54. export declare const stringify: <A>(a: A) => Either<unknown, string>