A collection of JavaScript libraries and TypeScript types for Guardian projects
npm install @guardian/libs@guardian/libs


> A collection of JavaScript libraries and TypeScript types for Guardian projects
Type that describes the role of an element in an article.
The Guardian's consent management platform.
API over document.cookies.
Country data and methods to access it.
Codified editorial design and information architecture.
Get the user’s current location.
Get the active switches on theguardian.com.
Check whether a value is a boolean.
Check whether a value is a NonNullable.
Checks whether a value is a plain object (i.e. {}-like).
Check whether a value is one of a set of literal string or numbers.
Check whether a value is a string.
Check whether a value is undefined.
Combines separate url parts into one valid url string.
Inject an external JavaScript file.
Selectively log team-specific messages to the console.
Types relating to Ophan.
API over window.performance with hooks into log the data warehouse.
Robust API over localStorage and sessionStorage.
Format absolute dates as time-ago strings.
Utility for extracting a useful error message from Errors (or other values) that can be thrown in JavaScript.

``bash`
yarn add @guardian/libs
or
`bash`
npm install @guardian/libs
then
`js`
import { loadScript, storage, ...etc } from '@guardian/libs';
This package uses ES2020.
If your target environment does not support that, make sure you transpile this package when bundling your application.
1. In the command line in your terminal, navigate to the csnx root directory. Run:
`sh`
make @guardian/libs:build
This build command has to be re-run for changes to be picked up.
2. Navigate to the repo that will test your code changes. In the appropriate folder of that repo, run
`sh`
npm/yarn/pnpm link ../csnx/libs/@guardian/libs
where '../csnx' is the path to your local changes in csnx where you cloned the csnx code to.
After re-building the '@guardian/libs' in step 1. this command does not have to be repeated and changes will be automatically picked up.
3. Once you’ve developed your changes and tested, you can unlink from the repo where you are testing the changes
`sh``
npm/yarn/pnpm unlink ../csnx/libs/@guardian/libs