GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — TypeScriptToLua/src/utils.ts at master · TypeScriptToLua/TypeScriptToLua Expand file tree/ Copy pathutils.tsMore file actions 87 lines (71 loc) · 2.96 KB / Copy pathutils.tsFile metadata and controls87 lines (71 loc) · 2.96 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 import * as ts from "typescript"; import * as nativeAssert from "assert"; import * as path from "path"; export function castArray<T>(value: T | T[]): T[]; export function castArray<T>(value: T | readonly T[]): readonly T[]; export function castArray<T>(value: T | readonly T[]): readonly T[] { return Array.isArray(value) ? value : [value as T]; } export const intersperse = <T>(values: readonly T[], separator: T): T[] => values.flatMap((value, index) => (index === 0 ? [value] : [separator, value])); export const union = <T>(...values: Array<Iterable<T>>): T[] => [...new Set(...values)]; export const intersection = <T>(first: readonly T[], ...rest: Array<readonly T[]>): T[] => union(first).filter(x => rest.every(r => r.includes(x))); type DiagnosticFactory = (...args: any) => Partial<ts.Diagnostic> & Pick<ts.Diagnostic, "messageText">; export const createDiagnosticFactoryWithCode = <T extends DiagnosticFactory>(code: number, create: T) => Object.assign( (...args: Parameters<T>): ts.Diagnostic => ({ file: undefined, start: undefined, length: undefined, category: ts.DiagnosticCategory.Error, code, source: "typescript-to-lua", ...create(...(args as any)), }), { code } ); let serialDiagnosticCodeCounter = 100000; export const createSerialDiagnosticFactory = <T extends DiagnosticFactory>(create: T) => createDiagnosticFactoryWithCode(serialDiagnosticCodeCounter++, create); export const normalizeSlashes = (filePath: string) => filePath.replace(/\\/g, "/"); export const trimExtension = (filePath: string) => filePath.slice(0, -path.extname(filePath).length); export function formatPathToLuaPath(filePath: string): string { filePath = filePath.replace(/\.json$/, ""); if (process.platform === "win32") { // Windows can use backslashes filePath = filePath.replace(/\.\\/g, "").replace(/\\/g, "."); } return filePath.replace(/\.\//g, "").replace(/\//g, "."); } type NoInfer<T> = [T][T extends any ? 0 : never]; export function getOrUpdate<K, V>( map: Map<K, V> | (K extends object ? WeakMap<K, V> : never), key: K, getDefaultValue: () => NoInfer<V> ): V { if (!map.has(key)) { map.set(key, getDefaultValue()); } return map.get(key)!; } export function isNonNull<T>(value: T | null | undefined): value is T { return value != null; } export function cast<TOriginal, TCast extends TOriginal>( item: TOriginal, cast: (item: TOriginal) => item is TCast ): TCast { if (cast(item)) { return item; } else { throw new Error(`Failed to cast value to expected type using ${cast.name}.`); } } export function assert(value: any, message?: string | Error): asserts value { nativeAssert.ok(value, message); } export function assertNever(_value: never): never { throw new Error("Value is expected to be never"); } export function assume<T>(_value: any): asserts _value is T {} |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |