This file contains hidden or 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 { SelectedValue, useNamespaces } from 'xpath'; | |
import { DOMParser } from 'xmldom'; | |
import * as _ from 'lodash'; | |
import { VError } from 'verror'; | |
interface Parser { | |
parseXml: (xml: string) => Document; | |
/** | |
* Type guard that returns true iff the selected value is a Node. |
This file contains hidden or 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 BanProps<T extends string> = { [P in T]: never } & { | |
[key: string]: any; | |
}; | |
interface Foo { | |
x: string; | |
y: number; | |
} | |
export type NotFoo = BanProps<keyof Foo>; |
This file contains hidden or 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 Omit<T1, T2> = { [K in Exclude<keyof T1, keyof T2>]: T1[K] }; | |
const curry = <TDeps, TPartialDeps extends Partial<TDeps>, TReturn>( | |
fn: (deps: TDeps) => TReturn, | |
supplied: TPartialDeps | |
): ((newDeps: Omit<TDeps, TPartialDeps>) => TReturn) => { | |
return (deps: Omit<TDeps, TPartialDeps>) => | |
fn({ | |
...supplied, | |
...deps |
This file contains hidden or 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 _ from 'lodash'; | |
/** | |
* Checks to see if a value is defined (not null/undefined) on a given object. | |
* Is a type-guard function, so the argument will be cast to a version of itself | |
* where that field is no longer nullable. | |
* @example | |
* type Foo = { x?: string } | |
* const foo: Foo = ... | |
* if (isDefined(foo, 'x')) { |
This file contains hidden or 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
{ | |
// See https://go.microsoft.com/fwlink/?LinkId=733558 | |
// for the documentation about the tasks.json format | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"label": "tsc-watch", | |
"group": "build", | |
"command": "./node_modules/.bin/tsc", | |
"type": "shell", |
This file contains hidden or 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 util from 'util'; | |
/** | |
* Behaves like Partial<T>, except nested properties also become optional. | |
* @example | |
* ```ts | |
* type Foo = DeepPartial<{x: { y: number, z: number }>; | |
* const foo: Foo = {x: { y: 42 } }; // Note that z is now not required | |
* ``` | |
*/ |
This file contains hidden or 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 { readFileSync } from 'fs'; | |
import { mergeSchemas, makeExecutableSchema } from 'graphql-tools'; | |
import { getRemoteSchemas } from './remoteSchemas'; | |
import { Resolvers } from './resolvers'; | |
export const createSchema = async () => { | |
const resolvers = [Resolvers]; | |
const localSchema = readFileSync(require.resolve('./schema.gql'), 'utf8'); |
This file contains hidden or 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
{ | |
// Use IntelliSense to learn about possible attributes. | |
// Hover to view descriptions of existing attributes. | |
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
"version": "0.2.0", | |
"configurations": [ | |
{ | |
"name": "Start", | |
"type": "node", | |
"request": "launch", |
This file contains hidden or 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
/** | |
* Dependency Example in TS. | |
* Instead of dependency injection, this method shows how services can "fetch" their dependencies, | |
* without being concerned about the lifecycles of their dependencies. | |
* These services are also isolated from their dependencies, lending themselves to easier testing. | |
* Does not use classes or decorators or any black magic to accomplish this. | |
* | |
* All services are essentially split into 3 pieces: | |
* 1. The interface that defines the service to other services. | |
* 2. The service constructing function that takes in all depedencies as arguments. |
This file contains hidden or 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
'use strict'; | |
const deepExclude = (node, exclude) => { | |
if (Array.isArray(node)) { | |
return node.map((n) => deepExclude(n, exclude)); | |
} else if (typeof node === 'object' && node) { | |
return Object.entries(node) | |
.filter(([key]) => exclude.indexOf(key) === -1) | |
.reduce((obj, [key, value]) => ({ ...obj, [key]: deepExclude(value, exclude) }), {}); | |
} |
NewerOlder