-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
149 lines (128 loc) · 4.59 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* jumbo-mortgage
*
* A work of the public domain from the Consumer Financial Protection Bureau.
*/
'use strict';
var formatUSD = require('format-usd');
function usd( num ) {
return formatUSD(num, {decimalPlaces: 0});
}
function getJumboLoanType( opts ) {
opts = opts || {};
var amount = opts.loanAmount || 0,
type = opts.loanType,
limits = {};
// Each loan type has a standard limit and may optionally have a lower
// one based on the relevant county.
limits.gse = {
defaultVal: 806500,
county: opts.gseCountyLimit
};
limits.fha = {
defaultVal: 524225,
county: opts.fhaCountyLimit
};
limits.va = {
defaultVal: 806500,
county: opts.vaCountyLimit
};
switch ( type ) {
case 'conf':
case 'agency':
case 'jumbo':
return processConfLoan( amount, limits );
case 'fha':
case 'fha-hb':
return processFHALoan( amount, limits );
case 'va':
case 'va-hb':
return processVALoan( amount, limits );
defaultVal:
return fail();
}
}
function processConfLoan( amount, limits ) {
if ( amount > limits.gse.defaultVal ) {
if ( !limits.gse.county ) {
return fail('county');
}
if ( amount <= limits.gse.county ) {
return success('agency', 'When you borrow between ' + usd( limits.gse.defaultVal ) + ' and ' + usd( limits.gse.county ) + ' in your county, you are eligible for a conforming jumbo loan.');
}
if ( amount > limits.gse.county ) {
return success('jumbo', 'When you borrow more than ' + usd( limits.gse.county ) + ' in your county, the only loan type available to you is a jumbo (non-conforming) loan.');
}
}
// It ain't jumbo
return success();
}
function processFHALoan( amount, limits ) {
if ( amount > limits.fha.defaultVal ) {
if ( !limits.gse.county || !limits.fha.county ) {
return fail('county');
}
if ( amount <= limits.fha.county ) {
return success('fha-hb', 'When you borrow between ' + usd( limits.fha.defaultVal ) + ' and ' + usd( limits.fha.county ) + ' in your county, you are eligible for a high-balance FHA loan.');
}
if ( amount > limits.fha.county && amount <= limits.gse.defaultVal ) {
return success('conf', 'You are not eligible for an FHA loan when you borrow more than ' + usd( limits.fha.county ) + ' in your county. You are eligible for a conventional loan.');
}
if ( amount > limits.gse.defaultVal && amount <= limits.gse.county ) {
return success('agency', 'You are not eligible for an FHA loan when you borrow more than ' + usd( limits.fha.county ) + ' in your county. You are eligible for a conforming jumbo loan.');
}
if ( amount > limits.gse.defaultVal && amount > limits.gse.county ) {
return success('jumbo', 'You are not eligible for an FHA loan when you borrow more than ' + usd( limits.fha.county ) + ' in your county. The only loan type available to you at this loan amount is a jumbo (non-conforming) loan.');
}
}
// It ain't jumbo
return success();
}
function processVALoan( amount, limits ) {
if ( amount > limits.va.defaultVal ) {
if ( !limits.gse.county || !limits.va.county ) {
return fail('county');
}
if ( amount <= limits.va.county ) {
return success('va-hb', 'When you borrow between ' + usd( limits.va.defaultVal ) + ' and ' + usd( limits.va.county ) + ' in your county, you may be eligible for a high-balance VA loan.');
}
if ( amount > limits.va.county && amount < limits.gse.county ) {
return success('agency', 'While VA loans do not have strict loan limits, most lenders are unlikely to make a VA loan more than ' + usd( limits.va.county ) + ' in your county. Your only option may be a conforming jumbo loan.');
}
if ( amount > limits.gse.county ) {
return success('jumbo', 'While VA loans do not have strict loan limits, most lenders are unlikely to make a VA loan more than ' + usd( limits.va.county ) + ' in your county. Your only option may be a jumbo (non-conforming) loan.');
}
}
// It ain't jumbo
return success();
}
function success( type, msg ) {
if ( type ) {
return {
success: true,
isJumbo: true,
type: type,
msg: msg || undefined
};
}
// If no loan type is provided, indicate that it's not a jumbo
// loan and nothing needs to be changed.
return {
success: true,
isJumbo: false
};
}
function fail( status ) {
if ( status === 'county' ) {
return {
success: false,
needCounty: true,
msg: 'Please provide county limits.'
};
}
return {
success: false,
msg: 'Unknown loan type.'
};
}
module.exports = getJumboLoanType;