UNPKG

dailyprogrammer

Version:

The /r/dailyprogrammer Tool provides you with a cli to quickly initialize programming challenges and publish them.

23 lines (22 loc) 845 B
import {Difficulty} from "../challenges/Difficulty"; export class OptParserUtil { /** * Parses diffuculty option and returns a Difficulty. Can take numbers and string (e.g. 1, easy, 2, intermediate etc.) * @param difficulty * @returns {Difficulty} */ public static parseDifficulty( difficulty: string ): Difficulty { let result: Difficulty; if (typeof difficulty === "boolean") { difficulty = null; } else if (typeof difficulty === "string") { if (/^[0-9]+$/.test(difficulty)) { // numeric difficulty result = parseInt(Difficulty[Difficulty[difficulty]]); } else { result = Difficulty[difficulty[0].toUpperCase() + difficulty.slice(1)]; } } return !result ? null : result; } }