Skip to content

Instantly share code, notes, and snippets.

View enjikaka's full-sized avatar

Jeremy Karlsson enjikaka

View GitHub Profile
class TemplateComponent extends HTMLElement {
/*...*/
async getTemplate (data) {
const templator = (t, d) => new Function('return `' + t + '`').call(d);
async function loadTemplate () {
return new Promise(resolve => {
document.currentScript.ownerDocument.addEventListener('DOMContentLoaded', event => {
resolve(event.target.querySelector('template'));
}, false);
<link rel="import" href="template-component.html">
<script>
class SsrData extends TemplateComponent {
constructor () {
super(SsrData.is);
}
static get is () {
return 'ssr-data';
}
<script>
/**
* Component that automagically finds sibling <template>
* to the instance script and uses it for rendering, with
* out without the getState form the instace of the child.
*
* @class TemplateComponent
* @extends {HTMLElement}
*/
class TemplateComponent extends HTMLElement {
@enjikaka
enjikaka / app.mjs
Last active September 23, 2017 20:14
'use latest';
import express from 'express';
import compression from 'compression';
const app = express();
if (process.env.NODE_ENV === 'production') {
app.use(compression());
}
@enjikaka
enjikaka / durationToMinutes.js
Last active January 14, 2018 13:28
HTML 5.1 Duration string / dateTime to minutes
export default function durationToMinutes (durationString) {
return durationString
.match(/\d+\w/g)
.map(u => ([parseInt(u.match(/\d+/g), 10), u.split(/\d+/g)[1]]))
.map(a => {
switch (a[1]) {
case 'D': return a[0] * 1440;
case 'H': return a[0] * 60;
case 'M': return a[0];
case 'S': return a[0] / 60;
@enjikaka
enjikaka / test.md
Last active February 28, 2018 09:42
Timing differences between Webpack 3.9.0 and Webpack 4.0.0

Timing differences between Webpack 3.9.0 and Webpack 4.0.0

TL;DR

Webpack 3.9.0: 5.3287 minutes

Webpack 4.0.0: 3.86826667 minutes

Webpack 3.9.0

'use latest';
import express from 'express';
import request from 'request';
import { fromExpress } from 'webtask-tools';
import bodyParser from 'body-parser';
const app = express();
app.use(bodyParser.json());
@enjikaka
enjikaka / web.js
Created September 11, 2019 20:21
Nightcore-App Web.js
class TemplateStore {
constructor (node) {
if (!(node instanceof HTMLElement)) {
throw new Error('DOM Node for template storage is not set up. Please pass in an HTMLElement to the constructor.');
}
this.parentDOMNode = node;
}
/**
@enjikaka
enjikaka / README.md
Last active September 12, 2019 08:54

npm install --save-dev gist:8ce270954c48a4092b5dc62a0866792e

@enjikaka
enjikaka / web.js
Created October 8, 2019 13:28
web.js from declinded PR
/**
* Converts a snake-case string to camelCase
*
* @param {string} str kebab-cased string
* @returns {string} camelCased string
*/
export function kebabToCamelCase(str) {
return str.replace(/(-)([a-z])/g, g => g[1].toUpperCase());
}