Skip to content

Instantly share code, notes, and snippets.

View kieranbarker's full-sized avatar

Kieran Barker kieranbarker

View GitHub Profile
@kieranbarker
kieranbarker / .gitignore
Last active August 23, 2020 12:31
A simple .gitignore for Eleventy projects
# Misc
*.log
npm-debug.*
*.scssc
*.swp
.DS_Store
Thumbs.db
.sass-cache
.env
.cache
@kieranbarker
kieranbarker / visuallyHidden.css
Last active August 23, 2020 12:33
Visually hide an element but keep it accessible to screen readers
/**
* Visually hide an element but keep it accessible to screen readers
* {@link https://github.com/h5bp/html5-boilerplate/blob/master/dist/css/main.css}
* {@link http://snook.ca/archives/html_and_css/hiding-content-for-accessibility}
* {@link https://github.com/h5bp/main.css/issues/12#issuecomment-321106995}
*/
.visually-hidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
@kieranbarker
kieranbarker / escapeQuotes.js
Created July 19, 2020 07:16
Escape double and single quotes inside a string
/**
* Escape double and single quotes inside a string
* @param {String} string The string
* @returns {String} The string with quotes escaped
*/
function escapeQuotes (string) {
return string.replace(/"/g, """).replace(/'/g, "'");
}
@kieranbarker
kieranbarker / getJSON.js
Last active March 21, 2022 09:42
Get the JSON data from a Response object.
/**
* Get the JSON data from a Response object.
* @param {Response} response The Response object.
* @returns {Promise} The JSON data or an Error.
*/
async function getJSON(response) {
if (response.ok) {
const data = await response.json();
return Promise.resolve(data);
}