-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-name.js
32 lines (25 loc) · 925 Bytes
/
check-name.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
const Promise = require('bluebird');
const format = require('./lib/helpers.js').format;
const providers = require('./providers/');
const debug = require('debug')('runner');
const noop = Function.prototype;
function isNameAvailable(name, options, callback) {
options = options || {};
callback = callback || noop;
debug(`Checking if "${ name }" is available...`);
debug(`provided options: ${ JSON.stringify(options) }`);
return Promise.map(providers, it => {
let query = it.query;
let provider = it.provider;
return query(name, options)
.then(result => {
result.success = true;
result.provider = provider;
debug(`${ provider }: Name "${ name }" is ${ format(result.available, 'available') }`);
return result;
})
.error(err => ({ success: false, error: err, provider }));
}).asCallback(callback);
}
module.exports = isNameAvailable;