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

doubleplus-numbers

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doubleplus-numbers - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

build.js

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"
}
}
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