Skip to content

Commit f495954

Browse files
committedFeb 17, 2020
chore: prettier changes
1 parent e4180ba commit f495954

7 files changed

+53
-55
lines changed
 

‎example.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var object = {
44
a: {
55
b: {
66
c: 1,
7-
d: [1,2,3],
7+
d: [1, 2, 3],
88
e: 'remy'
99
}
1010
}

‎lib/undefsafe.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
function undefsafe(obj, path, value, __res) {
4-
54
// I'm not super keen on this private function, but it's because
65
// it'll also be use in the browser and I wont *one* function exposed
76
function split(path) {
@@ -19,7 +18,8 @@ function undefsafe(obj, path, value, __res) {
1918
c = path.substr(i, 1);
2019
}
2120

22-
if (key) { // the first value could be a string
21+
if (key) {
22+
// the first value could be a string
2323
res.push(key);
2424
}
2525
key = '';
@@ -51,9 +51,12 @@ function undefsafe(obj, path, value, __res) {
5151
var root = obj;
5252
var parent = obj;
5353

54-
var star = parts.filter(function (_) { return _ === '*' }).length > 0;
54+
var star =
55+
parts.filter(function(_) {
56+
return _ === '*';
57+
}).length > 0;
5558

56-
// we're dealing with a primative
59+
// we're dealing with a primitive
5760
if (type !== 'object' && type !== 'function') {
5861
return obj;
5962
} else if (path.trim() === '') {
@@ -72,9 +75,14 @@ function undefsafe(obj, path, value, __res) {
7275
var res = __res || [];
7376

7477
for (prop in parent) {
75-
var shallowObj = undefsafe(obj[prop], parts.slice(i + 1).join('.'), value, res);
78+
var shallowObj = undefsafe(
79+
obj[prop],
80+
parts.slice(i + 1).join('.'),
81+
value,
82+
res
83+
);
7684
if (shallowObj && shallowObj !== res) {
77-
if ((value && shallowObj === value) || (value === undefined)) {
85+
if ((value && shallowObj === value) || value === undefined) {
7886
if (value !== undefined) {
7987
return shallowObj;
8088
}

‎package.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"cover": "tap test/*.test.js --cov --coverage-report=lcov",
1212
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
1313
},
14+
"prettier": {
15+
"trailingComma": "none",
16+
"singleQuote": true
17+
},
1418
"repository": {
1519
"type": "git",
1620
"url": "https://github.com/remy/undefsafe.git"

‎test/array.test.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@
22
var test = require('tap').test;
33
var undefsafe = require('../lib/undefsafe');
44

5-
test('get specific array index', function (t) {
5+
test('get specific array index', function(t) {
66
var fixture = {
7-
a: [1,2,3,4]
7+
a: [1, 2, 3, 4]
88
};
99

1010
var res = undefsafe(fixture, 'a.2');
1111
t.equal(res, 3);
1212
t.end();
1313
});
1414

15-
test('set specific array index', function (t) {
15+
test('set specific array index', function(t) {
1616
var fixture = {
17-
a: [1,2,3,4]
17+
a: [1, 2, 3, 4]
1818
};
1919

2020
undefsafe(fixture, 'a.2', 30);
21-
t.deepEqual(fixture, { a: [1,2,30,4] });
21+
t.deepEqual(fixture, { a: [1, 2, 30, 4] });
2222
t.end();
2323
});
24-

‎test/set.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var test = require('tap').test;
33
var undefsafe = require('../lib/undefsafe');
44

5-
test('setting deep object values', function (t) {
5+
test('setting deep object values', function(t) {
66
var fixture = {
77
a: {
88
b: {
@@ -14,11 +14,11 @@ test('setting deep object values', function (t) {
1414
};
1515

1616
undefsafe(fixture, 'a.b.c.d', 20);
17-
t.equal(fixture.a.b.c.d, 20, 'deep primative changed');
17+
t.equal(fixture.a.b.c.d, 20, 'deep primitive changed');
1818
t.end();
1919
});
2020

21-
test('setting shallow object values', function (t) {
21+
test('setting shallow object values', function(t) {
2222
var fixture = {
2323
a: {
2424
b: {
@@ -34,7 +34,7 @@ test('setting shallow object values', function (t) {
3434
t.end();
3535
});
3636

37-
test('undef value', function (t) {
37+
test('undef value', function(t) {
3838
var fixture = {
3939
a: {
4040
b: {
@@ -50,7 +50,7 @@ test('undef value', function (t) {
5050
t.end();
5151
});
5252

53-
test('missing value', function (t) {
53+
test('missing value', function(t) {
5454
var fixture = {
5555
a: {
5656
b: {

‎test/star-rule.test.js

+10-19
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,53 @@
22
var test = require('tap-only');
33
var undefsafe = require('../lib/undefsafe');
44
var fixture = {
5-
"commits": [
5+
commits: [
66
{
7-
"modified": [
8-
"one",
9-
"two"
10-
]
7+
modified: ['one', 'two']
118
},
129
{
13-
"modified": [
14-
"two",
15-
"four"
16-
]
10+
modified: ['two', 'four']
1711
}
1812
]
1913
};
2014

21-
test('2.0.0: match all.*', function (t) {
15+
test('2.0.0: match all.*', function(t) {
2216
var res = undefsafe(fixture, '*.*.*.1');
2317
t.deepEqual(res, ['two', 'four']);
2418
t.end();
2519
});
2620

27-
28-
test('2.0.0: match all.*', function (t) {
21+
test('2.0.0: match all.*', function(t) {
2922
var res = undefsafe(fixture, 'commits.*.modified.*.b');
3023
t.deepEqual(res, ['one', 'two', 'two', 'four']);
3124
t.end();
3225
});
3326

34-
35-
test('get value on first * selector', function (t) {
27+
test('get value on first * selector', function(t) {
3628
var res = undefsafe(fixture, 'commits.*.modified.0');
3729
t.deepEqual(res, ['one', 'two']);
3830
t.end();
3931
});
4032

41-
test('walking multiple routes', function (t) {
33+
test('walking multiple routes', function(t) {
4234
var res = undefsafe(fixture, 'commits.*.modified.*', 'four');
4335
t.equal(res, 'four');
4436
t.end();
4537
});
4638

47-
48-
test('get specific match * selector', function (t) {
39+
test('get specific match * selector', function(t) {
4940
var res = undefsafe(fixture, 'commits.*.modified.*', 'two');
5041
t.equal(res, 'two');
5142
t.end();
5243
});
5344

54-
test('match * selector returns undefined', function (t) {
45+
test('match * selector returns undefined', function(t) {
5546
var res = undefsafe(fixture, 'commits.*.modified.*', 'three');
5647
t.equal(res, undefined);
5748
t.end();
5849
});
5950

60-
test('match * selector works on objects', function (t) {
51+
test('match * selector works on objects', function(t) {
6152
var res = undefsafe(fixture, '*.*.modified.*', 'one');
6253
t.equal(res, 'one');
6354
t.end();

‎test/undefsafe.test.js

+14-18
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
var test = require('tap-only');
33
var undefsafe = require('../lib/undefsafe');
44

5-
test('should handle primatives', function (t) {
5+
test('should handle primatives', function(t) {
66
var r = undefsafe(1, '');
77
t.equal(r, 1, 'undefsafe is 1: ' + r);
88
t.end();
99
});
1010

11-
test('should handle null', function (t) {
11+
test('should handle null', function(t) {
1212
var r = undefsafe(null, 'foo');
1313
t.equal(r, undefined, 'undefsafe works with null');
1414
t.end();
1515
});
1616

17-
test('should handle empty objects', function (t) {
17+
test('should handle empty objects', function(t) {
1818
var value = {};
1919
var r;
2020

@@ -30,11 +30,11 @@ test('should handle empty objects', function (t) {
3030
t.end();
3131
});
3232

33-
test('should handle null properties', function (t) {
33+
test('should handle null properties', function(t) {
3434
var value = {
3535
a: {
36-
b: null,
37-
},
36+
b: null
37+
}
3838
};
3939
var r;
4040

@@ -47,7 +47,7 @@ test('should handle null properties', function (t) {
4747
t.end();
4848
});
4949

50-
test('should find properties with periods in them', function (t) {
50+
test('should find properties with periods in them', function(t) {
5151
var value = {
5252
a: { 'one.two': true }
5353
};
@@ -63,10 +63,7 @@ test('should find properties with periods in them', function (t) {
6363
t.equal(r, true, 'weird: ' + r);
6464

6565
value = {
66-
a: { 'one.two.and\three': [
67-
false,
68-
true,
69-
] }
66+
a: { 'one.two.and\three': [false, true] }
7067
};
7168

7269
r = undefsafe(value, `a['one.two.and\three'].1`);
@@ -82,23 +79,22 @@ test('should find properties with periods in them', function (t) {
8279
t.end();
8380
});
8481

85-
86-
test('should find deep object properties', function (t) {
82+
test('should find deep object properties', function(t) {
8783
var value = {
8884
a: {
8985
b: {
9086
c: {
9187
d: 10,
9288
e: {
93-
f: 20,
89+
f: 20
9490
},
9591
g: true,
9692
h: false,
9793
i: undefined,
98-
j: null,
99-
},
100-
},
101-
},
94+
j: null
95+
}
96+
}
97+
}
10298
};
10399
var r;
104100

0 commit comments

Comments
 (0)
Please sign in to comment.