Skip to content

Instantly share code, notes, and snippets.

@Noviel
Noviel / formatUrl.js
Created March 18, 2021 10:33
Break URL in appropriate places
/**
* Insert line break opportunities into a URL
*/
function formatUrl(url) {
// Split the URL into an array to distinguish double slashes from single slashes
var doubleSlash = url.split('//')
// Format the strings on either side of double slashes separately
var formatted = doubleSlash.map(str =>
// Insert a word break opportunity after a colon
@Noviel
Noviel / create-resource.js
Created March 13, 2021 17:16
react suspence create resource
function createResource(promise) {
let status = 'pending'
let result = promise.then(
resolved => {
status = 'success'
result = resolved
},
rejected => {
status = 'error'
result = rejected
@Noviel
Noviel / deferred.js
Last active March 12, 2021 13:05
deferred
/*
Returns controlled promise that we can resolve or reject when needed.
*/
function deferred() {
let resolve, reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
@Noviel
Noviel / fast-shadow-animation.css
Last active September 27, 2019 08:58
Fast css shadow animation
/* https://tobiasahlin.com/blog/how-to-animate-box-shadow/ */
.box {
position: relative;
display: inline-block;
width: 100px;
height: 100px;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 1px 2px rgba(0,0,0,0.15);