Comparing version 0.1.3 to 0.1.4
70
cli.js
#!/usr/bin/env node | ||
'use strict'; | ||
/** | ||
/* | ||
* Dependencies. | ||
@@ -11,6 +11,14 @@ */ | ||
pack = require('./package.json'); | ||
metaphone = require('./'); | ||
pack = require('./package.json'); | ||
/** | ||
/* | ||
* Detect if a value is expected to be piped in. | ||
*/ | ||
var expextPipeIn; | ||
expextPipeIn = !process.stdin.isTTY; | ||
/* | ||
* Arguments. | ||
@@ -23,3 +31,3 @@ */ | ||
/** | ||
/* | ||
* Command. | ||
@@ -33,9 +41,20 @@ */ | ||
/** | ||
* Get the distance for a word. | ||
* | ||
* @param {Array.<string>} values | ||
* @return {string} | ||
*/ | ||
function phonetics(values) { | ||
return values.map(metaphone).join(' '); | ||
} | ||
/** | ||
* Help. | ||
* | ||
* @return {string} | ||
*/ | ||
function help() { | ||
console.log([ | ||
return [ | ||
'', | ||
'Usage: ' + command + ' [options] string', | ||
'Usage: ' + command + ' [options] <words...>', | ||
'', | ||
@@ -51,13 +70,28 @@ pack.description, | ||
'', | ||
'# output phonetics of given value', | ||
'$ ' + command + ' detestable', | ||
'# TTSTBL', | ||
'# output phonetics', | ||
'$ ' + command + ' considerations detestable', | ||
'# ' + phonetics(['considerations', 'detestable']), | ||
'', | ||
'# output phonetics from stdin', | ||
'$ echo "vileness" | ' + command, | ||
'# FLNS' | ||
].join('\n ') + '\n'); | ||
'$ echo "hiccups vileness" | ' + command, | ||
'# ' + phonetics(['hiccups', 'vileness']), | ||
'' | ||
].join('\n ') + '\n'; | ||
} | ||
/** | ||
* Get the edit distance for a list containing one word. | ||
* | ||
* @param {Array.<string>} values | ||
*/ | ||
function getPhonetics(values) { | ||
if (values.length) { | ||
console.log(phonetics(values)); | ||
} else { | ||
process.stderr.write(help()); | ||
process.exit(1); | ||
} | ||
} | ||
/* | ||
* Program. | ||
@@ -70,3 +104,3 @@ */ | ||
) { | ||
help(); | ||
console.log(help()); | ||
} else if ( | ||
@@ -77,6 +111,6 @@ argv.indexOf('--version') !== -1 || | ||
console.log(pack.version); | ||
} else if (argv.length === 1) { | ||
console.log(metaphone(argv[0])); | ||
} else if (argv.length) { | ||
help(); | ||
getPhonetics(argv.join(' ').split(/\s+/g)); | ||
} else if (!expextPipeIn) { | ||
getPhonetics([]); | ||
} else { | ||
@@ -86,4 +120,4 @@ process.stdin.resume(); | ||
process.stdin.on('data', function (data) { | ||
console.log(metaphone(data.trim())); | ||
getPhonetics(data.trim().split(/\s+/g)); | ||
}); | ||
} |
67
index.js
@@ -32,3 +32,3 @@ 'use strict'; | ||
/** | ||
/* | ||
* Matches duplicate characters (excluding `c`), of which | ||
@@ -40,3 +40,3 @@ * one should be dropped. | ||
/** | ||
/* | ||
* Matches two characters at the start of a string, of | ||
@@ -48,3 +48,3 @@ * which the first is silent. | ||
/** | ||
/* | ||
* Matches `mb` at the end of string, of which the `b` | ||
@@ -56,3 +56,3 @@ * should be dropped. | ||
/** | ||
/* | ||
* Matches `c`. | ||
@@ -63,3 +63,3 @@ */ | ||
/** | ||
/* | ||
* Matches values which should be transformed to `x`. | ||
@@ -70,3 +70,3 @@ */ | ||
/** | ||
/* | ||
* Matches values which should be transformed to `s`. | ||
@@ -77,3 +77,3 @@ */ | ||
/** | ||
/* | ||
* Matches values containing `d` which should be | ||
@@ -85,3 +85,3 @@ * transformed to `j`. | ||
/** | ||
/* | ||
* Matches `d`. | ||
@@ -92,3 +92,3 @@ */ | ||
/** | ||
/* | ||
* Matches values containing `gh` of which the `g` should | ||
@@ -100,3 +100,3 @@ * be dropped. | ||
/** | ||
/* | ||
* Matches final values of which the `g` should be dropped. | ||
@@ -109,3 +109,3 @@ * | ||
/** | ||
/* | ||
* Matches values of which the `g` should be dropped. | ||
@@ -120,3 +120,3 @@ * | ||
/** | ||
/* | ||
* Matches `g`. | ||
@@ -127,3 +127,3 @@ */ | ||
/** | ||
/* | ||
* Matches values of which the `h` should be dropped. | ||
@@ -134,3 +134,3 @@ */ | ||
/** | ||
/* | ||
* Matches `ck`. | ||
@@ -141,3 +141,3 @@ */ | ||
/** | ||
/* | ||
* Matches `ph`. | ||
@@ -148,3 +148,3 @@ */ | ||
/** | ||
/* | ||
* Matches `q`. | ||
@@ -155,3 +155,3 @@ */ | ||
/** | ||
/* | ||
* Matches values containing `s` which should be replaced | ||
@@ -163,3 +163,3 @@ * with `x`. | ||
/** | ||
/* | ||
* Matches values containing `t` which should be replaced | ||
@@ -171,3 +171,3 @@ * with `x`. | ||
/** | ||
/* | ||
* Matches `th`. | ||
@@ -178,3 +178,3 @@ */ | ||
/** | ||
/* | ||
* Matches `tch`. | ||
@@ -185,3 +185,3 @@ */ | ||
/** | ||
/* | ||
* Matches `v`. | ||
@@ -192,3 +192,3 @@ */ | ||
/** | ||
/* | ||
* Matches initial `wh`. | ||
@@ -199,3 +199,3 @@ */ | ||
/** | ||
/* | ||
* Matches `w`, not followed by a vowel. | ||
@@ -206,3 +206,3 @@ */ | ||
/** | ||
/* | ||
* Matches initial `x`. | ||
@@ -213,3 +213,3 @@ */ | ||
/** | ||
/* | ||
* Matches `x`. | ||
@@ -220,3 +220,3 @@ */ | ||
/** | ||
/* | ||
* Matches `y`, not followed by a vowel. | ||
@@ -227,3 +227,3 @@ */ | ||
/** | ||
/* | ||
* Matches `z`. | ||
@@ -234,3 +234,3 @@ */ | ||
/** | ||
/* | ||
* Matches vowels (no `y`). | ||
@@ -243,4 +243,6 @@ */ | ||
* Return the character at `1`. | ||
* | ||
* @param {string} $0 | ||
* @return {string} | ||
*/ | ||
function initials($0) { | ||
@@ -252,4 +254,6 @@ return $0.charAt(1); | ||
* Return the value, `c`s replaced with `x`s. | ||
* | ||
* @param {string} $0 | ||
* @return {string} | ||
*/ | ||
function cToX($0) { | ||
@@ -266,3 +270,2 @@ return $0.replace(EXPRESSION_C, 'x'); | ||
*/ | ||
function metaphone(value) { | ||
@@ -304,3 +307,3 @@ value = String(value) | ||
/** | ||
/* | ||
* Expose `metaphone`. | ||
@@ -307,0 +310,0 @@ */ |
{ | ||
"name": "metaphone", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Fast Metaphone implementation", | ||
@@ -25,5 +25,6 @@ "license": "MIT", | ||
"devDependencies": { | ||
"eslint": "^0.10.0", | ||
"eslint": "^0.11.0", | ||
"istanbul": "^0.3.0", | ||
"jscs": "^1.0.0", | ||
"jscs-jsdoc": "^0.4.0", | ||
"matcha": "^0.6.0", | ||
@@ -33,15 +34,17 @@ "mocha": "^2.0.0" | ||
"scripts": { | ||
"test": "node_modules/.bin/_mocha --reporter spec --check-leaks -u exports test.js", | ||
"test-travis": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --check-leaks -u exports test.js", | ||
"coverage": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -- test.js", | ||
"lint-api": "node_modules/.bin/eslint index.js", | ||
"lint-cli": "node_modules/.bin/eslint cli.js", | ||
"lint-test": "node_modules/.bin/eslint test.js --env mocha", | ||
"lint-benchmark": "node_modules/.bin/eslint benchmark.js --global suite,set,bench", | ||
"lint-style": "node_modules/.bin/jscs benchmark.js index.js cli.js test.js --reporter=inline", | ||
"test": "_mocha --check-leaks test.js", | ||
"test-cli": "bash test.sh", | ||
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test.js", | ||
"test-travis": "npm run test-cli && npm run test-coveralls", | ||
"coverage": "istanbul cover _mocha -- -- test.js", | ||
"lint-api": "eslint index.js", | ||
"lint-cli": "eslint --rule no-process-exit:false cli.js", | ||
"lint-test": "eslint --env mocha test.js", | ||
"lint-benchmark": "eslint --global suite,set,bench benchmark.js", | ||
"lint-style": "jscs --reporter inline index.js benchmark.js cli.js test.js", | ||
"lint": "npm run lint-api && npm run lint-cli && npm run lint-test && npm run lint-benchmark && npm run lint-style", | ||
"make": "npm run lint && npm run coverage", | ||
"install-benchmark": "npm install natural && git clone git@github.com:Katee/metaphone.git node_modules/metafone", | ||
"benchmark": "node_modules/.bin/matcha benchmark.js" | ||
"benchmark": "matcha benchmark.js" | ||
} | ||
} |
@@ -7,20 +7,29 @@ # metaphone [![Build Status](https://img.shields.io/travis/wooorm/metaphone.svg?style=flat)](https://travis-ci.org/wooorm/metaphone) [![Coverage Status](https://img.shields.io/coveralls/wooorm/metaphone.svg?style=flat)](https://coveralls.io/r/wooorm/metaphone?branch=master) | ||
npm: | ||
```sh | ||
[npm](https://docs.npmjs.com/cli/install): | ||
```bash | ||
$ npm install metaphone | ||
``` | ||
Component: | ||
```sh | ||
[Component.js](https://github.com/componentjs/component): | ||
```bash | ||
$ component install wooorm/metaphone | ||
``` | ||
Bower: | ||
```sh | ||
[Bower](http://bower.io/#install-packages): | ||
```bash | ||
$ bower install metaphone | ||
``` | ||
[Duo](http://duojs.org/#getting-started): | ||
```javascript | ||
var metaphone = require('wooorm/metaphone'); | ||
``` | ||
## Usage | ||
```js | ||
```javascript | ||
var metaphone = require('metaphone'); | ||
@@ -35,3 +44,4 @@ | ||
With [stemmer](https://github.com/wooorm/stemmer): | ||
```js | ||
```javascript | ||
var metaphone = require('metaphone'); | ||
@@ -50,3 +60,4 @@ var stemmer = require('stemmer'); | ||
Install: | ||
```sh | ||
```bash | ||
$ npm install --global metaphone | ||
@@ -56,5 +67,6 @@ ``` | ||
Use: | ||
``` | ||
Usage: metaphone [options] string | ||
```text | ||
Usage: metaphone [options] <words...> | ||
Fast Metaphone implementation | ||
@@ -69,9 +81,9 @@ | ||
# output phonetics of given value | ||
$ metaphone detestable | ||
# TTSTBL | ||
# output phonetics | ||
$ metaphone considerations detestable | ||
# KNSTRXNS TTSTBL | ||
# output phonetics from stdin | ||
$ echo "vileness" | metaphone | ||
# FLNS | ||
$ echo "hiccups vileness" | metaphone | ||
# HKKPS FLNS | ||
``` | ||
@@ -83,3 +95,3 @@ | ||
``` | ||
```text | ||
metaphone — this module | ||
@@ -97,2 +109,2 @@ 136 op/s » op/s * 1,000 | ||
MIT © [Titus Wormer](http://wooorm.com) | ||
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11805
315
104
6