-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
39 lines (33 loc) · 1.22 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var range = require('array-range');
var numberStringRepresentation = require('number-string-representation');
var RANGEMAX = 100;
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 getNumberWords(input) {
/*
Returns a string containing words for the numeral `input`
*/
var dollarWords = numberStringRepresentation(input);
var words = deDollarize(dollarWords);
return words.toLowerCase();
}
function getRedundancy(input) {
/*
Given an integer, makes a redundant string like "two (2)"
*/
return getNumberWords(input) + " (" + input + ")";
}
var escapeRegExp = require('escape-regexp');
var integerRange = range(1,RANGEMAX+1);
var redundancies = integerRange.map(getRedundancy).map(escapeRegExp);
process.stdout.write(JSON.stringify(redundancies, null, 2) + '\n');