Skip to content

Commit bfdb96d

Browse files
committed
added babel, eslint pebblecode, version of node, ignore lib dir for transpiled js
1 parent d21de21 commit bfdb96d

File tree

7 files changed

+155
-143
lines changed

7 files changed

+155
-143
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/

.eslintrc

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"extends": "airbnb"
2+
"extends": "pebblecode",
3+
"rules": {
4+
// disable requiring trailing commas because it might be nice to revert to
5+
// being JSON at some point, and I don't want to make big changes now.
6+
"comma-dangle": [2, "never"]
7+
}
38
}

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
language: node_js
22
node_js:
33
- "0.10"
4+
- "4.x"

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
},
3131
"license": "MIT",
3232
"dependencies": {
33+
"eslint-config-pebblecode": "file:../../pebblecode-styleguide/packages/eslint-config-pebblecode",
3334
"map-obj": "^1.0.0"
3435
},
3536
"devDependencies": {
3637
"babel": "^5.x.x",
3738
"babel-eslint": "^4.1.5",
3839
"chai": "^2.1.1",
3940
"eslint": "^1.9.0",
40-
"eslint-config-airbnb": "^1.0.0",
41+
"eslint-config-pebblecode": "^1.0.0",
4142
"eslint-plugin-react": "^3.8.0",
4243
"istanbul": "^0.4.0",
4344
"mocha": "^2.2.1",

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ const isObject = (v) => typeof(v) === 'object';
44

55
const camelCase = (str) => str.replace(/[_.-](\w|$)/g, (_, x) => x.toUpperCase());
66

7+
const bob = {
8+
name: 'bob'
9+
};
10+
11+
bob.name = 'tim';
712

813
function camelCaseRecursive(obj) {
914
return mapObj(obj, (key, val) => {

test/index.js

+139-141
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,141 @@
1-
'use strict';
2-
3-
var expect = require('chai').expect;
4-
5-
var camelCaseKeys = require('../');
6-
7-
describe('Nested keys within arrays and objects are camelCased', function() {
8-
9-
it('Should camelCase all Snake keys', function() {
10-
11-
var anotherCamelWithTheHump = camelCaseKeys({
12-
'test-1': 123,
13-
'test-Two': [{
14-
'test-three': {
15-
'test-FOUR': [{
16-
'test-five': [{
17-
'test-six': {
18-
'test-seven': [1, 4, [1, 2, '3', 'four', 'five-one']]
19-
}
20-
}]
21-
}]
22-
}
23-
}]
24-
});
25-
26-
expect(anotherCamelWithTheHump).deep.equals({
27-
test1: 123,
28-
testTwo: [{
29-
testThree: {
30-
testFOUR: [{
31-
testFive: [{
32-
testSix: {
33-
testSeven: [1, 4, [1, 2, '3', 'four', 'five-one']]
34-
}
35-
}]
36-
}]
37-
}
38-
}]
39-
});
40-
41-
});
42-
43-
it('Should camelCase all Snake keys - with nulls', function() {
44-
45-
var anotherCamelWithTheHump = camelCaseKeys({
46-
'test-1': null,
47-
'test-Two': [{
48-
'test-three': {
49-
'test-FOUR': [{
50-
'test-five': [{
51-
'test-six': {
52-
'test-seven': [1, 4, [1, undefined, '3', 'four', 'five-one']]
53-
}
54-
}]
55-
}]
56-
}
57-
}]
58-
});
59-
60-
expect(anotherCamelWithTheHump).deep.equals({
61-
test1: null,
62-
testTwo: [{
63-
testThree: {
64-
testFOUR: [{
65-
testFive: [{
66-
testSix: {
67-
testSeven: [1, 4, [1, undefined, '3', 'four', 'five-one']]
68-
}
69-
}]
70-
}]
71-
}
72-
}]
73-
});
74-
75-
});
76-
77-
it('Should handle date values', function(){
78-
79-
var expected = {
80-
createdAt:'2015-09-24T13:44:41.553Z'
81-
};
82-
83-
var input = {
84-
created_at:'2015-09-24T13:44:41.553Z'
85-
};
86-
87-
expect(expected).deep.equals(camelCaseKeys(input));
88-
89-
});
90-
91-
it('Should handle date within objects', function(){
92-
var expected = {
93-
store: {
94-
total: '210.00',
95-
count: '1'
96-
},
97-
user: {
98-
lastOrder: {
99-
id: '1',
100-
status: 3,
101-
userId: '82',
102-
customerId: '6100',
103-
storeId: '12',
104-
externalId: '2015-09-22T14:38:01.201Z',
105-
createdAt: '2015-09-24T13:44:41.553Z',
106-
price: '210.00',
107-
pricePaid: '210.00',
108-
currencyIso: 'GBP',
109-
details: null,
110-
deleted: false
111-
}
112-
}
113-
};
114-
115-
var input = {
116-
store: {
117-
total: '210.00',
118-
count: '1'
119-
},
120-
user: {
121-
lastOrder: {
122-
id: '1',
123-
status: 3,
124-
user_id: '82',
125-
customer_id: '6100',
126-
store_id: '12',
127-
external_id: '2015-09-22T14:38:01.201Z',
128-
created_at: '2015-09-24T13:44:41.553Z',
129-
price: '210.00',
130-
price_paid: '210.00',
131-
currency_iso: 'GBP',
132-
details: null,
133-
deleted: false
134-
}
135-
}
136-
};
137-
138-
expect(expected).deep.equals(camelCaseKeys(input));
139-
140-
141-
});
1+
import {expect} from 'chai';
2+
3+
const camelCaseKeys = require('../');
4+
5+
describe('Nested keys within arrays and objects are camelCased', () => {
6+
7+
it('Should camelCase all Snake keys', () => {
8+
9+
const anotherCamelWithTheHump = camelCaseKeys({
10+
'test-1': 123,
11+
'test-Two': [{
12+
'test-three': {
13+
'test-FOUR': [{
14+
'test-five': [{
15+
'test-six': {
16+
'test-seven': [1, 4, [1, 2, '3', 'four', 'five-one']]
17+
}
18+
}]
19+
}]
20+
}
21+
}]
22+
});
23+
24+
expect(anotherCamelWithTheHump).deep.equals({
25+
test1: 123,
26+
testTwo: [{
27+
testThree: {
28+
testFOUR: [{
29+
testFive: [{
30+
testSix: {
31+
testSeven: [1, 4, [1, 2, '3', 'four', 'five-one']]
32+
}
33+
}]
34+
}]
35+
}
36+
}]
37+
});
38+
39+
});
40+
41+
it('Should camelCase all Snake keys - with nulls', () => {
42+
43+
const anotherCamelWithTheHump = camelCaseKeys({
44+
'test-1': null,
45+
'test-Two': [{
46+
'test-three': {
47+
'test-FOUR': [{
48+
'test-five': [{
49+
'test-six': {
50+
'test-seven': [1, 4, [1, undefined, '3', 'four', 'five-one']]
51+
}
52+
}]
53+
}]
54+
}
55+
}]
56+
});
57+
58+
expect(anotherCamelWithTheHump).deep.equals({
59+
test1: null,
60+
testTwo: [{
61+
testThree: {
62+
testFOUR: [{
63+
testFive: [{
64+
testSix: {
65+
testSeven: [1, 4, [1, undefined, '3', 'four', 'five-one']]
66+
}
67+
}]
68+
}]
69+
}
70+
}]
71+
});
72+
73+
});
74+
75+
it('Should handle date values', () => {
76+
77+
const expected = {
78+
createdAt: '2015-09-24T13:44:41.553Z'
79+
};
80+
81+
const input = {
82+
created_at: '2015-09-24T13:44:41.553Z'
83+
};
84+
85+
expect(expected).deep.equals(camelCaseKeys(input));
86+
87+
});
88+
89+
it('Should handle date within objects', () => {
90+
const expected = {
91+
store: {
92+
total: '210.00',
93+
count: '1'
94+
},
95+
user: {
96+
lastOrder: {
97+
id: '1',
98+
status: 3,
99+
userId: '82',
100+
customerId: '6100',
101+
storeId: '12',
102+
externalId: '2015-09-22T14:38:01.201Z',
103+
createdAt: '2015-09-24T13:44:41.553Z',
104+
price: '210.00',
105+
pricePaid: '210.00',
106+
currencyIso: 'GBP',
107+
details: null,
108+
deleted: false
109+
}
110+
}
111+
};
112+
113+
const input = {
114+
store: {
115+
total: '210.00',
116+
count: '1'
117+
},
118+
user: {
119+
lastOrder: {
120+
id: '1',
121+
status: 3,
122+
user_id: '82',
123+
customer_id: '6100',
124+
store_id: '12',
125+
external_id: '2015-09-22T14:38:01.201Z',
126+
created_at: '2015-09-24T13:44:41.553Z',
127+
price: '210.00',
128+
price_paid: '210.00',
129+
currency_iso: 'GBP',
130+
details: null,
131+
deleted: false
132+
}
133+
}
134+
};
135+
136+
expect(expected).deep.equals(camelCaseKeys(input));
137+
138+
139+
});
142140

143141
});

0 commit comments

Comments
 (0)