camel.js 857 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. var test = require('tape');
  3. var camelize = require('../');
  4. var obj = {
  5. fee_fie_foe: 'fum',
  6. beep_boop: [
  7. { 'abc.xyz': 'mno' },
  8. { 'foo-bar': 'baz' }
  9. ]
  10. };
  11. test('camelize a nested object', function (t) {
  12. t.plan(1);
  13. var res = camelize(obj);
  14. t.deepEqual(res, {
  15. feeFieFoe: 'fum',
  16. beepBoop: [
  17. { abcXyz: 'mno' },
  18. { fooBar: 'baz' }
  19. ]
  20. });
  21. });
  22. test('string', function (t) {
  23. t.plan(1);
  24. t.equal(camelize('one_two'), 'oneTwo');
  25. });
  26. test('date', function (t) {
  27. t.plan(1);
  28. var d = new Date();
  29. t.equal(camelize(d), d);
  30. });
  31. test('regex', function (t) {
  32. t.plan(1);
  33. var r = /1234/;
  34. t.equal(camelize(r), r);
  35. });
  36. test('only camelize strings that are the root value', function (t) {
  37. t.plan(2);
  38. t.equal(camelize('foo-bar'), 'fooBar');
  39. var res = camelize({ 'foo-bar': 'baz-foo' });
  40. t.deepEqual(res, { fooBar: 'baz-foo' });
  41. });