Skip to content

Instantly share code, notes, and snippets.

@hyuki

hyuki/Filter.ts Secret

Last active April 9, 2023 08:07
Show Gist options
  • Select an option

  • Save hyuki/ab36070fae8d34d1cb9341b7b5a8f950 to your computer and use it in GitHub Desktop.

Select an option

Save hyuki/ab36070fae8d34d1cb9341b7b5a8f950 to your computer and use it in GitHub Desktop.
#ChatGPT と結城浩が共同で作ったコード(IFTTT ProでTwitterへのツイートをEvernoteのノートに保存するときに使うフィルタ)
// TypeScript v2.92
function padLeft(str: string, targetLength: number, padChar: string): string {
const padding = targetLength - str.length;
if (padding <= 0) {
return str;
}
return repeatString(padChar, padding) + str;
}
function repeatString(str: string, count: number): string {
let repeated = '';
for (let i = 0; i < count; i++) {
repeated += str;
}
return repeated;
}
function formatDate(input: string): string {
const months = {
January: '01',
February: '02',
March: '03',
April: '04',
May: '05',
June: '06',
July: '07',
August: '08',
September: '09',
October: '10',
November: '11',
December: '12',
};
const datePattern = /(\w+)\s(\d+),\s(\d{4})/;
const match = input.match(datePattern);
if (match) {
const month = months[match[1] as keyof typeof months];
const day = padLeft(match[2], 2, '0');
const year = match[3];
return `${year}-${month}-${day}`;
}
throw new Error('Invalid date format');
}
const tweet_date = formatDate(Twitter.newTweetByYou.CreatedAt);
const note_title = `My Tweet ${tweet_date}`;
Evernote.appendToNote.setTitle(note_title);
@hyuki
Copy link
Copy Markdown
Author

hyuki commented Apr 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment