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
#!/usr/bin/env node | |
// Restore working dir and remove additional argument | |
const originalCwd = process.argv.length >= 3 ? process.argv[2] : ''; | |
if(originalCwd.startsWith('$$')) { | |
process.argv.splice(2, 1); | |
process.chdir(originalCwd.substring(2)); | |
} | |
require('../lib/cli.js')(process) |
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
const detect = require('detect-es-version'); | |
const path = require('path'); | |
async function main() { | |
const file = path.resolve('./file-to-be-detect.js'); | |
const ecmaVersion = await detect.getEntryPointEcmaVersion(file); | |
console.log(file, ecmaVersion); // prints 2015 | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"> | |
<link href="./styles.css" rel="stylesheet"> | |
<title>Hello World!</title> | |
</head> | |
<body> |
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 JSONPrimitive<T> = number | boolean | string | null | T; | |
type JSONValue<T> = JSONPrimitive<T> | JSONArray<T> | JSONObject<T>; | |
type JSONObject<T> = { [k: string]: JSONValue<T>; }; | |
interface JSONArray<T> extends Array<JSONValue<T>> { | |
} |
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 PropType<T, Path extends string> = | |
string extends Path ? never : | |
Path extends keyof T ? T[Path] : | |
Path extends `${infer K}.${infer R}` ? K extends keyof T ? PropType<T[K], R> : never : never; | |
declare function getPropValue<T, P extends string>(obj: T, path: P): PropType<T, P>; | |
const obj = { | |
a: | |
{ |
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
/// <reference types="node" /> | |
declare module 'server-timings' { | |
import { RequestHandler, Request, Response, NextFunction } from 'express'; | |
function ServerTimings(req: Request, res: Response, next: NextFunction): any; | |
module ServerTimings { | |
/** | |
* Record the start time |
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 MessageMap { | |
method1: { prop1: string }; | |
method2: { prop2: string }; | |
method3: { prop3: string }; | |
} | |
export type RequestMessage<T> = { | |
[P in keyof T]: { action: P, data: T[P] } | |
}[keyof T]; |
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 JSONified<T> = | |
JSONifiedValue<T extends { toJSON(): infer U } ? U : T>; | |
type JSONifiedValue<T> = | |
T extends string | number | boolean | null ? T : | |
T extends Function ? undefined : | |
T extends Array<infer U> ? JSONifiedArray<U> : | |
T extends object ? JSONifiedObject<T> : | |
undefined; |
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 type TypeFromConstructor<T> = | |
T extends StringConstructor ? string : | |
T extends NumberConstructor ? number : | |
any; | |
export type MethodDefinition = { | |
[x: string]: StringConstructor | NumberConstructor; | |
}; | |
export type ServiceDefinition = { | |
[x: string]: MethodDefinition | |
}; |
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
/* | |
It's impossible to call constructor of mixin class. All default properties in TypeScript don't work. | |
*/ | |
function applyMixins<T>(derivedCtor: any, ...baseCtors: any[]) { | |
baseCtors.forEach(baseCtor => { | |
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => { | |
derivedCtor.prototype[name] = baseCtor.prototype[name]; | |
}); | |
}); |
NewerOlder