Skip to content

Commit bded4a9

Browse files
committed
Refactor to adhere to strict jsdoc style
1 parent 40a2f7b commit bded4a9

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

index.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
'use strict';
22

33
/**
4+
* A property--value pair tuple.
5+
*
6+
* @typedef {Array} Pair
7+
* @typedef {string} Pair.0
8+
* @typedef {string} Pair.1
9+
*/
10+
11+
/*
412
* Cached methods.
513
*/
614

@@ -14,15 +22,13 @@ has = Object.prototype.hasOwnProperty;
1422
* @param {string} token
1523
* @return {function(string): string}
1624
*/
17-
1825
function stripComments(token) {
1926
/**
2027
* Strip comments.
2128
*
2229
* @param {string} value - Line.
2330
* @return {string} Value with comments removed.
2431
*/
25-
2632
return function (value) {
2733
var index;
2834

@@ -43,7 +49,6 @@ function stripComments(token) {
4349
* @return {string} Value with initial and final white
4450
* space removed.
4551
*/
46-
4752
function trimWhiteSpace(value) {
4853
return value.trim();
4954
}
@@ -54,7 +59,6 @@ function trimWhiteSpace(value) {
5459
* @param {string} value
5560
* @return {boolean}
5661
*/
57-
5862
function isNonEmpty(value) {
5963
return Boolean(value);
6064
}
@@ -63,18 +67,15 @@ function isNonEmpty(value) {
6367
* Factory to transform lines to property--value tuples.
6468
*
6569
* @param {string} token
66-
* @return {function(string): {0: string, 1: string}}
70+
* @return {function(string): Pair}
6771
*/
68-
6972
function toPropertyValuePairs(token) {
7073
/**
7174
* Transform `value` to a property--value tuple.
7275
*
7376
* @param {string} value - Line.
74-
* @return {{0: string, 1: string}} Array with
75-
* property at `0` and value at `1`.
77+
* @return {Pair}
7678
*/
77-
7879
return function (value) {
7980
var values,
8081
result;
@@ -95,21 +96,20 @@ function toPropertyValuePairs(token) {
9596
*
9697
* To be passed to `Array#sort()`.
9798
*
98-
* @param {{0: *}} a
99-
* @param {{0: *}} b
99+
* @param {Pair} a
100+
* @param {Pair} b
101+
* @return {number}
100102
*/
101-
102103
function sortOnFirstIndex(a, b) {
103104
return a[0].charCodeAt(0) - b[0].charCodeAt(0);
104105
}
105106

106107
/**
107-
* Transform a list of key--value tuples to an object.
108+
* Transform a list of property--value tuples to an object.
108109
*
109-
* @param {Array.<{0: string, 1: string}>} pairs
110+
* @param {Array.<Pair>} pairs
110111
* @return {Object.<string, string>}
111112
*/
112-
113113
function propertyValuePairsToObject(pairs) {
114114
var values;
115115

@@ -126,10 +126,13 @@ function propertyValuePairsToObject(pairs) {
126126
* Transform a string into an array or object of values.
127127
*
128128
* @param {string} value
129-
* @param {Object?} options
129+
* @param {?Object} options
130+
* @param {?boolean} options.log
131+
* @param {?(string|boolean)} options.comment
132+
* @param {?(string|boolean)} options.delimiter
133+
* @param {?(string|boolean)} options.fix
130134
* @return {Object.<string, string>|Array.<string>}
131135
*/
132-
133136
function textToJSON(value, options) {
134137
var propertyOrValues,
135138
lines,

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ describe('Values', function () {
247247

248248
log = console.log;
249249

250+
/**
251+
* Spy to detect if a function is invoked.
252+
*/
250253
global.console.log = function () {
251254
isCalled = true;
252255
};
@@ -274,6 +277,9 @@ describe('Values', function () {
274277
log = console.log;
275278

276279
/* istanbul ignore next */
280+
/**
281+
* Spy to detect if a function is invoked.
282+
*/
277283
global.console.log = function () {
278284
isCalled = true;
279285
};
@@ -328,6 +334,9 @@ describe('Property-value pairs', function () {
328334

329335
log = console.log;
330336

337+
/**
338+
* Spy to detect if a function is invoked.
339+
*/
331340
global.console.log = function () {
332341
isCalled = true;
333342
};
@@ -355,6 +364,9 @@ describe('Property-value pairs', function () {
355364
log = console.log;
356365

357366
/* istanbul ignore next */
367+
/**
368+
* Spy to detect if a function is invoked.
369+
*/
358370
global.console.log = function () {
359371
isCalled = true;
360372
};
@@ -418,6 +430,9 @@ describe('Property-value pairs', function () {
418430

419431
log = console.log;
420432

433+
/**
434+
* Spy to detect if a function is invoked.
435+
*/
421436
global.console.log = function () {
422437
isCalled = true;
423438
};
@@ -445,6 +460,9 @@ describe('Property-value pairs', function () {
445460
log = console.log;
446461

447462
/* istanbul ignore next */
463+
/**
464+
* Spy to detect if a function is invoked.
465+
*/
448466
global.console.log = function () {
449467
isCalled = true;
450468
};

0 commit comments

Comments
 (0)