camel.js 955 B

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