beyond clean code
type User = {
id: number;
username: string;
firstName: string;
lastName: string;
isActive: boolean;
}
type User = {
id: number;
username: string;
firstName: string;
lastName: string;
loggedInPrevious24Hours: boolean;
}
class Class {}
class Post {}
class Classroom {}
class BlogPost {}
class DateUtil {
static function dateStrFrmo(date: Date): string
{ ... }
}
class DateUtil {
static function getStringFromDate(date: Date): string
{ ... }
}
constructor() {
this.assignElements();
this.setInterval();
this.getNewArt();
this.listenForInstructions();
}
const SOCIAL_MEDIA_CHARACTER_COUNT = 116;
// shortens title for social media sharing
export const getSocialShareText = (post: BlogPost) => {
if (post.title.length =< SOCIAL_MEDIA_CHARACTER_COUNT) {
return post.title;
} else {
return post.title.substr(
0, SOCIAL_MEDIA_CHARACTER_COUNT
);
}
}
// Twitter has shortest character limit (140); URL shortener is always 23
const SOCIAL_MEDIA_CHARACTER_COUNT = 116;
export const getSocialShareText = (post: BlogPost) => {
if (post.title.length =< SOCIAL_MEDIA_CHARACTER_COUNT) {
return post.title + ' ' + post.url;
} else {
return post.title.substr(
0, SOCIAL_MEDIA_CHARACTER_COUNT
) + ' ' + post.url;
}
}
const title = (postRequest['title'])
? postRequest['title']
: '';
const title = postRequest['title'] || '';
describe('getSocialMediaText restricts to Twitter length', ()=> {
it('when title is less than length', () => {
const res = getSocialMediaText(MockPostShortTitle);
expect(res.length =< 116)
}),
it('when the title is more than length', () => {
const res = getSocialMediaText(MockPostLongTitle);
expect(res.length =< 116)
})
});
questions?
hello@kait.dev
written version
https://kait.dev/talks