This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class LabeledEnumType<T = number> { | |
private value: T; | |
private label: string; | |
private props: Map<string, unknown> = new Map<string, unknown>(); | |
constructor(value: T, label: string, props: Record<string, unknown> = {}) { | |
this.value = value; | |
this.label = label; | |
for (const key of Object.keys(props)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Zero = { | |
isZero: true; | |
}; | |
type Int = Zero | { prev: Int; isZero: false }; | |
type IncrOne<T extends Int> = { | |
prev: T; | |
isZero: false; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Vuex from 'vuex' | |
type GettersOption<S> = { [key: string]: (state: S) => unknown } | |
type Store<S, M, A, G extends GettersOption<S>> = { | |
state: S | |
mutations: M | |
actions: A | |
getters: { [key in keyof G]: ReturnType<G[key]> } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Vuex from 'vuex' | |
type GettersOption<S> = { [key: string]: (state: S) => unknown } | |
type Store<S, M, A, G extends GettersOption<S>> = { | |
state: S | |
mutations: M | |
actions: A | |
getters: { [key in keyof G]: ReturnType<G[key]> } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Options { | |
type: "boolean" | "number" | "string" | "array"; | |
} | |
type InferredOptionType<O extends Options> = | |
O extends { type: "array" } ? Array<string | number> : | |
O extends { type: "boolean" } ? boolean : | |
O extends { type: "number" } ? number : | |
O extends { type: "string" } ? string : | |
unknown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A simple co | |
* @param {Function} fn Generator Function | |
* @return {Function} callback | |
*/ | |
function co(fn) { | |
return function(done) { | |
done = done || function() {}; | |
var gen = fn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var web = require('webjs'); | |
var redis = require('redis'); | |
var client = redis.createClient(); | |
// webjs style | |
web.run(process.argv[2] || 8080) | |
.config({ | |
'views': __dirname + '/views', | |
'view engine': 'ejs', // jade, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var colls = {}; | |
jsd = exports; | |
function Collection (json) { | |
this.data = json; | |
this.toJSON = function () { | |
return this.data; | |
}; | |
this.findOne = function (opt) { |