Skip to content

Commit 39acc86

Browse files
Refactored utility functions
1 parent c0f79bc commit 39acc86

2 files changed

Lines changed: 38 additions & 34 deletions

File tree

lib/util/index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var debug = require('debug');
4+
5+
exports.path = require('./path');
6+
7+
/**
8+
* Writes messages to stdout.
9+
* Log messages are suppressed by default, but can be enabled by setting the DEBUG variable.
10+
* @type {function}
11+
*/
12+
exports.debug = debug('json-schema-ref-parser');
13+
14+
/**
15+
* Asynchronously invokes the given callback function with the given parameters.
16+
*
17+
* @param {function|undefined} callback
18+
* @param {*} [err]
19+
* @param {...*} [params]
20+
*/
21+
exports.doCallback = function doCallback(callback, err, params) {
22+
if (typeof(callback) === 'function') {
23+
var args = Array.prototype.slice.call(arguments, 1);
24+
25+
/* istanbul ignore if: code-coverage doesn't run in the browser */
26+
if (process.browser) {
27+
process.nextTick(invokeCallback);
28+
}
29+
else {
30+
setImmediate(invokeCallback);
31+
}
32+
}
33+
34+
function invokeCallback() {
35+
callback.apply(null, args);
36+
}
37+
};

lib/util.js renamed to lib/util/path.js

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

3-
var debug = require('debug'),
4-
protocolPattern = /^[a-z0-9.+-]+:\/\//i;
5-
6-
/**
7-
* Writes messages to stdout.
8-
* Log messages are suppressed by default, but can be enabled by setting the DEBUG variable.
9-
* @type {function}
10-
*/
11-
exports.debug = debug('json-schema-ref-parser');
3+
var protocolPattern = /^[a-z0-9.+-]+:\/\//i;
124

135
/**
146
* Returns the current working directory (in Node) or the current page URL (in browsers).
@@ -70,28 +62,3 @@ exports.extname = function extname(path) {
7062
}
7163
return '';
7264
};
73-
74-
/**
75-
* Asynchronously invokes the given callback function with the given parameters.
76-
*
77-
* @param {function|undefined} callback
78-
* @param {*} [err]
79-
* @param {...*} [params]
80-
*/
81-
exports.doCallback = function doCallback(callback, err, params) {
82-
if (typeof(callback) === 'function') {
83-
var args = Array.prototype.slice.call(arguments, 1);
84-
85-
/* istanbul ignore if: code-coverage doesn't run in the browser */
86-
if (process.browser) {
87-
process.nextTick(invokeCallback);
88-
}
89-
else {
90-
setImmediate(invokeCallback);
91-
}
92-
}
93-
94-
function invokeCallback() {
95-
callback.apply(null, args);
96-
}
97-
};

0 commit comments

Comments
 (0)