-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add @guardian/libs
code
#63
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
{ | ||
"name": "@guardian/libs", | ||
"version": "8.0.1", | ||
"private": true, | ||
"version": "8.0.0", | ||
"private": false, | ||
"description": "A collection of JavaScript libraries and TypeScript types for Guardian projects", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"original-libs": "npm:@guardian/[email protected]" | ||
}, | ||
"devDependencies": { | ||
"@types/wcag-contrast": "3.0.0", | ||
"jest-fetch-mock": "3.0.3", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import fs from 'node:fs'; | ||
import { commonStyle, teamStyles } from '../src/logger/teamStyles'; | ||
|
||
function generateSvg(): string { | ||
const teams = Object.entries(teamStyles); | ||
|
||
const padding = 10; | ||
const lineHeight = 24; | ||
const width = 600; | ||
const height = teams.length * lineHeight + padding * 2 + 60; | ||
|
||
const lines = teams.map((team, index) => { | ||
const [name, colours] = team; | ||
return `<div class="line"> | ||
<span class="label common">@guardian</span> | ||
<span class="label ${name}" style="background-color: ${colours.background}; color: ${colours.font}">${name}</span> | ||
<span class="label">message no.${index}</span> | ||
<span class="gap"></span> | ||
<span class="label log">console.log</span> | ||
</div>`; | ||
}); | ||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}"> | ||
<style> | ||
.wrapper { | ||
font-family: monospace; | ||
padding: ${padding}px; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
#console { | ||
width: 100%; | ||
height: 100%; | ||
border: 2px solid #999; | ||
border-radius: 5px | ||
} | ||
.line { | ||
display: flex; | ||
height: ${lineHeight}px; | ||
border-bottom: 1px solid #ccc; | ||
padding: 2px 10px; | ||
} | ||
.line.top { | ||
font-family: sans-serif; | ||
border-color: #999; | ||
border-width: 2px; | ||
} | ||
.label { | ||
display: inline-block; | ||
height: min-content; | ||
padding: 2px 3px; | ||
border-radius:3px | ||
} | ||
.label:nth-of-type(n+2) { | ||
margin-left: 3px; | ||
} | ||
.gap { | ||
flex-grow: 1; | ||
} | ||
.log { | ||
opacity: 0.7; | ||
text-decoration: underline; | ||
} | ||
|
||
.common { | ||
background-color: ${commonStyle.common.background}; | ||
color: ${commonStyle.common.font}; | ||
} | ||
</style> | ||
<foreignObject x="0" y="0" width="${width}" height="${height}"> | ||
<div class="wrapper" xmlns="http://www.w3.org/1999/xhtml"> | ||
<div id="console"> | ||
<div class="line top">Console</div> | ||
${lines.join('')} | ||
</div> | ||
</div> | ||
</foreignObject> | ||
</svg>`; | ||
return svg; | ||
} | ||
|
||
fs.writeFileSync(__dirname + '/../static/logger.svg', generateSvg()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { TeamSubscription } from '../logger/@types/logger'; | ||
import type { Switches } from '../switches/@types/Switches'; | ||
|
||
declare global { | ||
interface Window { | ||
guardian?: { | ||
logger?: { | ||
subscribeTo: TeamSubscription; | ||
unsubscribeFrom: TeamSubscription; | ||
teams: () => string[]; | ||
}; | ||
config?: { | ||
page?: { | ||
isPreview: boolean; | ||
}; | ||
switches?: Switches; | ||
}; | ||
}; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
libs/@guardian/libs/src/ArticleElementRole/ArticleElementRole.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ArticleElementRole } from './ArticleElementRole'; | ||
|
||
it('ArticleElementRole enum contains Standard', () => { | ||
expect(ArticleElementRole.Standard).toBeDefined(); | ||
}); |
15 changes: 15 additions & 0 deletions
15
libs/@guardian/libs/src/ArticleElementRole/ArticleElementRole.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// ----- Types ----- // | ||
|
||
enum ArticleElementRole { | ||
Standard, | ||
Immersive, | ||
Supporting, | ||
Showcase, | ||
Inline, | ||
Thumbnail, | ||
HalfWidth, | ||
} | ||
|
||
// ----- Exports ----- // | ||
|
||
export { ArticleElementRole }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `ArticleElementRole` | ||
|
||
ArticleElementRole is a semantic/layout-oriented property that's applied to elements in an article. It describes the "role" of that element in the piece and how it should be laid out within the page. Consider the example of an image: is the image filling a "supporting" role? is it just a thumbnail? is it "showcasing" something? | ||
|
||
Whilst most commonly used for images, it can also apply to atoms and embeds. | ||
|
||
## Usage | ||
|
||
```js | ||
import { ArticleElementRole } from '@guardian/libs'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ERR_INVALID_COOKIE = `Cookie must not contain invalid characters (space, tab and the following characters: '()<>@,;"/[]?={}')`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Cookies | ||
|
||
Robust API over `document.cookie`. | ||
|
||
### Usage | ||
|
||
```js | ||
import { | ||
getCookie, | ||
removeCookie, | ||
setCookie, | ||
setSessionCookie | ||
} from '@guardian/libs'; | ||
``` | ||
|
||
## Methods | ||
|
||
- [`setCookie({name, value, daysToLive?, isCrossSubdomain?})`](#setCookie) | ||
- [`setSessionCookie({name, value})`](#setSessionCookie) | ||
- [`getCookie({name, shouldMemoize?})`](#getCookie) | ||
- [`removeCookie(name)`](#removeCookie) | ||
|
||
## `setCookie({name, value, daysToLive?, isCrossSubdomain?})` | ||
|
||
Returns: `void` | ||
|
||
Sets a cookie taking a config object with name and value, optional daysToLive and optional isCrossSubdomain flag. | ||
|
||
#### `name` | ||
|
||
Type: `string` | ||
|
||
Name of the cookie. | ||
|
||
#### `value` | ||
|
||
Type: `string`<br> | ||
|
||
Value of the cookie. | ||
|
||
#### `daysToLive?` | ||
|
||
Type: `number` | ||
|
||
Days you would like this cookie to live for. | ||
|
||
#### `isCrossSubdomain?` | ||
|
||
Type: `boolean`<br> | ||
|
||
Set this true if the cookie is cross subdomain. | ||
|
||
### Example | ||
|
||
```js | ||
setCookie({name:'GU_country_code', value:'GB'}) | ||
setCookie({name:'GU_country_code', value:'GB', daysToLive: 7}) | ||
setCookie({name:'GU_country_code', value:'GB', daysToLive: 7, isCrossSubdomain: true}) | ||
``` | ||
|
||
## `setSessionCookie({name, value})` | ||
|
||
Returns: `void` | ||
|
||
Sets a session cookie (no expiry date) taking a config object with name and value. | ||
|
||
#### `name` | ||
|
||
Type: `string` | ||
|
||
Name of the cookie. | ||
|
||
#### `value` | ||
|
||
Type: `string`<br> | ||
|
||
Value of the cookie. | ||
|
||
### Example | ||
|
||
```js | ||
setSessionCookie({name:'GU_country_code', value: 'GB'}) | ||
``` | ||
|
||
## `getCookie({name, shouldMemoize?})` | ||
|
||
Returns: `cookie` value if it exists or `null`. Takes a config object with name and shouldMemoize params | ||
|
||
#### `name` | ||
|
||
Type: `string` | ||
|
||
Name of the cookie to retrieve. | ||
|
||
|
||
#### `shouldMemoize?` | ||
|
||
Type: `boolean`<br> | ||
|
||
When this is set to true it will keep the cookie in memory to avoid fetching more than once. | ||
|
||
|
||
### Example | ||
|
||
```js | ||
getCookie({name:'GU_geo_country'}); //GB | ||
getCookie({name:'GU_geo_country', shouldMemoize: true}); //GB | ||
``` | ||
|
||
## `removeCookie({name, currentDomainOnly?})` | ||
|
||
Returns: `void` | ||
|
||
Removes a cookie. | ||
|
||
#### `names` | ||
|
||
Type: `string` | ||
|
||
Name of the stored cookie to remove. | ||
|
||
#### `currentDomainOnly` | ||
|
||
Type: `boolean` | ||
|
||
Set to true if it's a cookie for current domain only, defaults to false | ||
### Example | ||
|
||
```js | ||
removeCookie({name:'GU_geo_country'}); | ||
removeCookie({name:'GU_geo_country', currentDomainOnly: true}); | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these sections now covered by a more general monorepo readme? maybe we could link to where that is, if it exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, this readme is the info gets displayed on npm for example, so it's still needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry — I was referring to the ones you removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no that's something we need to address, but probably beyond the scope of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, is it recorded somewhere that we need to address this? (on trello or similar)