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.

dataset.js 601 B

2 jaren geleden
123456789101112131415161718192021222324
  1. const { readFileSync } = require('fs');
  2. const { resolve } = require('path');
  3. module.exports = {
  4. json: function(options) {
  5. return JSON.parse(this.parse(options.data));
  6. },
  7. local: function(options) {
  8. let path = this.parse(options.path);
  9. if (typeof path !== 'string') throw new Error('dataset.local: path is required.');
  10. let data = readFileSync(resolve('public', path));
  11. return JSON.parse(data);
  12. },
  13. remote: function(options) {
  14. throw new Error('dataset.remote: not implemented, use api instead.');
  15. },
  16. };