I hereby claim:
- I am qwtel on github.
- I am qwtel (https://keybase.io/qwtel) on keybase.
- I have a public key ASCbFur24236CAj1oGXKHjjTVGaT35JcTLQNXvXUFG7aOwo
To claim this, I am signing this object:
var createElement = document.createElement.bind(document); | |
function appendChild(child) { | |
this.appendChild( | |
child instanceof Element ? child : document.createTextNode(child) | |
); | |
} | |
document.createElement = function(tagName, attrs, children) { | |
var el = createElement(tagName); |
/* | |
* Copyright (c) 2018 Florian Klampfer <https://qwtel.com/> | |
* | |
* This software uses portions of `sigV4Client.js`, | |
* which is Apache-2.0 licensed with the following copyright: | |
* | |
* > Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | |
* | |
* Changes: | |
* * Replaced "crypto-js" with Web Cryptography API |
function fetchRx(url, options) { | |
const controller = new AbortController(); | |
const { signal } = controller; | |
return Observable.create(observer => { | |
fetch(url, { signal, ...options }) | |
.then(x => observer.next(x)) | |
.catch(x => observer.error(x)) | |
.finally(() => observer.complete()) | |
return () => controller.abort(); | |
}); |
I hereby claim:
To claim this, I am signing this object:
import md5 from "js-md5"; | |
import { base64ToUint8Array, splitUint8Array, concatUint8Arrays } from "./utils"; | |
const HEAD_SIZE_DWORD = 2; | |
const SALT_SIZE_DWORD = 2; | |
export async function decryptCryptoJSCipherBase64( | |
cryptoJSCipherBase64, | |
password, |
const NEVER = new Promise(() => {}); | |
async function raceTruthy(iterable) { | |
const ps = [...iterable].map(_ => Promise.resolve(_)); | |
let { length } = ps; | |
const continueWhenNullish = value => value != null | |
? value | |
: --length > 0 | |
? NEVER | |
: undefined; |
Main difference to regular Response
and Request
types is that no manual JSON.stringify
and headers.set('Content-Type', ...)
is required.
In my opinion, JSONRequest
is the most lightweight way of fixing the biggest issue of the Fetch API when dealing with JSON APIs, without resorting to full alternatives such as superagent or axios.
Example:
const response = await fetch(new JSONRequest('/comments', {
method: 'POST',
body: { text: 'Usage example: ...' },
export const urlWithParams = (url, params) => { | |
const u = new URL(url, global.location.origin) | |
if (params) { | |
u.search = new URLSearchParams([...u.searchParams, ...Object.entries(params)]) | |
} | |
return u.href | |
} |
export class ParamsURL extends URL { | |
constructor(href, params, origin = globalThis.location) { | |
super(href, origin); | |
if (params) { | |
this.search = new URLSearchParams([...this.searchParams, ...Object.entries(params)]); | |
} | |
} | |
} |
const nearestAsteroidsByAngle = pipe( | |
asteroids.filter(mkNe(laserPos)), | |
groupBy(mkCalcAngle(laserPos)), | |
mapValues(ps => ps.sort((p1, p2) => distToLaser(p1) - distToLaser(p2))), | |
intoMap(), | |
); | |
pipe( | |
cycle([...nearestAsteroidsByAngle.keys()].sort((a, b) => a - b)), | |
skipWhile(a => a < -Math.PI/2), |