This file contains 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
class Logger { | |
final String name; | |
bool mute = false; | |
static final Map<String, Logger> _cache = <String, Logger>{}; | |
factory Logger(String name) { | |
if(_cache.containsKey(name)) { | |
return _cache[name]; | |
} |
This file contains 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
/** | |
* Get time in months|days|hours|seconds|miliseconds later (or of) months|days|hours|seconds|miliseconds | |
* | |
* Examples: | |
* timeIn('second').later(30).minutes(); | |
* timeIn('second').of(2).days(); | |
* | |
* @param {string} name | |
* @return {object} { later, of } | |
*/ |
This file contains 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
// Load CSS file async | |
export const loadAsyncCss = (href: string | Array<string>, id, cb: () => void = null) => { | |
function createElement(d, s, href) { | |
var link = d.createElement(s); | |
link.href = href; | |
link.rel = 'stylesheet'; | |
return link; | |
} | |
(function (d, id, href, r) { | |
var fjs = d.getElementsByTagName('link')[0]; |
This file contains 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
/** | |
* Load JS file async | |
* | |
* @param url url of JS file | |
* @param cb Callback after file has loaded. | |
* @param wait_id id of element that being waited to load. | |
* @returns Promise<any> | |
*/ | |
export const loadAsyncJS = (url: string | Array<string>, cb?: (error?: any) => void, wait_src: string = null): Promise<any> => { | |
const createElement = (d, s, url) => { |
This file contains 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
/** | |
* Method to add one or more function handler on an element's onload event | |
* This is because onload cannot carry out many separate functions. | |
* | |
* @param {any} element DOM element | |
* @param {any} handler function | |
*/ | |
const addOnloadHandler = (element, handler) => { | |
if (typeof element.onload === 'function') { | |
const pre_func = element.onload; |
This file contains 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 bodauTiengViet = str => { | |
str = str.toLowerCase(); | |
str = str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g, 'a'); | |
str = str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g, 'e'); | |
str = str.replace(/ì|í|ị|ỉ|ĩ/g, 'i'); | |
str = str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g, 'o'); | |
str = str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g, 'u'); | |
str = str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g, 'y'); | |
str = str.replace(/đ/g, 'd'); | |
// 2 lines below to replace spaces to '-', uncomment if you need. |
This file contains 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
/** | |
* Function to compare 2 string by percentage. | |
* | |
* @see https://stackoverflow.com/a/36566052/1427748 | |
* @param {string} s1 | |
* @param {string} s2 | |
*/ | |
const similarity = (s1, s2) => { | |
function editDistance(s1, s2) { | |
s1 = s1.toLowerCase(); |