@prezly/theme-kit-nextjs 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/build/adapter-nextjs/getBasePageProps.d.ts +9 -0
  4. package/build/adapter-nextjs/getBasePageProps.js +11 -0
  5. package/build/adapter-nextjs/getBasePageProps.js.map +1 -0
  6. package/build/adapter-nextjs/index.d.ts +2 -0
  7. package/build/adapter-nextjs/index.js +3 -0
  8. package/build/adapter-nextjs/index.js.map +1 -0
  9. package/build/adapter-nextjs/processRequest.d.ts +3 -0
  10. package/build/adapter-nextjs/processRequest.js +20 -0
  11. package/build/adapter-nextjs/processRequest.js.map +1 -0
  12. package/build/data-fetching/api/PrezlyApi.d.ts +43 -0
  13. package/build/data-fetching/api/PrezlyApi.js +139 -0
  14. package/build/data-fetching/api/PrezlyApi.js.map +1 -0
  15. package/build/data-fetching/api/getPrezlyApi.d.ts +4 -0
  16. package/build/data-fetching/api/getPrezlyApi.js +17 -0
  17. package/build/data-fetching/api/getPrezlyApi.js.map +1 -0
  18. package/build/data-fetching/api/index.d.ts +2 -0
  19. package/build/data-fetching/api/index.js +3 -0
  20. package/build/data-fetching/api/index.js.map +1 -0
  21. package/build/data-fetching/api/languages.d.ts +18 -0
  22. package/build/data-fetching/api/languages.js +117 -0
  23. package/build/data-fetching/api/languages.js.map +1 -0
  24. package/build/data-fetching/api/queries.d.ts +45 -0
  25. package/build/data-fetching/api/queries.js +35 -0
  26. package/build/data-fetching/api/queries.js.map +1 -0
  27. package/build/data-fetching/constants.d.ts +2 -0
  28. package/build/data-fetching/constants.js +3 -0
  29. package/build/data-fetching/constants.js.map +1 -0
  30. package/build/data-fetching/getAssetsUrl.d.ts +1 -0
  31. package/build/data-fetching/getAssetsUrl.js +5 -0
  32. package/build/data-fetching/getAssetsUrl.js.map +1 -0
  33. package/build/data-fetching/getLocalizedCategoryData.d.ts +10 -0
  34. package/build/data-fetching/getLocalizedCategoryData.js +31 -0
  35. package/build/data-fetching/getLocalizedCategoryData.js.map +1 -0
  36. package/build/data-fetching/getNewsroomLogoUrl.d.ts +3 -0
  37. package/build/data-fetching/getNewsroomLogoUrl.js +14 -0
  38. package/build/data-fetching/getNewsroomLogoUrl.js.map +1 -0
  39. package/build/data-fetching/getPrivacyPortalUrl.d.ts +8 -0
  40. package/build/data-fetching/getPrivacyPortalUrl.js +9 -0
  41. package/build/data-fetching/getPrivacyPortalUrl.js.map +1 -0
  42. package/build/data-fetching/getStoryPublicationDate.d.ts +3 -0
  43. package/build/data-fetching/getStoryPublicationDate.jsx +10 -0
  44. package/build/data-fetching/getStoryPublicationDate.jsx.map +1 -0
  45. package/build/data-fetching/getUploadcareGroupUrl.d.ts +1 -0
  46. package/build/data-fetching/getUploadcareGroupUrl.js +5 -0
  47. package/build/data-fetching/getUploadcareGroupUrl.js.map +1 -0
  48. package/build/data-fetching/index.d.ts +9 -0
  49. package/build/data-fetching/index.js +10 -0
  50. package/build/data-fetching/index.js.map +1 -0
  51. package/build/data-fetching/lib/getAlgoliaSettings.d.ts +4 -0
  52. package/build/data-fetching/lib/getAlgoliaSettings.js +18 -0
  53. package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -0
  54. package/build/data-fetching/lib/getEnvVariables.d.ts +4 -0
  55. package/build/data-fetching/lib/getEnvVariables.js +37 -0
  56. package/build/data-fetching/lib/getEnvVariables.js.map +1 -0
  57. package/build/data-fetching/types.d.ts +11 -0
  58. package/build/data-fetching/types.js +2 -0
  59. package/build/data-fetching/types.js.map +1 -0
  60. package/build/index.d.ts +5 -0
  61. package/build/index.js +6 -0
  62. package/build/index.js.map +1 -0
  63. package/build/intl/index.d.ts +4 -0
  64. package/build/intl/index.js +5 -0
  65. package/build/intl/index.js.map +1 -0
  66. package/build/intl/lang.d.ts +12 -0
  67. package/build/intl/lang.js +25 -0
  68. package/build/intl/lang.js.map +1 -0
  69. package/build/intl/locale.d.ts +10 -0
  70. package/build/intl/locale.js +93 -0
  71. package/build/intl/locale.js.map +1 -0
  72. package/build/intl/localeConfig.d.ts +2 -0
  73. package/build/intl/localeConfig.js +113 -0
  74. package/build/intl/localeConfig.js.map +1 -0
  75. package/build/intl/localeObject.d.ts +22 -0
  76. package/build/intl/localeObject.js +59 -0
  77. package/build/intl/localeObject.js.map +1 -0
  78. package/build/newsroom-context/context.d.ts +26 -0
  79. package/build/newsroom-context/context.jsx +22 -0
  80. package/build/newsroom-context/context.jsx.map +1 -0
  81. package/build/newsroom-context/hooks/index.d.ts +11 -0
  82. package/build/newsroom-context/hooks/index.js +12 -0
  83. package/build/newsroom-context/hooks/index.js.map +1 -0
  84. package/build/newsroom-context/hooks/useAlgoliaSettings.d.ts +1 -0
  85. package/build/newsroom-context/hooks/useAlgoliaSettings.js +6 -0
  86. package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -0
  87. package/build/newsroom-context/hooks/useCategories.d.ts +1 -0
  88. package/build/newsroom-context/hooks/useCategories.js +6 -0
  89. package/build/newsroom-context/hooks/useCategories.js.map +1 -0
  90. package/build/newsroom-context/hooks/useCompanyInformation.d.ts +1 -0
  91. package/build/newsroom-context/hooks/useCompanyInformation.js +6 -0
  92. package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -0
  93. package/build/newsroom-context/hooks/useCurrentLocale.d.ts +1 -0
  94. package/build/newsroom-context/hooks/useCurrentLocale.js +6 -0
  95. package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -0
  96. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.d.ts +2 -0
  97. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +21 -0
  98. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -0
  99. package/build/newsroom-context/hooks/useGetTranslationUrl.d.ts +2 -0
  100. package/build/newsroom-context/hooks/useGetTranslationUrl.js +36 -0
  101. package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -0
  102. package/build/newsroom-context/hooks/useLanguages.d.ts +1 -0
  103. package/build/newsroom-context/hooks/useLanguages.js +6 -0
  104. package/build/newsroom-context/hooks/useLanguages.js.map +1 -0
  105. package/build/newsroom-context/hooks/useNewsroom.d.ts +1 -0
  106. package/build/newsroom-context/hooks/useNewsroom.js +6 -0
  107. package/build/newsroom-context/hooks/useNewsroom.js.map +1 -0
  108. package/build/newsroom-context/hooks/useNewsroomContext.d.ts +2 -0
  109. package/build/newsroom-context/hooks/useNewsroomContext.js +12 -0
  110. package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -0
  111. package/build/newsroom-context/hooks/useSelectedCategory.d.ts +1 -0
  112. package/build/newsroom-context/hooks/useSelectedCategory.js +6 -0
  113. package/build/newsroom-context/hooks/useSelectedCategory.js.map +1 -0
  114. package/build/newsroom-context/hooks/useSelectedStory.d.ts +1 -0
  115. package/build/newsroom-context/hooks/useSelectedStory.js +6 -0
  116. package/build/newsroom-context/hooks/useSelectedStory.js.map +1 -0
  117. package/build/newsroom-context/index.d.ts +2 -0
  118. package/build/newsroom-context/index.js +3 -0
  119. package/build/newsroom-context/index.js.map +1 -0
  120. package/build/types.d.ts +38 -0
  121. package/build/types.js +2 -0
  122. package/build/types.js.map +1 -0
  123. package/package.json +60 -0
  124. package/src/@types/global.d.ts +7 -0
  125. package/src/adapter-nextjs/getBasePageProps.ts +23 -0
  126. package/src/adapter-nextjs/index.ts +2 -0
  127. package/src/adapter-nextjs/processRequest.ts +31 -0
  128. package/src/data-fetching/api/PrezlyApi.ts +240 -0
  129. package/src/data-fetching/api/getPrezlyApi.ts +24 -0
  130. package/src/data-fetching/api/index.ts +2 -0
  131. package/src/data-fetching/api/languages.ts +172 -0
  132. package/src/data-fetching/api/queries.ts +44 -0
  133. package/src/data-fetching/constants.ts +2 -0
  134. package/src/data-fetching/getAssetsUrl.ts +5 -0
  135. package/src/data-fetching/getLocalizedCategoryData.ts +47 -0
  136. package/src/data-fetching/getNewsroomLogoUrl.ts +21 -0
  137. package/src/data-fetching/getPrivacyPortalUrl.ts +22 -0
  138. package/src/data-fetching/getStoryPublicationDate.tsx +15 -0
  139. package/src/data-fetching/getUploadcareGroupUrl.ts +5 -0
  140. package/src/data-fetching/index.ts +9 -0
  141. package/src/data-fetching/lib/getAlgoliaSettings.ts +29 -0
  142. package/src/data-fetching/lib/getEnvVariables.ts +44 -0
  143. package/src/data-fetching/types.ts +12 -0
  144. package/src/index.ts +5 -0
  145. package/src/intl/index.ts +4 -0
  146. package/src/intl/lang.ts +36 -0
  147. package/src/intl/locale.ts +118 -0
  148. package/src/intl/localeConfig.js +116 -0
  149. package/src/intl/localeObject.ts +73 -0
  150. package/src/newsroom-context/context.tsx +73 -0
  151. package/src/newsroom-context/hooks/index.ts +11 -0
  152. package/src/newsroom-context/hooks/useAlgoliaSettings.ts +7 -0
  153. package/src/newsroom-context/hooks/useCategories.ts +7 -0
  154. package/src/newsroom-context/hooks/useCompanyInformation.ts +7 -0
  155. package/src/newsroom-context/hooks/useCurrentLocale.ts +7 -0
  156. package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +33 -0
  157. package/src/newsroom-context/hooks/useGetTranslationUrl.ts +61 -0
  158. package/src/newsroom-context/hooks/useLanguages.ts +7 -0
  159. package/src/newsroom-context/hooks/useNewsroom.ts +7 -0
  160. package/src/newsroom-context/hooks/useNewsroomContext.ts +14 -0
  161. package/src/newsroom-context/hooks/useSelectedCategory.ts +7 -0
  162. package/src/newsroom-context/hooks/useSelectedStory.ts +7 -0
  163. package/src/newsroom-context/index.ts +2 -0
  164. package/src/types.ts +56 -0
@@ -0,0 +1,31 @@
1
+ function isAlgoliaCategory(category) {
2
+ return 'name' in category && 'slug' in category;
3
+ }
4
+ export function getLocalizedCategoryData(category, locale) {
5
+ if (isAlgoliaCategory(category)) {
6
+ return {
7
+ description: null,
8
+ name: category.name,
9
+ slug: category.slug,
10
+ };
11
+ }
12
+ const targetLocaleCode = locale.toUnderscoreCode();
13
+ const { i18n } = category;
14
+ const populatedLocales = Object.keys(i18n).filter((localeCode) => i18n[localeCode].name);
15
+ const targetLocale = populatedLocales.find((localeCode) => localeCode === targetLocaleCode) ||
16
+ populatedLocales.find((localeCode) => i18n[localeCode].name === category.display_name) ||
17
+ populatedLocales[0];
18
+ const { locale: _, ...localizedData } = i18n[targetLocale];
19
+ return localizedData;
20
+ }
21
+ export function getCategoryUrl(category, locale) {
22
+ const { slug } = getLocalizedCategoryData(category, locale);
23
+ return `/category/${slug}`;
24
+ }
25
+ export function getCategoryHasTranslation(category, locale) {
26
+ const targetLocaleCode = locale.toUnderscoreCode();
27
+ const { i18n } = category;
28
+ const populatedLocales = Object.keys(i18n).filter((localeCode) => i18n[localeCode].name);
29
+ return Boolean(populatedLocales.find((localeCode) => localeCode === targetLocaleCode));
30
+ }
31
+ //# sourceMappingURL=getLocalizedCategoryData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocalizedCategoryData.js","sourceRoot":"","sources":["../../src/data-fetching/getLocalizedCategoryData.ts"],"names":[],"mappings":"AAKA,SAAS,iBAAiB,CACtB,QAAuC;IAEvC,OAAO,MAAM,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,wBAAwB,CACpC,QAAuC,EACvC,MAAoB;IAEpB,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE;QAC7B,OAAO;YACH,WAAW,EAAE,IAAI;YACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;SACtB,CAAC;KACL;IAED,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACnD,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC1B,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;IACzF,MAAM,YAAY,GACd,gBAAgB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,KAAK,gBAAgB,CAAC;QACtE,gBAAgB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,YAAY,CAAC;QACtF,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAExB,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,aAAa,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAE3D,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,QAAuC,EAAE,MAAoB;IACxF,MAAM,EAAE,IAAI,EAAE,GAAG,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC5D,OAAO,aAAa,IAAI,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,QAAkB,EAAE,MAAoB;IAC9E,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACnD,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC1B,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;IACzF,OAAO,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,KAAK,gBAAgB,CAAC,CAAC,CAAC;AAC3F,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Newsroom } from '@prezly/sdk';
2
+ export declare function getNewsroomLogoUrl(newsroom: Newsroom): string;
3
+ export declare function getNewsroomFaviconUrl(newsroom: Newsroom, previewSize?: number): string;
@@ -0,0 +1,14 @@
1
+ import { getAssetsUrl } from './getAssetsUrl';
2
+ export function getNewsroomLogoUrl(newsroom) {
3
+ if (newsroom.newsroom_logo) {
4
+ getAssetsUrl(newsroom.newsroom_logo.uuid);
5
+ }
6
+ return '';
7
+ }
8
+ export function getNewsroomFaviconUrl(newsroom, previewSize = 400) {
9
+ if (newsroom.icon) {
10
+ return `${getAssetsUrl(newsroom.icon.uuid)}-/preview/${previewSize}x${previewSize}/-/quality/best/`;
11
+ }
12
+ return '';
13
+ }
14
+ //# sourceMappingURL=getNewsroomLogoUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getNewsroomLogoUrl.js","sourceRoot":"","sources":["../../src/data-fetching/getNewsroomLogoUrl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,UAAU,kBAAkB,CAAC,QAAkB;IACjD,IAAI,QAAQ,CAAC,aAAa,EAAE;QACxB,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;KAC7C;IAED,OAAO,EAAE,CAAC;AACd,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,QAAkB,EAAE,WAAW,GAAG,GAAG;IACvE,IAAI,QAAQ,CAAC,IAAI,EAAE;QACf,OAAO,GAAG,YAAY,CAClB,QAAQ,CAAC,IAAI,CAAC,IAAI,CACrB,aAAa,WAAW,IAAI,WAAW,kBAAkB,CAAC;KAC9D;IAED,OAAO,EAAE,CAAC;AACd,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Newsroom } from '@prezly/sdk';
2
+ import { LocaleObject } from '../intl';
3
+ declare type PrivacyPortalUrlOptions = {
4
+ email?: string;
5
+ action?: 'subscribe' | 'unsubscribe';
6
+ };
7
+ export declare function getPrivacyPortalUrl(newsroom: Newsroom, locale: LocaleObject, options?: PrivacyPortalUrlOptions): string;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ export function getPrivacyPortalUrl(newsroom, locale, options) {
2
+ const { email, action = 'subscribe' } = options || {};
3
+ const url = new URL(`/${locale.toUrlSlug()}/newsroom/${newsroom.uuid}/${action}`, 'https://privacy.prezly.com');
4
+ if (email) {
5
+ url.searchParams.append('email', email);
6
+ }
7
+ return url.toString();
8
+ }
9
+ //# sourceMappingURL=getPrivacyPortalUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPrivacyPortalUrl.js","sourceRoot":"","sources":["../../src/data-fetching/getPrivacyPortalUrl.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,mBAAmB,CAC/B,QAAkB,EAClB,MAAoB,EACpB,OAAiC;IAEjC,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEtD,MAAM,GAAG,GAAG,IAAI,GAAG,CACf,IAAI,MAAM,CAAC,SAAS,EAAE,aAAa,QAAQ,CAAC,IAAI,IAAI,MAAM,EAAE,EAC5D,4BAA4B,CAC/B,CAAC;IACF,IAAI,KAAK,EAAE;QACP,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;KAC3C;IACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Story } from '@prezly/sdk';
2
+ import { AlgoliaStory } from '../types';
3
+ export declare function getStoryPublicationDate(story: Story | AlgoliaStory): Date | null;
@@ -0,0 +1,10 @@
1
+ export function getStoryPublicationDate(story) {
2
+ const { published_at } = story;
3
+ if (!published_at) {
4
+ return null;
5
+ }
6
+ return typeof published_at === 'string'
7
+ ? new Date(published_at)
8
+ : new Date(published_at * 1000);
9
+ }
10
+ //# sourceMappingURL=getStoryPublicationDate.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStoryPublicationDate.jsx","sourceRoot":"","sources":["../../src/data-fetching/getStoryPublicationDate.tsx"],"names":[],"mappings":"AAIA,MAAM,UAAU,uBAAuB,CAAC,KAA2B;IAC/D,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAE/B,IAAI,CAAC,YAAY,EAAE;QACf,OAAO,IAAI,CAAC;KACf;IAED,OAAO,OAAO,YAAY,KAAK,QAAQ;QACnC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC;QACxB,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function getUploadcareGroupUrl(uuid: string, title: string): string;
@@ -0,0 +1,5 @@
1
+ import { ASSETS_URL } from './constants';
2
+ export function getUploadcareGroupUrl(uuid, title) {
3
+ return `${ASSETS_URL}/${uuid}/archive/zip/${encodeURI(title)}.zip`;
4
+ }
5
+ //# sourceMappingURL=getUploadcareGroupUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUploadcareGroupUrl.js","sourceRoot":"","sources":["../../src/data-fetching/getUploadcareGroupUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,KAAa;IAC7D,OAAO,GAAG,UAAU,IAAI,IAAI,gBAAgB,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;AACvE,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from './api';
2
+ export * from './constants';
3
+ export * from './getAssetsUrl';
4
+ export * from './getLocalizedCategoryData';
5
+ export * from './getNewsroomLogoUrl';
6
+ export * from './getPrivacyPortalUrl';
7
+ export * from './getStoryPublicationDate';
8
+ export * from './getUploadcareGroupUrl';
9
+ export * from './types';
@@ -0,0 +1,10 @@
1
+ export * from './api';
2
+ export * from './constants';
3
+ export * from './getAssetsUrl';
4
+ export * from './getLocalizedCategoryData';
5
+ export * from './getNewsroomLogoUrl';
6
+ export * from './getPrivacyPortalUrl';
7
+ export * from './getStoryPublicationDate';
8
+ export * from './getUploadcareGroupUrl';
9
+ export * from './types';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/data-fetching/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage } from 'http';
3
+ import { AlgoliaSettings } from '../types';
4
+ export declare const getAlgoliaSettings: (req?: IncomingMessage | undefined) => AlgoliaSettings;
@@ -0,0 +1,18 @@
1
+ import { getEnvVariables } from './getEnvVariables';
2
+ export const getAlgoliaSettings = (req) => {
3
+ if (process.browser) {
4
+ throw new Error('"getAlgoliaSettings" should only be used on back-end side.');
5
+ }
6
+ // `getEnvVariables` handles both cases for envs parsing - .env and request headers
7
+ const { ALGOLIA_API_KEY = '', ALGOLIA_APP_ID = 'UI4CNRAHQB', ALGOLIA_INDEX = 'public_stories_prod', } = getEnvVariables(req);
8
+ if (!ALGOLIA_API_KEY) {
9
+ // eslint-disable-next-line no-console
10
+ console.error('"ALGOLIA_API_KEY" is not set in env variables. Search will not be enabled');
11
+ }
12
+ return {
13
+ ALGOLIA_API_KEY,
14
+ ALGOLIA_APP_ID,
15
+ ALGOLIA_INDEX,
16
+ };
17
+ };
18
+ //# sourceMappingURL=getAlgoliaSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getAlgoliaSettings.js","sourceRoot":"","sources":["../../../src/data-fetching/lib/getAlgoliaSettings.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAqB,EAAmB,EAAE;IACzE,IAAI,OAAO,CAAC,OAAO,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;KACjF;IAED,mFAAmF;IACnF,MAAM,EACF,eAAe,GAAG,EAAE,EACpB,cAAc,GAAG,YAAY,EAC7B,aAAa,GAAG,qBAAqB,GACxC,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAEzB,IAAI,CAAC,eAAe,EAAE;QAClB,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;KAC9F;IAED,OAAO;QACH,eAAe;QACf,cAAc;QACd,aAAa;KAChB,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import type { IncomingMessage } from 'http';
3
+ import type { PrezlyEnv } from '../types';
4
+ export declare const getEnvVariables: (req?: IncomingMessage | undefined) => PrezlyEnv;
@@ -0,0 +1,37 @@
1
+ import parseDataUrl from 'parse-data-url';
2
+ const decodeJson = (json) => {
3
+ try {
4
+ const decoded = JSON.parse(json);
5
+ if (decoded && typeof decoded === 'object') {
6
+ return decoded;
7
+ }
8
+ }
9
+ catch {
10
+ // passthru
11
+ }
12
+ return {};
13
+ };
14
+ const decodeHttpEnv = (header) => {
15
+ if (header.startsWith('data:')) {
16
+ const parsed = parseDataUrl(header);
17
+ if (parsed && parsed.contentType === 'application/json') {
18
+ const data = parsed.toBuffer().toString('utf-8');
19
+ return decodeJson(data);
20
+ }
21
+ return {}; // unsupported data-uri
22
+ }
23
+ return decodeJson(header);
24
+ };
25
+ export const getEnvVariables = (req) => {
26
+ if (process.browser) {
27
+ throw new Error('"getEnvVariables" should only be used on back-end side.');
28
+ }
29
+ const headerName = (process.env.HTTP_ENV_HEADER || '').toLowerCase();
30
+ if (headerName && req) {
31
+ const header = req.headers[headerName];
32
+ const httpEnv = decodeHttpEnv(header || '');
33
+ return { ...process.env, ...httpEnv };
34
+ }
35
+ return { ...process.env };
36
+ };
37
+ //# sourceMappingURL=getEnvVariables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getEnvVariables.js","sourceRoot":"","sources":["../../../src/data-fetching/lib/getEnvVariables.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAI1C,MAAM,UAAU,GAAG,CAAC,IAAY,EAAuB,EAAE;IACrD,IAAI;QACA,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YACxC,OAAO,OAAO,CAAC;SAClB;KACJ;IAAC,MAAM;QACJ,WAAW;KACd;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,MAAc,EAAuB,EAAE;IAC1D,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,MAAM,IAAI,MAAM,CAAC,WAAW,KAAK,kBAAkB,EAAE;YACrD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACjD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;SAC3B;QACD,OAAO,EAAE,CAAC,CAAC,uBAAuB;KACrC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAqB,EAAa,EAAE;IAChE,IAAI,OAAO,CAAC,OAAO,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;KAC9E;IAED,MAAM,UAAU,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAErE,IAAI,UAAU,IAAI,GAAG,EAAE;QACnB,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,CAAuB,CAAC;QAC7D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;QAC5C,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;KACzC;IAED,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAC9B,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ export interface AlgoliaSettings {
2
+ ALGOLIA_API_KEY: string;
3
+ ALGOLIA_APP_ID: string;
4
+ ALGOLIA_INDEX: string;
5
+ }
6
+ export interface PrezlyNewsroomEnv {
7
+ PREZLY_ACCESS_TOKEN: string;
8
+ PREZLY_NEWSROOM_UUID: string;
9
+ }
10
+ export interface PrezlyEnv extends PrezlyNewsroomEnv, AlgoliaSettings {
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/data-fetching/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from './adapter-nextjs';
2
+ export * from './data-fetching';
3
+ export * from './intl';
4
+ export * from './newsroom-context';
5
+ export * from './types';
package/build/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './adapter-nextjs';
2
+ export * from './data-fetching';
3
+ export * from './intl';
4
+ export * from './newsroom-context';
5
+ export * from './types';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './lang';
2
+ export * from './locale';
3
+ export { default as localeConfig } from './localeConfig';
4
+ export * from './localeObject';
@@ -0,0 +1,5 @@
1
+ export * from './lang';
2
+ export * from './locale';
3
+ export { default as localeConfig } from './localeConfig';
4
+ export * from './localeObject';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intl/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { NewsroomLanguageSettings } from '@prezly/sdk';
2
+ /**
3
+ * If there's only one culture used in a specific language,
4
+ * we strip the culture name completely.
5
+ *
6
+ * Examples:
7
+ * - English (Global), Spanish (Spain)
8
+ * -> English, Spanish
9
+ * - English (Global), English (UK), Spanish (Spain)
10
+ * -> English (Global), English (UK), Spanish
11
+ */
12
+ export declare function getLanguageDisplayName(language: NewsroomLanguageSettings, languages: NewsroomLanguageSettings[]): string;
@@ -0,0 +1,25 @@
1
+ function isOnlyCulture(culture, languages) {
2
+ const numberOfLanguages = languages.filter(({ locale: { language_code } }) => language_code === culture.language_code).length;
3
+ return numberOfLanguages === 1;
4
+ }
5
+ /**
6
+ * If there's only one culture used in a specific language,
7
+ * we strip the culture name completely.
8
+ *
9
+ * Examples:
10
+ * - English (Global), Spanish (Spain)
11
+ * -> English, Spanish
12
+ * - English (Global), English (UK), Spanish (Spain)
13
+ * -> English (Global), English (UK), Spanish
14
+ */
15
+ export function getLanguageDisplayName(language, languages) {
16
+ const { locale } = language;
17
+ if (isOnlyCulture(locale, languages)) {
18
+ const cultureNameIndex = locale.native_name.indexOf('(');
19
+ if (cultureNameIndex !== -1) {
20
+ return locale.native_name.slice(0, cultureNameIndex - 1);
21
+ }
22
+ }
23
+ return locale.native_name;
24
+ }
25
+ //# sourceMappingURL=lang.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lang.js","sourceRoot":"","sources":["../../src/intl/lang.ts"],"names":[],"mappings":"AAEA,SAAS,aAAa,CAAC,OAAmB,EAAE,SAAqC;IAC7E,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,CACtC,CAAC,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,EAAE,CAAC,aAAa,KAAK,OAAO,CAAC,aAAa,CAC7E,CAAC,MAAM,CAAC;IAET,OAAO,iBAAiB,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAClC,QAAkC,EAClC,SAAqC;IAErC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAE5B,IAAI,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE;QAClC,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAEzD,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE;YACzB,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,CAAC,CAAC;SAC5D;KACJ;IAED,OAAO,MAAM,CAAC,WAAW,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="node" />
2
+ import type { Redirect } from 'next';
3
+ import { ParsedUrlQuery } from 'querystring';
4
+ import { BasePageProps } from '../types';
5
+ import { LocaleObject } from './localeObject';
6
+ export declare const DEFAULT_LOCALE = "en";
7
+ export declare const DUMMY_DEFAULT_LOCALE = "qps-ploc";
8
+ export declare function getSupportedLocaleIsoCode(locale: LocaleObject): string;
9
+ export declare function getRedirectToCanonicalLocale(basePageProps: BasePageProps, nextLocaleIsoCode: string | undefined, redirectPath: string, query?: ParsedUrlQuery): Redirect | undefined;
10
+ export declare function getLocaleDirection(locale: LocaleObject): 'ltr' | 'rtl';
@@ -0,0 +1,93 @@
1
+ import { stringify } from 'querystring';
2
+ import { LocaleObject } from './localeObject';
3
+ export const DEFAULT_LOCALE = 'en';
4
+ export const DUMMY_DEFAULT_LOCALE = 'qps-ploc';
5
+ const SUPPORTED_LOCALES = [
6
+ 'af',
7
+ 'ar',
8
+ 'az',
9
+ 'be',
10
+ 'bg',
11
+ 'cs',
12
+ 'da',
13
+ 'de',
14
+ 'el',
15
+ 'en',
16
+ 'es',
17
+ 'et',
18
+ 'fi',
19
+ 'fil',
20
+ 'fr',
21
+ 'ga',
22
+ 'he',
23
+ 'hi',
24
+ 'hr',
25
+ 'hu',
26
+ 'id',
27
+ 'it',
28
+ 'ja',
29
+ 'kk',
30
+ 'ko',
31
+ 'lt',
32
+ 'lv',
33
+ 'mt',
34
+ 'nl',
35
+ 'no',
36
+ 'pl',
37
+ 'pt-BR',
38
+ 'pt',
39
+ 'ro',
40
+ 'ru',
41
+ 'sk',
42
+ 'sl',
43
+ 'sv',
44
+ 'th',
45
+ 'tr',
46
+ 'uk',
47
+ 'ur',
48
+ 'uz',
49
+ 'vi',
50
+ 'zh-CN',
51
+ 'zh-TW',
52
+ ];
53
+ export function getSupportedLocaleIsoCode(locale) {
54
+ const localeIsoCode = locale.toHyphenCode();
55
+ const isSupportedLocale = localeIsoCode.length >= 2 && SUPPORTED_LOCALES.includes(localeIsoCode);
56
+ if (isSupportedLocale) {
57
+ return localeIsoCode;
58
+ }
59
+ const language = localeIsoCode.slice(0, 2);
60
+ const isSupportedLanguage = SUPPORTED_LOCALES.includes(language);
61
+ if (isSupportedLanguage) {
62
+ return language;
63
+ }
64
+ return DEFAULT_LOCALE;
65
+ }
66
+ export function getRedirectToCanonicalLocale(basePageProps, nextLocaleIsoCode, redirectPath, query) {
67
+ const { shortestLocaleCode } = basePageProps;
68
+ const shortestLocaleSlug = shortestLocaleCode
69
+ ? LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug()
70
+ : shortestLocaleCode;
71
+ if (nextLocaleIsoCode === DUMMY_DEFAULT_LOCALE) {
72
+ return undefined;
73
+ }
74
+ if (shortestLocaleSlug !== nextLocaleIsoCode) {
75
+ const prefixedPath = redirectPath && !redirectPath.startsWith('/') ? `/${redirectPath}` : redirectPath;
76
+ const urlQuery = query ? `?${stringify(query)}` : '';
77
+ return {
78
+ destination: shortestLocaleSlug
79
+ ? `/${shortestLocaleSlug}${prefixedPath}${urlQuery}`
80
+ : `${prefixedPath}${urlQuery}`,
81
+ permanent: false,
82
+ };
83
+ }
84
+ return undefined;
85
+ }
86
+ export function getLocaleDirection(locale) {
87
+ const neutralLanguageCode = locale.toNeutralLanguageCode();
88
+ if (['ar', 'he', 'ur'].includes(neutralLanguageCode)) {
89
+ return 'rtl';
90
+ }
91
+ return 'ltr';
92
+ }
93
+ //# sourceMappingURL=locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export = lowercaseLocalPermutations;
2
+ declare const lowercaseLocalPermutations: string[];
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ // This list is pulled from the main Prezly application. The underscores are replaced with dashes.
3
+ const supportedLocales = [
4
+ 'af-ZA',
5
+ 'ar',
6
+ 'ar-AE',
7
+ 'ar-BH',
8
+ 'ar-QA',
9
+ 'ar-SA',
10
+ 'az',
11
+ 'be',
12
+ 'bg-BG',
13
+ 'cs-CZ',
14
+ 'da-DK',
15
+ 'de',
16
+ 'de-DE',
17
+ 'de-AT',
18
+ 'de-CH',
19
+ 'el-GR',
20
+ 'en',
21
+ 'en-US',
22
+ 'en-AE',
23
+ 'en-AU',
24
+ 'en-BD',
25
+ 'en-BE',
26
+ 'en-BH',
27
+ 'en-CA',
28
+ 'en-CN',
29
+ 'en-DE',
30
+ 'en-DK',
31
+ 'en-GB',
32
+ 'en-HK',
33
+ 'en-ID',
34
+ 'en-IE',
35
+ 'en-IL',
36
+ 'en-IN',
37
+ 'en-JP',
38
+ 'en-KH',
39
+ 'en-KR',
40
+ 'en-LK',
41
+ 'en-MV',
42
+ 'en-MM',
43
+ 'en-MY',
44
+ 'en-NP',
45
+ 'en-NZ',
46
+ 'en-PH',
47
+ 'en-PK',
48
+ 'en-QA',
49
+ 'en-SA',
50
+ 'en-SG',
51
+ 'en-TH',
52
+ 'en-TW',
53
+ 'en-VN',
54
+ 'en-ZA',
55
+ 'es',
56
+ 'es-ES',
57
+ 'es-MX',
58
+ 'et-EE',
59
+ 'fi-FI',
60
+ 'fil',
61
+ 'fr',
62
+ 'fr-BE',
63
+ 'fr-FR',
64
+ 'fr-CA',
65
+ 'fr-LU',
66
+ 'ga-IE',
67
+ 'he-IL',
68
+ 'hi-IN',
69
+ 'hr-HR',
70
+ 'hu-HU',
71
+ 'id-ID',
72
+ 'it-IT',
73
+ 'ja-JP',
74
+ 'kk',
75
+ 'ko-KR',
76
+ 'ky',
77
+ 'lt-LT',
78
+ 'lv-LV',
79
+ 'mt-MT',
80
+ 'ms-MY',
81
+ 'nb-NO',
82
+ 'nl',
83
+ 'nl-BE',
84
+ 'nl-NL',
85
+ 'pl-PL',
86
+ 'pt',
87
+ 'pt-BR',
88
+ 'pt-PT',
89
+ 'ro-RO',
90
+ 'ru-RU',
91
+ 'sk-SK',
92
+ 'sl-SI',
93
+ 'sv-SE',
94
+ 'th-TH',
95
+ 'tr-TR',
96
+ 'uk-UA',
97
+ 'ur-PK',
98
+ 'uz',
99
+ 'vi-VN',
100
+ 'zh-Hant',
101
+ 'zh-HK',
102
+ 'zh-TW',
103
+ 'zh-CN',
104
+ ];
105
+ const lowercaseLocales = supportedLocales.map((l) => l.toLowerCase());
106
+ // Get all permutations for the shorter locale codes supported by Prezly (e.g. short region codes)
107
+ const lowercaseLocalPermutations = Array.from(new Set([
108
+ ...lowercaseLocales,
109
+ ...lowercaseLocales.map((code) => code.split('-')[0]),
110
+ ...lowercaseLocales.map((code) => code.split('-')[1]).filter(Boolean),
111
+ ])).sort();
112
+ module.exports = lowercaseLocalPermutations;
113
+ //# sourceMappingURL=localeConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeConfig.js","sourceRoot":"","sources":["../../src/intl/localeConfig.js"],"names":[],"mappings":";AAAA,kGAAkG;AAClG,MAAM,gBAAgB,GAAG;IACrB,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,KAAK;IACL,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,SAAS;IACT,OAAO;IACP,OAAO;IACP,OAAO;CACV,CAAC;AAEF,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAEtE,kGAAkG;AAClG,MAAM,0BAA0B,GAAG,KAAK,CAAC,IAAI,CACzC,IAAI,GAAG,CAAC;IACJ,GAAG,gBAAgB;IACnB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;CACxE,CAAC,CACL,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,CAAC,OAAO,GAAG,0BAA0B,CAAC"}
@@ -0,0 +1,22 @@
1
+ export declare class LocaleObject {
2
+ /**
3
+ * Hyphen-separated locale code.
4
+ * Examples: `nl-BE`, `en-US`, `fr`, `fil`
5
+ */
6
+ private localeCode;
7
+ private constructor();
8
+ /**
9
+ * @param localeCode Locale code in any of the formats below.
10
+ * Examples:
11
+ * - Hyphen-codes: `nl-BE`, `en-US`, `fr`, `fil`
12
+ * - Underscore-codes: `nl_BE`, `en_US`, `fr`, `fil`
13
+ * - Slugs: `nl-be`, `en-us`, `fr`, `fil`
14
+ */
15
+ static fromAnyCode(localeCode: string): LocaleObject;
16
+ toHyphenCode(): string;
17
+ toUnderscoreCode(): string;
18
+ toUrlSlug(): string;
19
+ toNeutralLanguageCode(): string;
20
+ toRegionCode(): string;
21
+ isEqual(anotherLocale: LocaleObject): boolean;
22
+ }
@@ -0,0 +1,59 @@
1
+ import localeConfig from './localeConfig';
2
+ export class LocaleObject {
3
+ /**
4
+ * Hyphen-separated locale code.
5
+ * Examples: `nl-BE`, `en-US`, `fr`, `fil`
6
+ */
7
+ localeCode;
8
+ constructor(localeCode) {
9
+ if (localeCode.indexOf('_') !== -1) {
10
+ throw new Error('Invalid locale code provided!');
11
+ }
12
+ const [language, region] = localeCode.split('-');
13
+ if (region) {
14
+ this.localeCode = [language, region.toUpperCase()].join('-');
15
+ }
16
+ else {
17
+ this.localeCode = language;
18
+ }
19
+ }
20
+ /**
21
+ * @param localeCode Locale code in any of the formats below.
22
+ * Examples:
23
+ * - Hyphen-codes: `nl-BE`, `en-US`, `fr`, `fil`
24
+ * - Underscore-codes: `nl_BE`, `en_US`, `fr`, `fil`
25
+ * - Slugs: `nl-be`, `en-us`, `fr`, `fil`
26
+ */
27
+ static fromAnyCode(localeCode) {
28
+ const lowercaseCode = localeCode.toLowerCase().replace('_', '-');
29
+ const foundCode = localeConfig.find((code) => code === lowercaseCode);
30
+ if (!foundCode) {
31
+ throw new Error(`Unsupported locale code provided: "${lowercaseCode}"`);
32
+ }
33
+ return new LocaleObject(foundCode);
34
+ }
35
+ toHyphenCode() {
36
+ return this.localeCode;
37
+ }
38
+ toUnderscoreCode() {
39
+ return this.localeCode.replace('-', '_');
40
+ }
41
+ toUrlSlug() {
42
+ return this.localeCode.toLowerCase();
43
+ }
44
+ toNeutralLanguageCode() {
45
+ const [language] = this.localeCode.split('-');
46
+ return language;
47
+ }
48
+ toRegionCode() {
49
+ const [language, region] = this.localeCode.split('-');
50
+ if (!region) {
51
+ return language.toUpperCase();
52
+ }
53
+ return region.toUpperCase();
54
+ }
55
+ isEqual(anotherLocale) {
56
+ return anotherLocale.toHyphenCode() === this.localeCode;
57
+ }
58
+ }
59
+ //# sourceMappingURL=localeObject.js.map