Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # parse-json
  2. > Parse JSON with more helpful errors
  3. ## Install
  4. ```
  5. $ npm install parse-json
  6. ```
  7. ## Usage
  8. ```js
  9. const parseJson = require('parse-json');
  10. const json = '{\n\t"foo": true,\n}';
  11. JSON.parse(json);
  12. /*
  13. undefined:3
  14. }
  15. ^
  16. SyntaxError: Unexpected token }
  17. */
  18. parseJson(json);
  19. /*
  20. JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}'
  21. 1 | {
  22. 2 | "foo": true,
  23. > 3 | }
  24. | ^
  25. */
  26. parseJson(json, 'foo.json');
  27. /*
  28. JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}' in foo.json
  29. 1 | {
  30. 2 | "foo": true,
  31. > 3 | }
  32. | ^
  33. */
  34. // You can also add the filename at a later point
  35. try {
  36. parseJson(json);
  37. } catch (error) {
  38. if (error instanceof parseJson.JSONError) {
  39. error.fileName = 'foo.json';
  40. }
  41. throw error;
  42. }
  43. /*
  44. JSONError: Unexpected token } in JSON at position 16 while parsing near '{ "foo": true,}' in foo.json
  45. 1 | {
  46. 2 | "foo": true,
  47. > 3 | }
  48. | ^
  49. */
  50. ```
  51. ## API
  52. ### parseJson(string, reviver?, filename?)
  53. Throws a `JSONError` when there is a parsing error.
  54. #### string
  55. Type: `string`
  56. #### reviver
  57. Type: `Function`
  58. Prescribes how the value originally produced by parsing is transformed, before being returned. See [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter
  59. ) for more.
  60. #### filename
  61. Type: `string`
  62. Filename displayed in the error message.
  63. ### parseJson.JSONError
  64. Exposed for `instanceof` checking.
  65. #### fileName
  66. Type: `string`
  67. The filename displayed in the error message.
  68. #### codeFrame
  69. Type: `string`
  70. The printable section of the JSON which produces the error.
  71. ---
  72. <div align="center">
  73. <b>
  74. <a href="https://tidelift.com/subscription/pkg/npm-parse-json?utm_source=npm-parse-json&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  75. </b>
  76. <br>
  77. <sub>
  78. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  79. </sub>
  80. </div>