Created
March 23, 2018 04:03
-
-
Save ghiculescu/d33b524c30416adf2313aaaa23a3e755 to your computer and use it in GitHub Desktop.
moment.js locale whitelist
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
def moment_js_locale | |
# to generate this list, go to https://cdnjs.com/libraries/moment.js | |
# and run this in the console: | |
# $('.library-url').map((index, cell) => "'" + $(cell).text().replace("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/locale/", "").replace(".js", "") + "'").get().join(", ") | |
valid_moment_js_locales = Set.new(['af', 'ar-dz', 'ar-kw', 'ar-ly', 'ar-ma', 'ar-sa', 'ar-tn', 'ar', 'az', 'be', 'bg', 'bm', 'bn', 'bo', 'br', 'bs', 'ca', 'cs', 'cv', 'cy', 'da', 'de-at', 'de-ch', 'de', 'dv', 'el', 'en-au', 'en-ca', 'en-gb', 'en-ie', 'en-il', 'en-nz', 'eo', 'es-do', 'es-us', 'es', 'et', 'eu', 'fa', 'fi', 'fo', 'fr-ca', 'fr-ch', 'fr', 'fy', 'gd', 'gl', 'gom-latn', 'gu', 'he', 'hi', 'hr', 'hu', 'hy-am', 'id', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'ky', 'lb', 'lo', 'lt', 'lv', 'me', 'mi', 'mk', 'ml', 'mr', 'ms-my', 'ms', 'mt', 'my', 'nb', 'ne', 'nl-be', 'nl', 'nn', 'pa-in', 'pl', 'pt-br', 'pt', 'ro', 'ru', 'sd', 'se', 'si', 'sk', 'sl', 'sq', 'sr-cyrl', 'sr', 'ss', 'sv', 'sw', 'ta', 'te', 'tet', 'tg', 'th', 'tl-ph', 'tlh', 'tr', 'tzl', 'tzm-latn', 'tzm', 'ug-cn', 'uk', 'ur', 'uz-latn', 'uz', 'vi', 'x-pseudo', 'yo', 'zh-cn', 'zh-hk', 'zh-tw']) | |
temp_locale = locale.downcase | |
# whitelist algorithm: https://github.com/TandaHQ/payaus/pull/3158#discussion_r174992209 | |
return temp_locale if valid_moment_js_locales.include?(temp_locale) | |
until !temp_locale.include?('-') | |
split = temp_locale.split('-') | |
temp_locale = split.first(split.count - 1).join('-') | |
return temp_locale if valid_moment_js_locales.include?(temp_locale) | |
end | |
'en' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment