-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
515 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage/ | ||
metaphone.js | ||
metaphone.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,58 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
'use strict' | ||
|
||
var pack = require('./package.json'); | ||
var metaphone = require('.'); | ||
var pack = require('./package.json') | ||
var metaphone = 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(phonetics(data)); | ||
}); | ||
process.stdin.resume() | ||
process.stdin.setEncoding('utf8') | ||
process.stdin.on('data', function(data) { | ||
console.log(phonetics(data)) | ||
}) | ||
} else { | ||
console.log(phonetics(argv.join(' '))); | ||
console.log(phonetics(argv.join(' '))) | ||
} | ||
|
||
function phonetics(values) { | ||
return values.split(/\s+/g).map(metaphone).join(' '); | ||
return values | ||
.split(/\s+/g) | ||
.map(metaphone) | ||
.join(' ') | ||
} | ||
|
||
function help() { | ||
return [ | ||
'', | ||
'Usage: ' + pack.name + ' [options] <words...>', | ||
'', | ||
pack.description, | ||
'', | ||
'Options:', | ||
'', | ||
' -h, --help output usage information', | ||
' -v, --version output version number', | ||
'', | ||
'Usage:', | ||
'', | ||
'# output phonetics', | ||
'$ ' + pack.name + ' considerations detestable', | ||
'# ' + phonetics('considerations detestable'), | ||
'', | ||
'# output phonetics from stdin', | ||
'$ echo \'hiccups vileness\' | ' + pack.name, | ||
'# ' + phonetics('hiccups vileness'), | ||
'', | ||
'# with stemmer', | ||
'$ echo \'vileness\' | stemmer | ' + pack.name, | ||
'# ' + phonetics('vile') | ||
].join('\n ') + '\n'; | ||
return ( | ||
[ | ||
'', | ||
'Usage: ' + pack.name + ' [options] <words...>', | ||
'', | ||
pack.description, | ||
'', | ||
'Options:', | ||
'', | ||
' -h, --help output usage information', | ||
' -v, --version output version number', | ||
'', | ||
'Usage:', | ||
'', | ||
'# output phonetics', | ||
'$ ' + pack.name + ' considerations detestable', | ||
'# ' + phonetics('considerations detestable'), | ||
'', | ||
'# output phonetics from stdin', | ||
"$ echo 'hiccups vileness' | " + pack.name, | ||
'# ' + phonetics('hiccups vileness'), | ||
'', | ||
'# with stemmer', | ||
"$ echo 'vileness' | stemmer | " + pack.name, | ||
'# ' + phonetics('vile') | ||
].join('\n ') + '\n' | ||
) | ||
} |
Oops, something went wrong.