diff --git a/README.md b/README.md index 4d4f41a7..75de4d77 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ - [Modules](#modules) - [`cookies`](#cookies) - [Countries](#countries) + - [`format`](#format) - [`getLocale`](#getlocale) - [`getSwitches`](#getswitches) - [`isBoolean`](#isboolean) @@ -45,6 +46,10 @@ API over `document.cookies`. Country data and methods to access it. +### [`format`](./src/format.README.md) + +Types and enums related to editorial formats. + ### [`getLocale`](./src/getLocale.README.md) Get the user’s current location. diff --git a/src/format.README.md b/src/format.README.md new file mode 100644 index 00000000..fea4633c --- /dev/null +++ b/src/format.README.md @@ -0,0 +1,15 @@ +# `format` + +Types and enums related to editorial formats. + +## Usage + +```js +import type { ArticleTheme, ArticleFormat } from '@guardian/libs'; +import { + ArticlePillar, + ArticleSpecial, + ArticleDesign, + ArticleDisplay, +} from '@guardian/libs'; +``` diff --git a/src/format.test.ts b/src/format.test.ts new file mode 100644 index 00000000..22a5cabf --- /dev/null +++ b/src/format.test.ts @@ -0,0 +1,22 @@ +import { + ArticleDesign, + ArticleDisplay, + ArticlePillar, + ArticleSpecial, +} from './format'; + +it('Design enum contains Article', () => { + expect(ArticleDesign.Article).toBeDefined(); +}); + +it('Display enum contains Standard', () => { + expect(ArticleDisplay.Standard).toBeDefined(); +}); + +it('Pillar enum contains News', () => { + expect(ArticlePillar.News).toBe(0); +}); + +it('Special enum contains SpecialReport', () => { + expect(ArticleSpecial.SpecialReport).toBe(5); +}); diff --git a/src/format.ts b/src/format.ts new file mode 100644 index 00000000..124b8448 --- /dev/null +++ b/src/format.ts @@ -0,0 +1,55 @@ +// ----- Types ----- // + +enum ArticlePillar { + News = 0, + Opinion = 1, + Sport = 2, + Culture = 3, + Lifestyle = 4, +} + +enum ArticleSpecial { + SpecialReport = 5, + Labs = 6, +} + +type ArticleTheme = ArticlePillar | ArticleSpecial; + +enum ArticleDesign { + Article, + Media, + Review, + Analysis, + Comment, + Letter, + Feature, + LiveBlog, + DeadBlog, + Recipe, + MatchReport, + Interview, + Editorial, + Quiz, + Interactive, + PhotoEssay, + PrintShop, + Obituary, +} + +enum ArticleDisplay { + Standard, + Immersive, + Showcase, + NumberedList, +} + +interface ArticleFormat { + theme: ArticleTheme; + design: ArticleDesign; + display: ArticleDisplay; +} + +// ----- Exports ----- // + +export type { ArticleTheme, ArticleFormat }; +export { ArticlePillar, ArticleSpecial, ArticleDesign, ArticleDisplay }; diff --git a/src/index.ts b/src/index.ts index 2bb5fb81..2f599e95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,13 @@ export { export type { Country } from './countries'; export { countries, getCountryByCountryCode } from './countries'; export type { CountryCode } from './@types/countries'; +export type { ArticleTheme, ArticleFormat } from './format'; +export { + ArticlePillar, + ArticleSpecial, + ArticleDesign, + ArticleDisplay, +} from './format'; export { getLocale } from './getLocale'; export { getSwitches } from './getSwitches'; export { isBoolean } from './isBoolean';