index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1677462587462, function(require, module, exports) {
  8. let _fs
  9. try {
  10. _fs = require('graceful-fs')
  11. } catch (_) {
  12. _fs = require('fs')
  13. }
  14. const universalify = require('universalify')
  15. const { stringify, stripBom } = require('./utils')
  16. async function _readFile (file, options = {}) {
  17. if (typeof options === 'string') {
  18. options = { encoding: options }
  19. }
  20. const fs = options.fs || _fs
  21. const shouldThrow = 'throws' in options ? options.throws : true
  22. let data = await universalify.fromCallback(fs.readFile)(file, options)
  23. data = stripBom(data)
  24. let obj
  25. try {
  26. obj = JSON.parse(data, options ? options.reviver : null)
  27. } catch (err) {
  28. if (shouldThrow) {
  29. err.message = `${file}: ${err.message}`
  30. throw err
  31. } else {
  32. return null
  33. }
  34. }
  35. return obj
  36. }
  37. const readFile = universalify.fromPromise(_readFile)
  38. function readFileSync (file, options = {}) {
  39. if (typeof options === 'string') {
  40. options = { encoding: options }
  41. }
  42. const fs = options.fs || _fs
  43. const shouldThrow = 'throws' in options ? options.throws : true
  44. try {
  45. let content = fs.readFileSync(file, options)
  46. content = stripBom(content)
  47. return JSON.parse(content, options.reviver)
  48. } catch (err) {
  49. if (shouldThrow) {
  50. err.message = `${file}: ${err.message}`
  51. throw err
  52. } else {
  53. return null
  54. }
  55. }
  56. }
  57. async function _writeFile (file, obj, options = {}) {
  58. const fs = options.fs || _fs
  59. const str = stringify(obj, options)
  60. await universalify.fromCallback(fs.writeFile)(file, str, options)
  61. }
  62. const writeFile = universalify.fromPromise(_writeFile)
  63. function writeFileSync (file, obj, options = {}) {
  64. const fs = options.fs || _fs
  65. const str = stringify(obj, options)
  66. // not sure if fs.writeFileSync returns anything, but just in case
  67. return fs.writeFileSync(file, str, options)
  68. }
  69. const jsonfile = {
  70. readFile,
  71. readFileSync,
  72. writeFile,
  73. writeFileSync
  74. }
  75. module.exports = jsonfile
  76. }, function(modId) {var map = {"./utils":1677462587463}; return __REQUIRE__(map[modId], modId); })
  77. __DEFINE__(1677462587463, function(require, module, exports) {
  78. function stringify (obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
  79. const EOF = finalEOL ? EOL : ''
  80. const str = JSON.stringify(obj, replacer, spaces)
  81. return str.replace(/\n/g, EOL) + EOF
  82. }
  83. function stripBom (content) {
  84. // we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
  85. if (Buffer.isBuffer(content)) content = content.toString('utf8')
  86. return content.replace(/^\uFEFF/, '')
  87. }
  88. module.exports = { stringify, stripBom }
  89. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  90. return __REQUIRE__(1677462587462);
  91. })()
  92. //miniprogram-npm-outsideDeps=["graceful-fs","fs","universalify"]
  93. //# sourceMappingURL=index.js.map