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
| /* Typescript conversion of Ben Nadel's Collection class. | |
| Based on the fact that subclassing Array directly does not work very well, | |
| at least in Ecmascript versions < 6. Instead, this is based on creating a | |
| collection from an array, where the actual methods are added to the array | |
| after creation. | |
| It works exactly like an array, while at the same time having additional | |
| functionality. | |
| */ |
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 class ThrottledQueue { | |
| private isThrottling = false; | |
| private items: (() => void)[] = []; | |
| constructor(private duration: number) { | |
| } | |
| run(item: () => void) { | |
| this.items.push(item); | |
| this.attemptExecute(); |
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
| /// <summary> | |
| /// Very simple extension method for adding an item to a dictionary | |
| /// and not evaluating the function unless the key doesn't exist. | |
| /// | |
| /// Example with Entity Framework: | |
| /// dataValueCache.AddIfNotExists(dataID, () => db.DataItems.First(d => d.DataID == dataID).Value); | |
| /// </summary> | |
| /// <param name="key">The dictionary key.</param> | |
| /// <param name="value">The dictionary value.</param> | |
| /// <returns>If the item was added to the dictionary.</returns> |
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
| /*! | |
| * Copyright 2014 - David Sherret | |
| * MIT License | |
| */ | |
| // Limits an input to specific values without checking keycodes and without flickering the value. | |
| // | |
| // Example usage: | |
| // $("input").limitRegex(/^[0-9]+\.?[0-9]{0,2}$/); -- limit to numbers, up to 2 decimal places | |
| // |
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 ts from "typescript"; | |
| import * as Lint from "tslint/lib/lint"; | |
| export class Rule extends Lint.Rules.AbstractRule { | |
| static FAILURE_STRING = "duplicate imports from same file forbidden"; | |
| apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | |
| return this.applyWithWalker(new NoImportsWalker(sourceFile, this.getOptions())); | |
| } | |
| } |
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
| // only works with number enums... | |
| class EnumEx { | |
| private constructor() { | |
| } | |
| static getMembersCount(e: any) { | |
| return EnumEx.getNames(e).length; | |
| } | |
| static getMemberValue(e: any, memberName: string) { |
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
| /** | |
| * Ensure Public API Has Tests | |
| * --------------------------- | |
| * This demonstrates analyzing code to find methods and properties from the public | |
| * api that don't appear in the tests. | |
| * | |
| * This is a very basic implementation... a better implementation would examine more | |
| * aspects of the code (ex. are the return values properly checked?) and report | |
| * statistics about the tests that possibly indicate how they could be improved (ex. | |
| * "this test has a lot of overlap with these other tests"). The goal would be to |
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 class WeakCache<T extends object, U> { | |
| private readonly cacheItems: WeakDictionary<T, U>; | |
| constructor() { | |
| if (typeof WeakMap !== "undefined") | |
| this.cacheItems = new WeakMap<T, U>(); | |
| else | |
| this.cacheItems = new Es5WeakMap(); | |
| } |
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
| // untested... | |
| import { Project, SyntaxKind } from "ts-simple-ast"; | |
| const project = new Project({ tsConfigFilePath: "tsconfig.json" }); | |
| const srcDir = project.getDirectoryOrThrow("./src"); | |
| for (const sourceFile of project.getSourceFiles().filter(s => srcDir.isAncestorOf(s))) { | |
| for (const dec of [...sourceFile.getImportDeclarations(), ...sourceFile.getExportDeclarations()]) { | |
| const moduleSpecifierSourceFile = dec.getModuleSpecifierSourceFile(); | |
| if (moduleSpecifierSourceFile == null || !srcDir.isAncestorOf(moduleSpecifierSourceFile)) |
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
| // This script will look at all the exported class declarations from the main entrypoint of a library | |
| // and ensure all private, protected, and @internal members are prefixed with an underscore. | |
| import { Project, Node, SyntaxKind, TypeGuards, Scope, ClassMemberTypes, ParameterDeclaration } from "ts-simple-ast"; | |
| const project = new Project({ tsConfigFilePath: "tsconfig.json" }); | |
| const sourceFiles = project.getSourceFiles(); | |
| for (const file of sourceFiles) | |
| for (const classDec of file.getDescendantsOfKind(SyntaxKind.ClassDeclaration)) | |
| for (const member of classDec.getMembers()) |
OlderNewer