Skip to content

Commit 7af3228

Browse files
authored
Update dev dependencies and files names (#25)
1 parent 3c1f7dd commit 7af3228

14 files changed

+2094
-9320
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["es2015"]
2+
"presets": ["@babel/preset-env"]
33
}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
coverage
2+
coverage
3+
settings.json

__tests__/ScaledSheet.spec.js

+80-78
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,97 @@
11
jest.mock('react-native');
2-
import { scale, verticalScale, moderateScale } from '../lib/scalingUtils';
2+
import { scale, verticalScale, moderateScale } from '../lib/scaling-utils';
33
import ScaledSheet from '../lib/ScaledSheet';
44

55
const getRandomInt = (min = 1, max = 100) => Math.floor(Math.random() * (max - min + 1)) + min;
66

7-
test('Scale works', () => {
8-
const number = getRandomInt();
9-
const input = { test: `${number}@s` }
10-
expect(ScaledSheet.create(input).test).toBe(scale(number));
11-
});
7+
describe('ScaledSheet', () => {
8+
test('Scale works', () => {
9+
const number = getRandomInt();
10+
const input = { test: `${number}@s` }
11+
expect(ScaledSheet.create(input).test).toBe(scale(number));
12+
});
1213

13-
test('verticalScale works', () => {
14-
const number = getRandomInt();
15-
const input = { test: `${number}@vs` }
16-
expect(ScaledSheet.create(input).test).toBe(verticalScale(number));
17-
});
14+
test('verticalScale works', () => {
15+
const number = getRandomInt();
16+
const input = { test: `${number}@vs` }
17+
expect(ScaledSheet.create(input).test).toBe(verticalScale(number));
18+
});
1819

19-
test('moderateScale with default factor works', () => {
20-
const number = getRandomInt();
21-
const input = { test: `${number}@ms` }
22-
expect(ScaledSheet.create(input).test).toBe(moderateScale(number));
23-
});
20+
test('moderateScale with default factor works', () => {
21+
const number = getRandomInt();
22+
const input = { test: `${number}@ms` }
23+
expect(ScaledSheet.create(input).test).toBe(moderateScale(number));
24+
});
2425

25-
test('moderateScale with custom factor works', () => {
26-
const number = getRandomInt();
27-
const input = { test: `${number}@ms0.7` }
28-
expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.7));
29-
});
26+
test('moderateScale with custom factor works', () => {
27+
const number = getRandomInt();
28+
const input = { test: `${number}@ms0.7` }
29+
expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.7));
30+
});
3031

31-
test('Scale works with a negative value', () => {
32-
const number = getRandomInt(-100, -1);
33-
const input = { test: `${number}@s` }
34-
expect(ScaledSheet.create(input).test).toBe(scale(number));
35-
});
32+
test('Scale works with a negative value', () => {
33+
const number = getRandomInt(-100, -1);
34+
const input = { test: `${number}@s` }
35+
expect(ScaledSheet.create(input).test).toBe(scale(number));
36+
});
3637

37-
test('moderateScale works with a negative value', () => {
38-
const number = getRandomInt(-100, -1);
39-
const input = { test: `${number}@ms0.3` }
40-
expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.3));
41-
});
38+
test('moderateScale works with a negative value', () => {
39+
const number = getRandomInt(-100, -1);
40+
const input = { test: `${number}@ms0.3` }
41+
expect(ScaledSheet.create(input).test).toBe(moderateScale(number, 0.3));
42+
});
4243

43-
test('Scale works on a deeply nested object', () => {
44-
const number = getRandomInt();
45-
const input = { test: { test: { test: `${number}@s` } } }
46-
expect(ScaledSheet.create(input).test.test.test).toBe(scale(number));
47-
});
44+
test('Scale works on a deeply nested object', () => {
45+
const number = getRandomInt();
46+
const input = { test: { test: { test: `${number}@s` } } }
47+
expect(ScaledSheet.create(input).test.test.test).toBe(scale(number));
48+
});
4849

49-
test('No special annotation should leave the number intact', () => {
50-
const number = getRandomInt();
51-
const input = { test: number }
52-
expect(ScaledSheet.create(input).test).toBe(number);
53-
});
50+
test('No special annotation should leave the number intact', () => {
51+
const number = getRandomInt();
52+
const input = { test: number }
53+
expect(ScaledSheet.create(input).test).toBe(number);
54+
});
5455

55-
test('ScaledSheet should map a complete StyleSheet with special annotations', () => {
56-
const input = {
57-
container: {
58-
width: '30@s',
59-
height: '50@vs',
60-
margin: {
61-
width: 12,
62-
height: '12@s',
63-
paddingBottom: -1
56+
test('ScaledSheet should map a complete StyleSheet with special annotations', () => {
57+
const input = {
58+
container: {
59+
width: '30@s',
60+
height: '50@vs',
61+
margin: {
62+
width: 12,
63+
height: '12@s',
64+
paddingBottom: -1
65+
}
66+
},
67+
row: {
68+
padding: '[email protected]',
69+
height: '34@ms',
70+
marginRight: '[email protected]',
71+
marginLeft: '[email protected]',
72+
marginTop: '-10@s',
6473
}
65-
},
66-
row: {
67-
padding: '[email protected]',
68-
height: '34@ms',
69-
marginRight: '[email protected]',
70-
marginLeft: '[email protected]',
71-
marginTop: '-10@s',
72-
}
73-
};
74+
};
7475

75-
const expectedOutput = {
76-
container: {
77-
width: scale(30),
78-
height: verticalScale(50),
79-
margin: {
80-
width: 12,
81-
height: scale(12),
82-
paddingBottom: -1
76+
const expectedOutput = {
77+
container: {
78+
width: scale(30),
79+
height: verticalScale(50),
80+
margin: {
81+
width: 12,
82+
height: scale(12),
83+
paddingBottom: -1
84+
}
85+
},
86+
row: {
87+
padding: moderateScale(10, 0.3),
88+
height: moderateScale(34),
89+
marginRight: moderateScale(0.5, 0.9),
90+
marginLeft: moderateScale(-0.5, 0.9),
91+
marginTop: scale(-10),
8392
}
84-
},
85-
row: {
86-
padding: moderateScale(10, 0.3),
87-
height: moderateScale(34),
88-
marginRight: moderateScale(0.5, 0.9),
89-
marginLeft: moderateScale(-0.5, 0.9),
90-
marginTop: scale(-10),
91-
}
92-
};
93+
};
9394

94-
expect(JSON.stringify(ScaledSheet.create(input))).toBe(JSON.stringify(expectedOutput));
95-
});
95+
expect(JSON.stringify(ScaledSheet.create(input))).toBe(JSON.stringify(expectedOutput));
96+
});
97+
})

__tests__/deep-map.spec.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import deepMap from '../lib/deep-map';
2+
3+
const add3 = x => x + 3;
4+
5+
describe('deep-map', () => {
6+
test('returns value if it\'s not an object or array', () => {
7+
expect(deepMap(5, add3)).toBe(5);
8+
expect(deepMap(true, add3)).toBe(true);
9+
expect(deepMap(null, add3)).toBe(null);
10+
expect(deepMap(undefined, add3)).toBe(undefined);
11+
expect(deepMap('string', add3)).toBe('string');
12+
});
13+
14+
test('maps non-nested object', () => {
15+
expect(JSON.stringify(deepMap({ a: 5 }, add3))).toBe(JSON.stringify({ a: 8 }));
16+
});
17+
18+
test('maps nested object', () => {
19+
const input = { a: { b: { d: 1, e: 2 }, c: 3, f: { g: 4 } } };
20+
const expectedOutput = { a: { b: { d: 1 + 3, e: 2 + 3 }, c: 3 + 3, f: { g: 4 + 3 } } };
21+
22+
expect(JSON.stringify(deepMap(input, add3))).toBe(JSON.stringify(expectedOutput));
23+
});
24+
25+
test('maps array', () => {
26+
const input = [1, 2, 3, 4];
27+
const expectedOutput = [4, 5, 6, 7];
28+
29+
expect(JSON.stringify(deepMap(input, add3))).toBe(JSON.stringify(expectedOutput));
30+
});
31+
32+
test('maps object within array', () => {
33+
const input = [1, 2, 3, { a: 10 }];
34+
const expectedOutput = [4, 5, 6, { a: 13 }];
35+
36+
expect(JSON.stringify(deepMap(input, add3))).toBe(JSON.stringify(expectedOutput));
37+
});
38+
39+
test('maps array within object', () => {
40+
const input = { a: [1, 2, 3] };
41+
const expectedOutput = { a: [4, 5, 6] };
42+
43+
expect(JSON.stringify(deepMap(input, add3))).toBe(JSON.stringify(expectedOutput));
44+
});
45+
});

__tests__/deepMap.spec.js

-43
This file was deleted.

__tests__/scaling-utils.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
jest.mock('react-native');
2+
import { scale, verticalScale, moderateScale } from '../lib/scaling-utils';
3+
4+
describe('scaling-utils', () => {
5+
test('scale returns the expected result based on mocked Dimensions', () => {
6+
expect(scale(2.5)).toBe(5);
7+
expect(scale(100)).toBe(200);
8+
expect(scale(200)).toBe(400);
9+
});
10+
11+
test('verticalScale returns the expected result based on mocked Dimensions', () => {
12+
expect(verticalScale(5)).toBe(7.5);
13+
expect(verticalScale(100)).toBe(150);
14+
expect(verticalScale(200)).toBe(300);
15+
});
16+
17+
test('moderateScale returns the expected result based on mocked Dimensions', () => {
18+
expect(moderateScale(100)).toBe(150);
19+
expect(moderateScale(100, 0.1)).toBe(110);
20+
expect(moderateScale(100, 0.3)).toBe(130);
21+
expect(moderateScale(100, 0.6)).toBe(160);
22+
expect(moderateScale(100, 0.9)).toBe(190);
23+
expect(moderateScale(100, 2)).toBe(300);
24+
});
25+
})

__tests__/scalingUtils.spec.js

-23
This file was deleted.

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { default as ScaledSheet } from './lib/ScaledSheet';
2-
export { moderateScale, scale, verticalScale } from './lib/scalingUtils';
2+
export { moderateScale, scale, verticalScale } from './lib/scaling-utils';

lib/ScaledSheet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StyleSheet } from 'react-native';
2-
import { moderateScale, scale, verticalScale } from './scalingUtils';
3-
import deepMap from './deepMap';
2+
import { moderateScale, scale, verticalScale } from './scaling-utils';
3+
import deepMap from './deep-map';
44

55
const validScaleSheetRegex = /^(\-?\d+(\.\d{1,2})?)@(ms(\d+(\.\d{1,2})?)?|s|vs)$/;
66
const scaleRegex = /^(\-?\d+(\.\d{1,2})?)@s$/;
File renamed without changes.

lib/scalingUtils.js renamed to lib/scaling-utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Dimensions } from 'react-native';
2+
23
const { width, height } = Dimensions.get('window');
34
const [shortDimension, longDimension] = width < height ? [width, height] : [height, width];
45

5-
//Guideline sizes are based on standard ~5" screen mobile device
6+
//Default guideline sizes are based on standard ~5" screen mobile device
67
const guidelineBaseWidth = 350;
78
const guidelineBaseHeight = 680;
89

0 commit comments

Comments
 (0)