Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dice-coefficient

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dice-coefficient - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

81

cli.js
#!/usr/bin/env node
'use strict';
/**
/*
* Dependencies.

@@ -14,3 +14,11 @@ */

/**
/*
* Detect if a value is expected to be piped in.
*/
var expextPipeIn;
expextPipeIn = !process.stdin.isTTY;
/*
* Arguments.

@@ -23,11 +31,22 @@ */

/*
* Command.
*/
var command;
command = Object.keys(pack.bin)[0];
/**
* Help.
*
* @return {string}
*/
function help() {
console.log([
return [
'',
'Usage: dice-coefficient <string> <string>',
'Usage: ' + command + ' [options] <word> <word>',
'',
pack.description,
'',
'Options:',

@@ -40,9 +59,27 @@ '',

'',
'# output dice-coefficient',
'$ dice-coefficient night nacht',
'# 0.25'
].join('\n ') + '\n');
'# output edit distance',
'$ ' + command + ' night nacht',
'# ' + diceCoefficient('night', 'nacht'),
'',
'# output edit distance from stdin',
'$ echo "saturday sunday" | ' + command,
'# ' + diceCoefficient('saturday', 'sunday')
].join('\n ') + '\n';
}
/**
* Get the edit distance for a list of words.
*
* @param {Array.<string>} values
*/
function getEditDistance(values) {
if (values.length === 2) {
console.log(diceCoefficient(values[0], values[1]) || 0);
} else {
process.stderr.write(help());
process.exit(1);
}
}
/*
* Program.

@@ -52,19 +89,21 @@ */

if (
argv.indexOf('--help') === 0 ||
argv.indexOf('-h') === 0
argv.indexOf('--help') !== -1 ||
argv.indexOf('-h') !== -1
) {
help();
console.log(help());
} else if (
argv.indexOf('--version') === 0 ||
argv.indexOf('-v') === 0
argv.indexOf('--version') !== -1 ||
argv.indexOf('-v') !== -1
) {
console.log(pack.version);
} else if (
argv.length === 2 &&
argv[0] &&
argv[1]
) {
console.log(diceCoefficient(argv[0], argv[1]));
} else if (argv.length) {
getEditDistance(argv.join(' ').split(/\s+/g));
} else if (!expextPipeIn) {
getEditDistance([]);
} else {
help();
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (data) {
getEditDistance(data.trim().split(/\s+/g));
});
}

@@ -5,3 +5,3 @@ 'use strict';

/**
/*
* Module dependencies.

@@ -19,3 +19,2 @@ */

*/
function diceCoefficient(value, alternative) {

@@ -50,3 +49,3 @@ var pairs,

/**
/*
* Make sure this pair never matches again

@@ -64,3 +63,3 @@ */

/**
/*
* Expose `diceCoefficient`.

@@ -67,0 +66,0 @@ */

{
"name": "dice-coefficient",
"version": "0.1.3",
"version": "0.1.4",
"description": "Sørensen–Dice coefficient",

@@ -26,5 +26,6 @@ "license": "MIT",

"devDependencies": {
"eslint": "^0.9.0",
"eslint": "^0.10.0",
"istanbul": "^0.3.0",
"jscs": "^1.0.0",
"jscs-jsdoc": "^0.3.0",
"matcha": "^0.6.0",

@@ -34,15 +35,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 index.js cli.js test.js benchmark.js --reporter=inline",
"lint": "npm run lint-api && npm run lint-cli && npm run lint-test && npm run lint-style && npm run lint-benchmark",
"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-benchmark && npm run lint-cli && npm run lint-test && npm run lint-style",
"make": "npm run lint && npm run coverage",
"install-benchmark": "npm install natural",
"benchmark": "node_modules/.bin/matcha benchmark.js"
"benchmark": "matcha benchmark.js"
}
}

@@ -8,3 +8,3 @@ # dice-coefficient [![Build Status](https://img.shields.io/travis/wooorm/dice-coefficient.svg?style=flat)](https://travis-ci.org/wooorm/dice-coefficient) [![Coverage Status](https://img.shields.io/coveralls/wooorm/dice-coefficient.svg?style=flat)](https://coveralls.io/r/wooorm/dice-coefficient?branch=master)

npm:
```sh
```bash
$ npm install dice-coefficient

@@ -14,3 +14,3 @@ ```

Component:
```sh
```bash
$ component install wooorm/dice-coefficient

@@ -20,3 +20,3 @@ ```

Bower:
```sh
```bash
$ bower install dice-coefficient

@@ -38,35 +38,41 @@ ```

## Benchmark
## CLI
On a MacBook Air, it runs about 781,000 op/s, which is more than 7.5 times faster than natural.
Install:
```bash
$ npm install --global dice-coefficient
```
dice-coefficient
781 op/s » op/s * 1,000
natural
102 op/s » op/s * 1,000
Usage:
```
Usage: dice-coefficient [options] <word> <word>
## CLI
Sørensen–Dice coefficient
Install:
```sh
$ npm install dice-coefficient
```
Options:
-h, --help output usage information
-v, --version output version number
Usage:
# output edit distance
$ dice-coefficient night nacht
# 0.25
# output edit distance from stdin
$ echo "saturday sunday" | dice-coefficient
# 0.3333333333333333
```
Usage: dice-coefficient <string> <string>
Options:
## Benchmark
-h, --help output usage information
-v, --version output version number
On a MacBook Air, it runs about 781,000 op/s, which is more than 7.5 times faster than natural.
Usage:
```
dice-coefficient
781 op/s » op/s * 1,000
# output dice-coefficient
$ dice-coefficient night nacht
# 0.25
natural
102 op/s » op/s * 1,000
```

@@ -73,0 +79,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc