Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active July 4, 2022 07:38
Show Gist options
  • Save jirawatee/a34e9679803d6a94d776febe708b2ecc to your computer and use it in GitHub Desktop.
Save jirawatee/a34e9679803d6a94d776febe708b2ecc to your computer and use it in GitHub Desktop.
Example of LIFF plugin
class BMIPlugin {
constructor() {
this.name = "bmi";
}
install(context, option) {
return {
today: this.localDate(context.liff.getLanguage(), option.date),
greet: this.greeting,
cal: this.calculate
};
}
localDate(lang, date) {
const locale = (lang === "en")? "en-US": "th-TH";
return date.toLocaleDateString(locale, {
year: '2-digit',
month: 'short',
day: 'numeric',
});
}
greeting(lang, profile) {
const prefix = (lang === "en")? "Hello": "สวัสดี";
return `${prefix} ${profile.displayName}!`;
}
calculate(height, weight) {
const heightInMeter = height / 100;
const bmi = (weight / (heightInMeter * heightInMeter)).toFixed(2);
let result = "none";
if (bmi < 18.5) {
result = "XS";
} else if (bmi >= 18.5 && bmi < 23) {
result = "S";
} else if (bmi >= 23 && bmi < 25) {
result = "M";
} else if (bmi >= 25 && bmi < 30) {
result = "L";
} else if (bmi >= 30) {
result = "XL";
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment