doubleplus-numbers
Advanced tools
Comparing version 0.1.0 to 0.2.0
86
index.js
@@ -1,85 +0,5 @@ | ||
var range = require('array-range'); | ||
var numberStringRepresentation = require('number-string-representation'); | ||
var RANGEMAX = 100; | ||
var expressions = require('./redundancies').map(function(element) { | ||
return new RegExp(element); | ||
}); | ||
// Regex for detecting numerals: | ||
// \d+ First numerals | ||
// (,\d+)* Optionally, a comma and some more numerals (may be repeated) | ||
// (\.\d+)? Optionally, a decimal point followed by more numerals | ||
var reNumerals = /\d+(,\d+)*(\.\d+)?/i; | ||
function deDollarize(dollary) { | ||
// Unfortunately, number-string-representation alawys returns stuff about | ||
// dollars at the end of its output. This function trims it off. | ||
// TODO: Account for decimals instead of lopping them off. | ||
// Example `dollary` input string: "two thousand five hundred twenty-three and 00/100 dollars" | ||
var reNoDollars = /(.+)(\sand \d\d\/100 dollars)/i; | ||
if (reNoDollars.test(dollary)) { | ||
return reNoDollars.exec(dollary)[1]; | ||
} else { | ||
return dollary; | ||
} | ||
} | ||
function getAllNumerals(input) { | ||
/* | ||
returns a list of all numerals (as strings) in the input string | ||
good test string: "one 234.56 three 456 five 67.89 foo" | ||
more test strings: | ||
two (2) things | ||
three (3) more | ||
five dollars and twenty cents (5.20)! | ||
four thousand (4,000)!!! | ||
some more (1,234.567) | ||
billions and billions (1,234,567,890.10) | ||
one 234.56 three 456 five 67.89 foo | ||
Test at http://regexpal.com/ | ||
*/ | ||
r = []; | ||
var matches = input.match(reNumerals); | ||
console.log("reNumerals: " + reNumerals); | ||
console.log("matches: " + matches); | ||
for (i=0; i < matches.length; i++) { | ||
var match = matches[i]; | ||
console.log("i=" + i + "; match: " + match); | ||
r.push(match); | ||
console.log("r: " +r); | ||
} | ||
return r; | ||
} | ||
function getNumberWords(input) { | ||
/* | ||
Returns a string containing words for the numeral `input` | ||
*/ | ||
dollarWords = numberStringRepresentation(input); | ||
words = deDollarize(dollarWords); | ||
return words.toLowerCase(); | ||
} | ||
function getRedundancy(input) { | ||
/* | ||
Given an integer, makes a redundant string like "two (2)" | ||
*/ | ||
return getNumberWords(input) + " (" + input + ")"; | ||
} | ||
function escapeRegExp(str) { | ||
// Source: http://stackoverflow.com/a/17326679 | ||
return String(str).replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); | ||
} | ||
function makeRegExp(input) { | ||
// use this to map() onto an array of redundancies | ||
return new RegExp(escapeRegExp(input)); | ||
} | ||
var integerRange = range(1,RANGEMAX+1); | ||
var redundancies = integerRange.map(getRedundancy); | ||
var expressions = redundancies.map(makeRegExp); | ||
function message(form, path, expression, match) { | ||
@@ -86,0 +6,0 @@ var word = match[0]; |
{ | ||
"name": "doubleplus-numbers", | ||
"description": "Common Form annotator to find and identify redundant and repeated number(s) and numeral(s)", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Ansel Halliburton <github@anseljh.com> (http://anseljh.com)", | ||
@@ -16,14 +16,17 @@ "bugs": "https://github.com/anseljh/doubleplus-numbers/issues", | ||
"dependencies": { | ||
"commonform-regexp-annotator": ">=1.0.3", | ||
"number-string-representation": "0.1.9", | ||
"array-range": ">=1.0" | ||
"commonform-regexp-annotator": "^1.0.3" | ||
}, | ||
"devDependencies": { | ||
"defence-cli": "~1.0.1", | ||
"replace-require-self": "~1.0.0" | ||
"array-range": "^1.0.0", | ||
"defence-cli": "^1.0.1", | ||
"escape-regexp": "^0.0.1", | ||
"number-string-representation": "^0.1.9", | ||
"replace-require-self": "^1.0.0" | ||
}, | ||
"repository": "anseljh/doubleplus-numbers", | ||
"scripts": { | ||
"prepublish": "node build.js > redundancies.json", | ||
"pretest": "npm run prepublish", | ||
"test": "defence README.md | replace-require-self | node" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
17462
1
6
150
5
1
+ Addedcommonform-predicate@0.4.4(transitive)
+ Addedcommonform-regexp-annotator@1.1.1(transitive)
- Removedarray-range@>=1.0
- Removednumber-string-representation@0.1.9
- Removedarray-range@1.0.1(transitive)
- Removedcommonform-predicate@3.0.1(transitive)
- Removedcommonform-regexp-annotator@2.0.0(transitive)
- Removednumber-string-representation@0.1.9(transitive)
- Removedoptimist@0.5.2(transitive)
- Removedwordwrap@0.0.3(transitive)