apply linter
This commit is contained in:
parent
e9cb85c695
commit
5130a96edc
|
@ -3,56 +3,56 @@
|
||||||
var Minimist = require('minimist');
|
var Minimist = require('minimist');
|
||||||
|
|
||||||
class Input {
|
class Input {
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param object process
|
* @param object process
|
||||||
*/
|
*/
|
||||||
constructor(process) {
|
constructor(process) {
|
||||||
this.args = Minimist(process.argv.slice(2))
|
this.args = Minimist(process.argv.slice(2))
|
||||||
this.node = process.argv[0]
|
this.node = process.argv[0]
|
||||||
this.script = process.argv[1]
|
this.script = process.argv[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the value of the given name argument.
|
||||||
|
*
|
||||||
|
* @param string name
|
||||||
|
* @param mixed default
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
get(name, defaultValue) {
|
||||||
|
if (this.has(name)) {
|
||||||
|
return this.args[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (defaultValue !== undefined) {
|
||||||
* Return the value of the given name argument.
|
return defaultValue
|
||||||
*
|
|
||||||
* @param string name
|
|
||||||
* @param mixed default
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
get(name, defaultValue) {
|
|
||||||
if (this.has(name)) {
|
|
||||||
return this.args[name]
|
|
||||||
}
|
|
||||||
|
|
||||||
if (defaultValue !== undefined) {
|
|
||||||
return defaultValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return null;
|
||||||
* Check the given argument name exists.
|
}
|
||||||
*
|
|
||||||
* @param string name
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
has(name) {
|
|
||||||
return this.args.hasOwnProperty(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return if args is empty.
|
* Check the given argument name exists.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @param string name
|
||||||
*/
|
*
|
||||||
empty() {
|
* @return boolean
|
||||||
return Object.keys(this.args).length === 1
|
*/
|
||||||
}
|
has(name) {
|
||||||
|
return this.args.hasOwnProperty(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return if args is empty.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
empty() {
|
||||||
|
return Object.keys(this.args).length === 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Input
|
module.exports = Input
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
class Output {
|
class Output {
|
||||||
/**
|
/**
|
||||||
* Convert and print data to json.
|
* Convert and print data to json.
|
||||||
*
|
*
|
||||||
* @param mixed data
|
* @param mixed data
|
||||||
*/
|
*/
|
||||||
json(data, pretty) {
|
json(data, pretty) {
|
||||||
data = JSON.stringify(
|
data = JSON.stringify(
|
||||||
data,
|
data,
|
||||||
function(key, value) {
|
function(key, value) {
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
},
|
},
|
||||||
pretty ? 2 : null
|
pretty ? 2 : null
|
||||||
);
|
);
|
||||||
|
|
||||||
return this.write(data)
|
return this.write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print data.
|
* Print data.
|
||||||
*
|
*
|
||||||
* @param mixed data
|
* @param mixed data
|
||||||
*/
|
*/
|
||||||
write(data, level) {
|
write(data, level) {
|
||||||
level = level || 'log'
|
level = level || 'log'
|
||||||
|
|
||||||
console[level](data)
|
console[level](data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Output
|
module.exports = Output
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const filter = function(value) {
|
const filter = function(value) {
|
||||||
return value.replace(/(\n|\r)/g, '')
|
return value.replace(/(\n|\r)/g, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = filter
|
module.exports = filter
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const filter = function(value) {
|
const filter = function(value) {
|
||||||
return value.replace(/\s{2,}/g, ' ')
|
return value.replace(/\s{2,}/g, ' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = filter
|
module.exports = filter
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const striptags = require('striptags')
|
const striptags = require('striptags')
|
||||||
|
|
||||||
const filter = function(value, tags) {
|
const filter = function(value, tags) {
|
||||||
return striptags(value, tags)
|
return striptags(value, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = filter
|
module.exports = filter
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const trim = require('trim')
|
const trim = require('trim')
|
||||||
|
|
||||||
const filter = function(value) {
|
const filter = function(value) {
|
||||||
return trim(value)
|
return trim(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = filter
|
module.exports = filter
|
||||||
|
|
Loading…
Reference in a new issue