Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 29, 2018
1 parent 26975b0 commit 75114c7
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 371 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage/
lancaster-stemmer.js
lancaster-stemmer.min.js
83 changes: 41 additions & 42 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
#!/usr/bin/env node
'use strict';
'use strict'

var pack = require('./package.json');
var stemmer = require('.');
var pack = require('./package.json')
var stemmer = require('.')

var argv = process.argv.slice(2);
var argv = process.argv.slice(2)

if (
argv.indexOf('--help') !== -1 ||
argv.indexOf('-h') !== -1
) {
console.log(help());
} else if (
argv.indexOf('--version') !== -1 ||
argv.indexOf('-v') !== -1
) {
console.log(pack.version);
if (argv.indexOf('--help') !== -1 || argv.indexOf('-h') !== -1) {
console.log(help())
} else if (argv.indexOf('--version') !== -1 || argv.indexOf('-v') !== -1) {
console.log(pack.version)
} else if (argv.length === 0) {
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (data) {
console.log(stem(data));
});
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', function(data) {
console.log(stem(data))
})
} else {
console.log(stem(argv.join(' ')));
console.log(stem(argv.join(' ')))
}

function stem(values) {
return values.split(/\s+/g).map(stemmer).join(' ');
return values
.split(/\s+/g)
.map(stemmer)
.join(' ')
}

function help() {
return [
'',
'Usage: ' + pack.name + ' [options] <words...>',
'',
pack.description,
'',
'Options:',
'',
' -h, --help output usage information',
' -v, --version output version number',
'',
'Usage:',
'',
'# output stems',
'$ ' + pack.name + ' considerations',
stem('considerations'),
'',
'# output stems from stdin',
'$ echo "detestable vileness" | ' + pack.name,
stem('detestable vileness')
].join('\n ') + '\n';
return (
[
'',
'Usage: ' + pack.name + ' [options] <words...>',
'',
pack.description,
'',
'Options:',
'',
' -h, --help output usage information',
' -v, --version output version number',
'',
'Usage:',
'',
'# output stems',
'$ ' + pack.name + ' considerations',
stem('considerations'),
'',
'# output stems from stdin',
'$ echo "detestable vileness" | ' + pack.name,
stem('detestable vileness')
].join('\n ') + '\n'
)
}
Loading

0 comments on commit 75114c7

Please sign in to comment.