UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 1.28 kB
{"version":3,"file":"boolean.cjs","names":["Result","Identifiers"],"sources":["../../../../src/lib/resolvers/boolean.ts"],"sourcesContent":["import { Result } from '@sapphire/result';\nimport { Identifiers } from '../errors/Identifiers';\n\nconst baseTruths = ['1', 'true', '+', 't', 'yes', 'y'] as const;\nconst baseFalses = ['0', 'false', '-', 'f', 'no', 'n'] as const;\n\nexport function resolveBoolean(\n\tparameter: string,\n\tcustoms?: { truths?: readonly string[]; falses?: readonly string[] }\n): Result<boolean, Identifiers.ArgumentBooleanError> {\n\tconst boolean = parameter.toLowerCase();\n\n\tif ([...baseTruths, ...(customs?.truths ?? [])].includes(boolean)) {\n\t\treturn Result.ok(true);\n\t}\n\n\tif ([...baseFalses, ...(customs?.falses ?? [])].includes(boolean)) {\n\t\treturn Result.ok(false);\n\t}\n\n\treturn Result.err(Identifiers.ArgumentBooleanError);\n}\n"],"mappings":";;;;;AAGA,MAAM,aAAa;CAAC;CAAK;CAAQ;CAAK;CAAK;CAAO;CAAI;AACtD,MAAM,aAAa;CAAC;CAAK;CAAS;CAAK;CAAK;CAAM;CAAI;AAEtD,SAAgB,eACf,WACA,SACoD;CACpD,MAAM,UAAU,UAAU,aAAa;AAEvC,KAAI,CAAC,GAAG,YAAY,GAAI,SAAS,UAAU,EAAE,CAAE,CAAC,SAAS,QAAQ,CAChE,QAAOA,yBAAO,GAAG,KAAK;AAGvB,KAAI,CAAC,GAAG,YAAY,GAAI,SAAS,UAAU,EAAE,CAAE,CAAC,SAAS,QAAQ,CAChE,QAAOA,yBAAO,GAAG,MAAM;AAGxB,QAAOA,yBAAO,IAAIC,2CAAY,qBAAqB"}