index.ts 984 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export const groupBy = function (xs, key) {
  2. return xs.reduce(function (rv, x) {
  3. ;(rv[x[key]] = rv[x[key]] || []).push(x)
  4. return rv
  5. }, {})
  6. }
  7. export const sortByKeys = function (xs) {
  8. return Object.keys(xs)
  9. .sort()
  10. .reduce((obj, key) => {
  11. obj[key] = xs[key]
  12. return obj
  13. }, {})
  14. }
  15. export const toPascalCase = function (text: string) {
  16. return text
  17. .replace(new RegExp(/[-_]+/, "g"), " ")
  18. .replace(new RegExp(/[^\w\s]/, "g"), "")
  19. .replace(
  20. new RegExp(/\s+(.)(\w+)/, "g"),
  21. ($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`
  22. )
  23. .replace(new RegExp(/\s/, "g"), "")
  24. .replace(new RegExp(/\w/), (s) => s.toUpperCase())
  25. }
  26. export const baseUrl = {
  27. development: "http://localhost:3000",
  28. production: "https://tabler-icons.io",
  29. }[process.env.NODE_ENV]
  30. export const getCurrentBrand = (hostname: string) => {
  31. if (hostname && hostname.match(/tabler-icons/)) {
  32. return "tabler-icons"
  33. }
  34. return "tabler-ui"
  35. }