@guardian/libs
TypeScript icon, indicating that this package has built-in type declarations

16.1.0 • Public • Published

@guardian/libs

npm (scoped) ES version npm type definitions

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.

Installation

Generic badge

yarn add @guardian/libs

or

npm install @guardian/libs

then

import { loadScript, storage, ...etc } from '@guardian/libs';

Bundling

This package uses ES2020.

If your target environment does not support that, make sure you transpile this package when bundling your application.

Local Testing Using Linking

  1. In the command line in your terminal, navigate to the csnx root directory. Run:
make @guardian/libs:build

This build command has to be re-run for changes to be picked up.

  1. Navigate to the repo that will test your code changes. In the appropriate folder of that repo, run
npm/yarn/pnpm link ../csnx/dist/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.

  1. Once you’ve developed your changes and tested, you can unlink from the repo where you are testing the changes
npm/yarn/pnpm unlink ../csnx/dist/libs/@guardian/libs

Readme

Keywords

none

Package Sidebar

Install

npm i @guardian/libs

Weekly Downloads

2,181

Version

16.1.0

License

MIT

Unpacked Size

745 kB

Total Files

420

Last publish

Collaborators

  • joecowton1
  • guardian-developers
  • akash1810
  • reetta
  • sndrs
  • mxdvl