mapValue.js 685 B

123456789101112131415161718192021222324252627282930
  1. var assert = require('assert');
  2. var requireDir = require('..');
  3. var mapper = function(v, f) {
  4. if (typeof v === 'string') return v.toUpperCase();
  5. return v;
  6. };
  7. // first test without recursing:
  8. assert.deepEqual(requireDir('./recurse', { mapValue: mapper }), {
  9. a: 'A',
  10. });
  11. // then test with recursing:
  12. assert.deepEqual(requireDir('./recurse', { recurse: true, mapValue: mapper }), {
  13. a: 'A',
  14. b: {
  15. '1': {
  16. foo: 'FOO',
  17. bar: 'BAR',
  18. },
  19. '2': {} // note how the directory is always returned
  20. },
  21. c: {
  22. '3': 3
  23. },
  24. // note that node_modules was explicitly ignored
  25. });
  26. console.log('mapValue tests passed.');