Skip to content

Instantly share code, notes, and snippets.

@mitchellaha
Last active July 3, 2024 17:19
Show Gist options
  • Save mitchellaha/c63d37bcf429cf1f503e15c4bfbe1439 to your computer and use it in GitHub Desktop.
Save mitchellaha/c63d37bcf429cf1f503e15c4bfbe1439 to your computer and use it in GitHub Desktop.
Javascript One Liners
export const URLS = {
AUTH_HOME: '/',
AUTH_LEADS: '/leads',
AUTH_LEAD: ':id/*',
AUTH_LEAD_DETAILS: 'details',
AUTH_LEAD_NOTES: 'notes',
AUTH_LEAD_CHECKLISTS: 'checklists',
AUTH_LEAD_SPEND: 'spend',
AUTH_DASHBOARD: '/dashboard',
LOGIN: '/login',
ORGANIZATION_REGISTRATION: '/registration',
AUTH_LOGOUT: '/logout',
AUTH_DEALS: '/opportunities/',
AUTH_DEALS_LIST: 'list',
AUTH_DEALS_BOARD: 'board',
AUTH_DEAL: '/opportunities/:id',
AUTH_ROUTES_DEAL: '/opportunities/:id/*',
AUTH_DEAL_DETAILS: 'details',
AUTH_DEAL_PROPOSALS: 'proposals',
AUTH_DEAL_DOCUMENTS: 'documents',
AUTH_DEAL_TASKS: 'tasks',
AUTH_DEAL_CHECKLISTS: 'checklists',
AUTH_DEAL_ESTIMATING: 'estimating',
AUTH_DEAL_ANALYSIS: 'analysis',
AUTH_DEAL_TIMETRACKER: 'timetracker',
AUTH_DEAL_ACTIVITY: 'activity',
AUTH_DEAL_NOTES: 'notes',
AUTH_PROPOSALS: '/proposals',
AUTH_PROPOSAL: '/proposals/:id',
AUTH_CONTACTS: '/contacts',
AUTH_COMPANIES: '/companies',
AUTH_COMPANY: '/companies/:id',
AUTH_CONTACT: '/contacts/:id',
AUTH_LISTS: '/lists',
AUTH_CALENDAR: '/calendar',
AUTH_ADMIN: '/admin',
RESET_PASSWORD: '/reset-password',
CHANGE_PASSWORD: '/change-password',
AUTH_GLOBAL_SEARCH: '/search',
AUTH_REPORTS: '/reports',
AUTH_ROUTES_REPORTS: 'reports/*',
AUTH_TIME_TRACKING: '/time-tracking'
}
export const DATE_FORMAT = {
MONTH_DAY_YEAR: 'MM/DD/YYYY',
DAY_MONTH_YEAR: 'DD/MM/YYYY',
YEAR_MONTH_DAY: 'YYYY/MM/DD'
}
export const FNS_DATE_FORMAT = {
MONTH_DAY_YEAR: 'MM/dd/yyyy',
DAY_MONTH_YEAR: 'dd/MM/yyyy',
YEAR_MONTH_DAY: 'yyyy/MM/dd'
}
export const TIME_FORMAT = {
HOUR_MINUTE: 'HH:mm',
HOUR_MINUTE_SECOND: 'HH:mm:ss'
}
export const DATETIME_FORMAT = {
MONTH_DAY_YEAR_HOUR_MINUTE: 'MM/DD/YYYY HH:mm',
DAY_MONTH_YEAR_HOUR_MINUTE: 'DD/MM/YYYY HH:mm',
YEAR_MONTH_DAY_HOUR_MINUTE: 'YYYY/MM/DD HH:mm'
}
export const APP_CONSTANTS = {
DealDocumentType: {
BID_DOCUMENT: 'Bid Document',
RFI_DOCUMENT: 'RFI Document'
},
DealPriority: {
NORMAL: 'Normal',
URGENT: 'Urgent',
HIGHPRIORITY: 'High Priority',
LOWPRIORITY: 'Low Priority'
},
DealHealth: {
ONTRACK: 'On Track',
SLIPPING: 'Slipping',
AHEAD: 'Ahead of Schedule',
WARNING: 'Warning - Danger'
},
DealSize: {
SMALL: 'Small',
MEDIUM: 'Medium',
LARGE: 'Large',
XLARGE: 'X-Large'
},
DealClientRole: {
DECISION: 'Decision Maker',
MANAGER: 'Project Manager',
ENGINEER: 'Project Engineer',
PROPOSALRECEIVER: 'Proposal Receiver',
LEGAL: 'Legal / Contract Admin',
SECRETARY: 'Secretary / Admin',
PRESIDENT: 'President',
ESTIMATOR: 'Estimator'
},
DealNoteToEstimator: {
NEWBID: 'New Bid',
REVIEW: 'Review',
REPRICE: 'Reprice',
PRELIMINARY: 'Preliminary',
BUDGET: 'Budget',
PERCENT30: '30%',
PERCENT60: '60%',
PERCENT90: '90%',
IFC: 'IFC',
FINAL: 'Final'
},
ProposalStatus: {
CREATION: 'Proposal Creation',
CHANGES: 'Proposal Changes',
INTERNALREVIEW: 'In Internal Review',
READYTOSEND: 'Ready to Send',
SENT: 'Sent',
RECEIVED: 'Received',
YY: 'Won - New Job',
YN: 'Lost by Us',
NN: 'Lost by Client(s)',
NY: 'Lost by Client Won by Us',
ARCHIVED: 'Archived'
},
ProposalSigned: {
NO: 'No',
YES: 'Yes'
},
TaskTypes: {
CALL: 'Call',
EMAIL: 'Email',
TASK: 'Task',
MEET: 'Meet',
LUNCH: 'Lunch',
DINNER: 'Dinner'
},
CompanySize: {
S: '0 - 100K',
M: '100K - 500K',
L: '500K - 1M',
XL: '1M - 5M',
XXL: '5M and Up'
},
EntityType: {
DEAL: 'Deal',
PROPOSAL: 'Proposal',
COMPANY: 'Company',
CONTACT: 'Contact',
REPORT: 'Report',
TASK: 'Task',
NOTE: 'Note'
},
OrganizationSize: {
S: '1-2',
M: '3-5',
L: '6-10',
XL: '11-25',
XXL: '25+'
},
OrganizationType: {
CONTRACTOR: 'Contractor / Subcontractor',
GC: 'General Contractor',
AE: 'AE Firm',
SUPPLIER: 'Material Supplier',
INSURANCE: 'Insurance Company',
OTHER: 'Other'
},
OrganizationInterest: {
TRACKING: 'Tracking multiple bids & clients for one opportunity',
EXPEDITE: 'Need to expedite proposal creation',
STREAMLINE: 'Need to streamline & automate follow-up activities',
TIME: 'Manual work is too time consuming',
CENTRALIZE: 'Sales information is not centralized or siloed',
OTHER: 'Other'
}
}
const formatNumber = number => {
return Math.floor(number)
.toString()
.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
export const currencyFormatter = params => {
return params && (params.value || params.value === 0)
? getCurrency().symbol + formatNumber(params.value)
: ''
}
export const percentageFormatter = params => {
return params && (params.value || params.value === 0) ? formatNumber(params.value) + '%' : ''
}
export const hasJsonStructure = str => {
if (typeof str !== 'string') return false
try {
const result = JSON.parse(str)
const type = Object.prototype.toString.call(result)
return type === '[object Object]' || type === '[object Array]'
} catch (err) {
return false
}
}
export const utcDate = (date, format, timezone) => {
if (!format)
moment
.tz(moment(date).format('YYYY-MM-DD HH:mm:ss'), timezone || getTimezone())
.utc()
.format()
return moment
.tz(moment(date).format('YYYY-MM-DD HH:mm:ss'), timezone || getTimezone())
.utc()
.format(format)
}
export const utcCurrentDate = (format, isDateObj = false) => {
if (isDateObj) {
return moment.tz(moment().format('YYYY-MM-DD HH:mm:ss'), getTimezone()).utc()
}
if (!format) moment.tz(moment().format('YYYY-MM-DD HH:mm:ss'), getTimezone()).utc().format()
return moment.tz(moment().format('YYYY-MM-DD HH:mm:ss'), getTimezone()).utc().format(format)
}
export const timezoneDate = (
date,
timeFormat,
splitCharacter = ' ',
noFormat = false,
customFormat,
timezone
) => {
let format = customFormat || getDateFormat()
if (timeFormat) {
format = `${format}${splitCharacter}${timeFormat}`
}
if (noFormat) return moment.tz(date, timezone || getTimezone())
return moment.tz(date, timezone || getTimezone()).format(format)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment