This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const formatDate = (date) => { | |
if (!date) throw new Error('No date') // If no date, throw an error | |
const dateObj = new Date(date) | |
if (isToday(dateObj)) return 'Today' // If the date is today, return 'Today' | |
if (isYesterday(dateObj)) return 'Yesterday' // If the date is yesterday, return 'Yesterday' | |
if (!isThisYear(dateObj)) return format(dateObj, 'MMMM d, yyyy') // If the date is not in this year, return date with year | |
return format(dateObj, 'MMMM d') // If no matching the above, return date with month and date | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (kind === 'Persian' || kind === 'Maine' || kind === 'British Shorthair') { | |
// do something ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const CATS_TYPE = ['Persian', 'Maine', 'British Shorthair'] | |
if (CATS_TYPE.includes(kind)) { | |
// do something ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (user && user.addressInfo) { | |
let zipcode | |
if (user.addressInfo.zipcode) { | |
zipcode = user.addressInfo.zipcode | |
} else { | |
zipcode = '' | |
} | |
// do something | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const zipcode = user?.addressInfo?.zipcode || '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const todos = [ | |
{ | |
code: 'code', | |
name: 'name', | |
list: [ | |
{ | |
name: 'todo name', | |
}, | |
{ | |
name: 'todo name', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const list = []; | |
todos.forEach(t => { | |
t.todo2.forEach(t2 => { | |
t2.todo3.forEach(t3 => { | |
t3.list.forEach(l => { | |
list.push({ | |
todo3Name: l.name | |
}) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const list = todos | |
.reduce((acc, t) => [...acc, ...t.todo2], []) | |
.reduce((acc, t2) => [...acc, ...t2.todo3], []) | |
.reduce((acc, t3) => [...acc, ...t3.list], []) | |
.map(l => ({ todo3Name: l.name })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const updateUser = async (user) => { | |
try { | |
await axios.post('/users', user) | |
await axios.post('/user/profile', user.profile) | |
const email = new Email() | |
await email.send(user.email, 'User has been updated successfully') | |
const logger = new Logger() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const updateUser = async (user) => { | |
try { | |
await axios.post('/users', user) | |
} catch (e) { | |
// handling error | |
} | |
} |