Skip to content

Instantly share code, notes, and snippets.

@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 / 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());
}
<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 {
<link rel="import" href="template-component.html">
<script>
class SsrData extends TemplateComponent {
constructor () {
super(SsrData.is);
}
static get is () {
return 'ssr-data';
}
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);
class TemplateComponent extends HTMLElement {
/*...*/
get path () {
const query = `link[rel="import"][href*="${this._tagName}"]`;
const target = document.head.querySelector(query);
return target.href.split(document.location.host)[1];
}
/*...*/
}
class TemplateComponent extends HTMLElement {
constructor (tagName) {
super();
if (!tagName) {
throw new Error('You did now specify a tag name. You need to call super with the tag name in you constructor.');
}
this._tagName = tagName;
}
class TemplateComponent extends HTMLElement {
constructor (tagName) {
super();
if (!tagName) {
throw new Error('You did now specify a tag name. You need to call super with the tag name in you constructor.');
}
this._tagName = tagName;
}
class TemplateComponent extends HTMLElement {
constructor (tagName) {
super();
if (!tagName) {
throw new Error('You did now specify a tag name. You need to call super with the tag name in you constructor.');
}
this._tagName = tagName;
}
<link rel="import" href="template-component.html">
<script>
class HelloWorld extends TemplateComponent {
constructor() {
super(HelloWorld.is);
}
static get is() {
return 'hello-world';
}