Prettier format all js files

This commit is contained in:
George Drummond
2019-01-24 09:38:43 -05:00
parent 20604e6ca9
commit 619bc9fe59
32 changed files with 553 additions and 443 deletions

View File

@@ -8,12 +8,19 @@ export const formatDollars = (value, cents = true) => {
}
export const abbreviateDollars = (value, decimals = 1) => {
if (value === null) { return null } // terminate early
if (value === 0) { return '0' } // terminate early
var b = (value).toPrecision(2).split("e"), // get power
k = b.length === 1 ? 0 : Math.floor(Math.min(b[1].slice(1), 14) / 3), // floor at decimals, ceiling at trillions
c = k < 1 ? value.toFixed(0 + decimals) : (value / Math.pow(10, k * 3) ).toFixed(decimals), // divide by power
d = c < 0 ? c : Math.abs(c), // enforce -0 is 0
e = d + ['', 'k', 'M', 'B', 'T'][k]; // append power
return e;
if (value === null) {
return null
} // terminate early
if (value === 0) {
return '0'
} // terminate early
var b = value.toPrecision(2).split('e'), // get power
k = b.length === 1 ? 0 : Math.floor(Math.min(b[1].slice(1), 14) / 3), // floor at decimals, ceiling at trillions
c =
k < 1
? value.toFixed(0 + decimals)
: (value / Math.pow(10, k * 3)).toFixed(decimals), // divide by power
d = c < 0 ? c : Math.abs(c), // enforce -0 is 0
e = d + ['', 'k', 'M', 'B', 'T'][k] // append power
return e
}

View File

@@ -7,86 +7,121 @@ export default {
mask: false,
match: /\s*/,
unmask: [],
validationError: 'Please enter a response'
validationError: 'Please enter a response',
},
requiredField: {
mask: false,
match: /.+/,
unmask: [],
validationError: 'This field is required'
validationError: 'This field is required',
},
integer: {
mask: createNumberMask({ prefix: '', allowDecimal: false }),
match: /^[1-9]\d*$/,
unmask: [','],
validationError: 'Please enter a number'
validationError: 'Please enter a number',
},
dollars: {
mask: createNumberMask({ prefix: '$', allowDecimal: true }),
match: /^-?\d+\.?\d*$/,
unmask: ['$',','],
validationError: 'Please enter a dollar amount'
unmask: ['$', ','],
validationError: 'Please enter a dollar amount',
},
gigabytes: {
mask: createNumberMask({ prefix: '', suffix:' GB', allowDecimal: false }),
mask: createNumberMask({ prefix: '', suffix: ' GB', allowDecimal: false }),
match: /^[1-9]\d*$/,
unmask: [',',' GB'],
validationError: 'Please enter an amount of data in gigabytes'
unmask: [',', ' GB'],
validationError: 'Please enter an amount of data in gigabytes',
},
email: {
mask: emailMask,
match: /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/i,
unmask: [],
validationError: 'Please enter a valid e-mail address'
validationError: 'Please enter a valid e-mail address',
},
date: {
mask: [/\d/,/\d/,'/',/\d/,/\d/,'/',/\d/,/\d/,/\d/,/\d/],
mask: [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/],
match: /(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d/,
unmask: [],
pipe: createAutoCorrectedDatePipe('mm/dd/yyyy HH:MM'),
keepCharPositions: true,
validationError: 'Please enter a valid date in the form MM/DD/YYYY'
validationError: 'Please enter a valid date in the form MM/DD/YYYY',
},
usPhone: {
mask: ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
mask: [
'(',
/[1-9]/,
/\d/,
/\d/,
')',
' ',
/\d/,
/\d/,
/\d/,
'-',
/\d/,
/\d/,
/\d/,
/\d/,
],
match: /^\d{10}$/,
unmask: ['(',')','-',' '],
validationError: 'Please enter a 10-digit phone number'
unmask: ['(', ')', '-', ' '],
validationError: 'Please enter a 10-digit phone number',
},
phoneExt: {
mask: createNumberMask({ prefix: '', allowDecimal: false, integerLimit: 10, allowLeadingZeroes: true, includeThousandsSeparator: false }),
mask: createNumberMask({
prefix: '',
allowDecimal: false,
integerLimit: 10,
allowLeadingZeroes: true,
includeThousandsSeparator: false,
}),
match: /^\d{0,10}$/,
unmask: [],
validationError: 'Optional: Please enter up to 10 digits'
validationError: 'Optional: Please enter up to 10 digits',
},
dodId: {
mask: createNumberMask({ prefix: '', allowDecimal: false, allowLeadingZeroes: true, includeThousandsSeparator: false }),
mask: createNumberMask({
prefix: '',
allowDecimal: false,
allowLeadingZeroes: true,
includeThousandsSeparator: false,
}),
match: /^\d{10}$/,
unmask: [],
validationError: 'Please enter a 10-digit DoD ID number'
validationError: 'Please enter a 10-digit DoD ID number',
},
peNumber: {
mask: false,
match: /(0\d)(0\d)(\d{3})([a-z,A-Z]{1,3})/,
unmask: ['_'],
validationError: 'Please enter a valid PE number. Note that it should be 7 digits followed by 1-3 letters, and should have a zero as the first and third digits.'
validationError:
'Please enter a valid PE number. Note that it should be 7 digits followed by 1-3 letters, and should have a zero as the first and third digits.',
},
treasuryCode: {
mask: createNumberMask({ prefix: '', allowDecimal: false, allowLeadingZeroes: true, includeThousandsSeparator: false }),
mask: createNumberMask({
prefix: '',
allowDecimal: false,
allowLeadingZeroes: true,
includeThousandsSeparator: false,
}),
match: /^0*([1-9]{4}|[1-9]{6})$/,
unmask: [],
validationError: 'Please enter a valid Program Treasury Code. Note that it should be a four digit or six digit number, optionally prefixed by one or more zeros.'
validationError:
'Please enter a valid Program Treasury Code. Note that it should be a four digit or six digit number, optionally prefixed by one or more zeros.',
},
baCode: {
mask: false,
match: /[0-9]{2}\w?$/,
unmask: [],
validationError: 'Please enter a valid BA Code. Note that it should be two digits, followed by an optional letter.'
validationError:
'Please enter a valid BA Code. Note that it should be two digits, followed by an optional letter.',
},
portfolioName: {
mask: false,
match: /^.{4,100}$/,
unmask: [],
validationError: 'Portfolio and request names must be at least 4 and not more than 100 characters'
validationError:
'Portfolio and request names must be at least 4 and not more than 100 characters',
},
}

View File

@@ -1,11 +1,11 @@
export const isNotInVerticalViewport = (el) => {
export const isNotInVerticalViewport = el => {
const bounds = el.getBoundingClientRect()
if (bounds.top < 0) {
return true
}
if (bounds.bottom > ((window.innerHeight - 50))) {
if (bounds.bottom > window.innerHeight - 50) {
// 50 is a magic number to offset for the sticky footer
// see variables.scss for $footer-height
return true