Best JavaScript code snippet using fast-check-monorepo
ApplicationCommandOption.ts
Source:ApplicationCommandOption.ts
1import type { ChannelTypes, Localization, Locales } from '@biscuitland/api-types';2import { ApplicationCommandOptionTypes } from '@biscuitland/api-types';3import type { ApplicationCommandOptionChoice } from '@biscuitland/core';4export type Localizations = typeof Locales[keyof typeof Locales] & string;5export class ChoiceBuilder {6 name?: string;7 value?: string;8 setName(name: string): ChoiceBuilder {9 this.name = name;10 return this;11 }12 setValue(value: string): this {13 this.value = value;14 return this;15 }16 toJSON(): ApplicationCommandOptionChoice {17 if (!this.name) { throw new TypeError('Property \'name\' is required'); }18 if (!this.value) { throw new TypeError('Property \'value\' is required'); }19 return {20 name: this.name,21 value: this.value,22 };23 }24}25export class OptionBuilder {26 required?: boolean;27 autocomplete?: boolean;28 type?: ApplicationCommandOptionTypes;29 name?: string;30 nameLocalization?: Record<Localizations, string>;31 description?: string;32 descriptionLocalization?: Record<Localizations, string>;33 constructor(type?: ApplicationCommandOptionTypes, name?: string, description?: string) {34 this.type = type;35 this.name = name;36 this.description = description;37 }38 setType(type: ApplicationCommandOptionTypes): this {39 return (this.type = type), this;40 }41 setName(name: string, localization?: Record<Localizations, string>): this {42 this.name = name;43 this.nameLocalization = localization;44 return this;45 }46 setDescription(description: string, localization?: Record<Localizations, string>): this {47 this.description = description;48 this.descriptionLocalization = localization;49 return this;50 }51 setRequired(required: boolean): this {52 return (this.required = required), this;53 }54 toJSON(): ApplicationCommandOption {55 if (!this.type) { throw new TypeError('Property \'type\' is required'); }56 if (!this.name) { throw new TypeError('Property \'name\' is required'); }57 if (!this.description) {58 throw new TypeError('Property \'description\' is required');59 }60 const applicationCommandOption: ApplicationCommandOption = {61 type: this.type,62 name: this.name,63 name_localizations: this.nameLocalization,64 description: this.description,65 description_localizations: this.descriptionLocalization,66 required: this.required ? true : false,67 };68 return applicationCommandOption;69 }70}71export class OptionBuilderLimitedValues extends OptionBuilder {72 choices?: ChoiceBuilder[];73 minValue?: number;74 maxValue?: number;75 constructor(76 type?: ApplicationCommandOptionTypes.Integer | ApplicationCommandOptionTypes.Number,77 name?: string,78 description?: string,79 ) {80 super();81 this.type = type;82 this.name = name;83 this.description = description;84 }85 setMinValue(n: number): this {86 return (this.minValue = n), this;87 }88 setMaxValue(n: number): this {89 return (this.maxValue = n), this;90 }91 addChoice(fn: (choice: ChoiceBuilder) => ChoiceBuilder): this {92 const choice = fn(new ChoiceBuilder());93 this.choices ??= [];94 this.choices.push(choice);95 return this;96 }97 override toJSON(): ApplicationCommandOption {98 return {99 ...super.toJSON(),100 choices: this.choices?.map(c => c.toJSON()) ?? [],101 min_value: this.minValue,102 max_value: this.maxValue,103 };104 }105}106export class OptionBuilderString extends OptionBuilder {107 choices?: ChoiceBuilder[];108 constructor(109 type?: ApplicationCommandOptionTypes.String,110 name?: string,111 description?: string,112 ) {113 super();114 this.type = type;115 this.name = name;116 this.description = description;117 this;118 }119 addChoice(fn: (choice: ChoiceBuilder) => ChoiceBuilder): this {120 const choice = fn(new ChoiceBuilder());121 this.choices ??= [];122 this.choices.push(choice);123 return this;124 }125 override toJSON(): ApplicationCommandOption {126 return {127 ...super.toJSON(),128 choices: this.choices?.map(c => c.toJSON()) ?? [],129 };130 }131}132export class OptionBuilderChannel extends OptionBuilder {133 channelTypes?: ChannelTypes[];134 constructor(135 type?: ApplicationCommandOptionTypes.Channel,136 name?: string,137 description?: string,138 ) {139 super();140 this.type = type;141 this.name = name;142 this.description = description;143 this;144 }145 addChannelTypes(...channels: ChannelTypes[]): this {146 this.channelTypes ??= [];147 this.channelTypes.push(...channels);148 return this;149 }150 override toJSON(): ApplicationCommandOption {151 return {152 ...super.toJSON(),153 channel_types: this.channelTypes ?? [],154 };155 }156}157export interface OptionBuilderLike {158 toJSON(): ApplicationCommandOption;159}160export class OptionBased {161 options?:162 & (163 | OptionBuilder[]164 | OptionBuilderString[]165 | OptionBuilderLimitedValues[]166 | OptionBuilderNested[]167 | OptionBuilderChannel[]168 )169 & OptionBuilderLike[];170 addOption(fn: (option: OptionBuilder) => OptionBuilder, type?: ApplicationCommandOptionTypes): this {171 const option = fn(new OptionBuilder(type));172 this.options ??= [];173 this.options.push(option);174 return this;175 }176 addNestedOption(fn: (option: OptionBuilder) => OptionBuilder): this {177 const option = fn(new OptionBuilder(ApplicationCommandOptionTypes.SubCommand));178 this.options ??= [];179 this.options.push(option);180 return this;181 }182 addStringOption(fn: (option: OptionBuilderString) => OptionBuilderString): this {183 const option = fn(new OptionBuilderString(ApplicationCommandOptionTypes.String));184 this.options ??= [];185 this.options.push(option);186 return this;187 }188 addIntegerOption(fn: (option: OptionBuilderLimitedValues) => OptionBuilderLimitedValues): this {189 const option = fn(new OptionBuilderLimitedValues(ApplicationCommandOptionTypes.Integer));190 this.options ??= [];191 this.options.push(option);192 return this;193 }194 addNumberOption(fn: (option: OptionBuilderLimitedValues) => OptionBuilderLimitedValues): this {195 const option = fn(new OptionBuilderLimitedValues(ApplicationCommandOptionTypes.Number));196 this.options ??= [];197 this.options.push(option);198 return this;199 }200 addBooleanOption(fn: (option: OptionBuilder) => OptionBuilder): this {201 return this.addOption(fn, ApplicationCommandOptionTypes.Boolean);202 }203 addSubCommand(fn: (option: OptionBuilderNested) => OptionBuilderNested): this {204 const option = fn(new OptionBuilderNested(ApplicationCommandOptionTypes.SubCommand));205 this.options ??= [];206 this.options.push(option);207 return this;208 }209 addSubCommandGroup(fn: (option: OptionBuilderNested) => OptionBuilderNested): this {210 const option = fn(new OptionBuilderNested(ApplicationCommandOptionTypes.SubCommandGroup));211 this.options ??= [];212 this.options.push(option);213 return this;214 }215 addUserOption(fn: (option: OptionBuilder) => OptionBuilder): this {216 return this.addOption(fn, ApplicationCommandOptionTypes.User);217 }218 addChannelOption(fn: (option: OptionBuilderChannel) => OptionBuilderChannel): this {219 const option = fn(new OptionBuilderChannel(ApplicationCommandOptionTypes.Channel));220 this.options ??= [];221 this.options.push(option);222 return this;223 }224 addRoleOption(fn: (option: OptionBuilder) => OptionBuilder): this {225 return this.addOption(fn, ApplicationCommandOptionTypes.Role);226 }227 addMentionableOption(fn: (option: OptionBuilder) => OptionBuilder): this {228 return this.addOption(fn, ApplicationCommandOptionTypes.Mentionable);229 }230 // eslint-disable-next-line @typescript-eslint/ban-types231 static applyTo(klass: Function, ignore: (keyof OptionBased)[] = []): void {232 const methods: (keyof OptionBased)[] = [233 'addOption',234 'addNestedOption',235 'addStringOption',236 'addIntegerOption',237 'addNumberOption',238 'addBooleanOption',239 'addSubCommand',240 'addSubCommandGroup',241 'addUserOption',242 'addChannelOption',243 'addRoleOption',244 'addMentionableOption',245 ];246 for (const method of methods) {247 if (ignore.includes(method)) { continue; }248 klass.prototype[method] = OptionBased.prototype[method];249 }250 }251}252export class OptionBuilderNested extends OptionBuilder {253 constructor(254 type?: ApplicationCommandOptionTypes.SubCommand | ApplicationCommandOptionTypes.SubCommandGroup,255 name?: string,256 description?: string,257 ) {258 super();259 this.type = type;260 this.name = name;261 this.description = description;262 }263 override toJSON(): ApplicationCommandOption {264 if (!this.type) { throw new TypeError('Property \'type\' is required'); }265 if (!this.name) { throw new TypeError('Property \'name\' is required'); }266 if (!this.description) {267 throw new TypeError('Property \'description\' is required');268 }269 return {270 type: this.type,271 name: this.name,272 description: this.description,273 options: this.options?.map(o => o.toJSON()) ?? [],274 required: this.required ? true : false,275 };276 }277}278OptionBased.applyTo(OptionBuilderNested);279export interface OptionBuilderNested extends OptionBuilder, OptionBased {280 // pass281}282export interface ApplicationCommandOption {283 /** Value of Application Command Option Type */284 type: ApplicationCommandOptionTypes;285 /** 1-32 character name matching lowercase `^[\w-]{1,32}$` */286 name: string;287 /** Localization object for the `name` field. Values follow the same restrictions as `name` */288 name_localizations?: Localization;289 /** 1-100 character description */290 description: string;291 /** Localization object for the `description` field. Values follow the same restrictions as `description` */292 description_localizations?: Localization;293 /** If the parameter is required or optional--default `false` */294 required?: boolean;295 /** Choices for `string` and `int` types for the user to pick from */296 choices?: ApplicationCommandOptionChoice[];297 /** If the option is a subcommand or subcommand group type, this nested options will be the parameters */298 options?: ApplicationCommandOption[];299 /** if autocomplete interactions are enabled for this `String`, `Integer`, or `Number` type option */300 autocomplete?: boolean;301 /** If the option is a channel type, the channels shown will be restricted to these types */302 channel_types?: ChannelTypes[];303 /** Minimum number desired. */304 min_value?: number;305 /** Maximum number desired. */306 max_value?: number;...
gardeningManager.module.ts
Source:gardeningManager.module.ts
1import { CommandInteraction } from "discord.js";2import { singleton } from "tsyringe";3import { addCommandKeys, authorize } from "../permission_manager/index.js";4import { Client } from "../utils/models/client.js";5import { ModuleBase } from "../utils/models/index.js";6import { GardeningManagerService } from "../services/gardeningManager.service.js";7import { Reason } from "../models/gardening_manager/index.js";8@singleton()9export class GardeningManagerModule extends ModuleBase {10 @addCommandKeys()11 private static readonly command = {12 $index: "gardening",13 Reserve: "reserve",14 Cancel: "cancel",15 List: "list",16 };17 constructor(private gardeningManagerService: GardeningManagerService) {18 super();19 this.moduleName = "GardeningModule";20 this.commands = [ {21 command: builder => builder22 .setName(GardeningManagerModule.command.$index)23 .setDescription("gardening module.")24 .addSubcommand(25 subComBuilder => subComBuilder26 .setName(GardeningManagerModule.command.Reserve)27 .setDescription("Reserve a slot in a plot to be used by you.")28 .addIntegerOption(29 optionBuilder => optionBuilder30 .setName("plot")31 .setDescription("The plot number.")32 .setRequired(true),33 )34 .addIntegerOption(35 optionBuilder => optionBuilder36 .setName("slot")37 .setDescription("The slot number.")38 .setRequired(true),39 )40 .addStringOption(41 optionBuilder => optionBuilder42 .setName("plant")43 .setDescription("The name of the plant you wish to plant.")44 .setRequired(true),45 )46 .addIntegerOption(optionBuilder =>47 optionBuilder48 .setName("duration")49 .setDescription("For how long do you wish to reserve this spot. In hours.")50 .setRequired(true),51 )52 .addStringOption(optionBuilder =>53 optionBuilder54 .setName("reason")55 .setDescription("The reason you are reserving this spot.")56 .setRequired(true)57 .addChoices(Object.keys(Reason)58 .map(value =>59 [60 value.replace(61 /(\w)(\w*)/g,62 (_, g1, g2) => g1 + g2.toLowerCase(),63 ),64 value,65 ],66 ),67 ),68 ),69 )70 .addSubcommand(subComBuilder =>71 subComBuilder72 .setName(GardeningManagerModule.command.Cancel)73 .setDescription("Cancel any reservations you have made to a slot in a plot.")74 .addIntegerOption(optionBuilder =>75 optionBuilder76 .setName("plot")77 .setDescription("The plot number.")78 .setRequired(true),79 )80 .addIntegerOption(optionBuilder =>81 optionBuilder82 .setName("slot")83 .setDescription("The slot number.")84 .setRequired(true),85 )86 .addStringOption(optionBuilder =>87 optionBuilder88 .setName("plant")89 .setDescription("The name of the plant you wish to cancel for.")90 .setRequired(true),91 ),92 )93 .addSubcommand(subComBuilder =>94 subComBuilder95 .setName(GardeningManagerModule.command.List)96 .setDescription("Shows all plots and their states.")97 .addIntegerOption(optionBuilder =>98 optionBuilder99 .setName("plot")100 .setDescription("Index of the plot you wish to view."),101 )102 .addIntegerOption(optionBuilder =>103 optionBuilder104 .setName("slot")105 .setDescription("Index of the slot you wish to view."),106 )107 .addBooleanOption(optionBuilder =>108 optionBuilder109 .setName("detailed")110 .setDescription("Should show a detailed view. Default: false"),111 ),112 ),113 run: async interaction => this.subCommandResolver(interaction),114 } ];115 this.tasks = [116 { name: `${this.moduleName}#TickTask`, timeout: 60000, run: client => this.tick(client) },117 ];118 }119 @authorize(GardeningManagerModule.command.$index, GardeningManagerModule.command.Reserve)120 private register(interaction: CommandInteraction, player: string, plant: string, duration: number, reason: Reason, plotNum: number, slotNum: number): Promise<void> {121 return this.gardeningManagerService.register(interaction, player, plant, duration, reason, plotNum, slotNum);122 }123 @authorize(GardeningManagerModule.command.$index, GardeningManagerModule.command.Cancel)124 private cancel(interaction: CommandInteraction, player: string, plant: string, plotNum: number, slotNum: number): Promise<void> {125 return this.gardeningManagerService.cancel(interaction, player, plant, plotNum, slotNum);126 }127 @authorize(GardeningManagerModule.command.$index, GardeningManagerModule.command.List)128 private list(interaction: CommandInteraction, plotNum: number, slotNum: number) {129 return this.gardeningManagerService.list(interaction, plotNum, slotNum);130 }131 private tick(client: Client): Promise<void> {132 return this.gardeningManagerService.tick(client);133 }134 private subCommandResolver(interaction: CommandInteraction) {135 const subCommand: string = interaction.options.getSubcommand();136 if (!subCommand) throw new Error();137 const plotNum = interaction.options.getInteger("plot");138 const slotNum = interaction.options.getInteger("slot");139 const player = `${interaction.user.username}#${interaction.user.discriminator}`;140 const plant: string = interaction.options.getString("plant");141 const duration: number = (interaction.options.getInteger("duration") ?? 0) * 360;142 const reason: Reason = (interaction.options.getInteger("reason") ?? Reason.NONE) as Reason;143 switch (subCommand) {144 case "reserve":145 return this.register(interaction, player, plant, duration, reason, plotNum, slotNum);146 case "cancel":147 return this.cancel(interaction, player, plant, plotNum, slotNum);148 case "list":149 return this.list(interaction, plotNum, slotNum);150 default:151 return interaction.reply({ content: "Not a valid subcommand", ephemeral: true });152 }153 }...
Option.js
Source:Option.js
1/* Generated from Java with JSweet 2.3.0-SNAPSHOT - http://www.jsweet.org */2var quickstart;3(function (quickstart) {4 /**5 * Classe su cui si vuole costruire oggetto Option6 * @author Savino7 * @class8 */9 class Option {10 constructor() {11 }12 }13 quickstart.Option = Option;14 Option["__class"] = "quickstart.Option";15 (function (Option) {16 /**17 * Crea l'elemento option18 * @class19 * @extends quickstart.Builder20 * @author Savino21 */22 class OptionBuilder extends quickstart.Builder {23 constructor() {24 super();25 if (this.option === undefined)26 this.option = null;27 this.option = document.createElement("option");28 }29 /**30 * Asssegna un valore alla option31 * @param {string} value valore dell'option32 * @return {quickstart.Option.OptionBuilder} oggetto builder33 */34 setValue(value) {35 this.option.value = value;36 return this;37 }38 /**39 * Assegna un testo da visualizzare nell'option40 * @param {string} innerText testo dell'option41 * @return {quickstart.Option.OptionBuilder} oggetto builder42 */43 setInnerText(innerText) {44 this.option.innerText = innerText;45 return this;46 }47 /**48 * Imposta l'option come selezionata49 * @return {quickstart.Option.OptionBuilder} oggetto builder50 */51 selected() {52 this.option.selected = true;53 return this;54 }55 /**56 * Imposta l'option come disabilitata57 * @return {quickstart.Option.OptionBuilder} oggetto builder58 */59 disabled() {60 this.option.disabled = true;61 return this;62 }63 /**64 * Imposta l'option come option nascosta65 * @return {quickstart.Option.OptionBuilder} oggetto builder66 */67 hidden() {68 this.option.hidden = true;69 return this;70 }71 /**72 *73 * @param {string} className74 * @return {quickstart.Option.OptionBuilder}75 */76 setClassName(className) {77 this.option.className = className;78 return this;79 }80 /**81 *82 * @param {string} property83 * @param {string} value84 * @return {quickstart.Option.OptionBuilder}85 */86 css(property, value) {87 $(this.option).css(property, value);88 return this;89 }90 /**91 *92 * @return {HTMLOptionElement}93 */94 build() {95 return this.option;96 }97 }98 Option.OptionBuilder = OptionBuilder;99 OptionBuilder["__class"] = "quickstart.Option.OptionBuilder";100 })(Option = quickstart.Option || (quickstart.Option = {}));
...
Using AI Code Generation
1const { optionBuilder } = require('fast-check');2const { option } = require('fast-check');3const { Arbitrary } = require('fast-check');4const { integer } = require('fast-check');5const { string } = require('fast-check');6const { oneof } = require('fast-check');7const { array } = require('fast-check');8const { record } = require('fast-check');9const { object } = require('fast-check');10const { tuple } = require('fast-check');11const { constant } = require('fast-check');12const { mapToConstant } = require('fast-check');13const { map } = require('fast-check');14const { frequency } = require('fast-check');15const { constantFrom } = require('fast-check');16const { option } = require('fast-check');17const { constantFrom } = require('fast-check');18const { oneof } = require('fast-check');19const { array } = require('fast-check');
Using AI Code Generation
1const fc = require('fast-check');2const { optionBuilder } = require('fast-check-monorepo');3const optionArb = optionBuilder(fc.integer());4fc.assert(5 fc.property(optionArb, optionArb, (a, b) => a.isNone() || b.isNone() || a.equals(b))6);7const optionArb = optionBuilder(fc.integer());8const optionArb = optionBuilder(fc.string());9const optionArb = optionBuilder(fc.array(fc.integer()));10const optionArb = optionBuilder(fc.tuple(fc.integer(), fc.string()));11const optionArb = optionBuilder(fc.func(fc.integer(), fc.integer()));12const optionArb = optionBuilder(fc.object({a: fc.integer(), b: fc.string()}));13const optionArb = optionBuilder(fc.object({a: fc.integer(), b: fc.string(), c: fc.array(fc.integer())}));14const optionArb = optionBuilder(fc.object({a: fc.integer(), b: fc.string(), c: fc.tuple(fc.integer(), fc.string())}));15const optionArb = optionBuilder(fc.object({a: fc.integer(), b:
Using AI Code Generation
1const fastCheck = require('fast-check');2const { optionBuilder } = require('fast-check-monorepo');3const { option } = fastCheck;4const { oneof } = option;5const option1 = optionBuilder()6 .withMaxDepth(2)7 .withMaxShrinkDepth(1)8 .withMaxDepthPerRun(1)9 .withMaxShrinkDepthPerRun(1)10 .withMaxSkipsPerRun(1)11 .withMaxSkips(1)12 .withMaxTries(1)13 .withMaxTriesPerRun(1)14 .withNoShrink()15 .withNoShrinkOnFailure()16 .withVerbose()17 .withVerboseShrink()18 .withVerboseSkips()19 .withVerboseTries()20 .withVerboseWarnings()21 .withVerboseWarningsSkips()22 .withVerboseWarningsTries()23 .withSeed(123)24 .withPath('test.js')25 .withReporter('json')26 .build();27const option2 = optionBuilder()28 .withMaxDepth(2)29 .withMaxShrinkDepth(1)30 .withMaxDepthPerRun(1)31 .withMaxShrinkDepthPerRun(1)32 .withMaxSkipsPerRun(1)33 .withMaxSkips(1)34 .withMaxTries(1)35 .withMaxTriesPerRun(1)36 .withNoShrink()37 .withNoShrinkOnFailure()38 .withVerbose()39 .withVerboseShrink()40 .withVerboseSkips()41 .withVerboseTries()42 .withVerboseWarnings()43 .withVerboseWarningsSkips()44 .withVerboseWarningsTries()45 .withSeed(123)46 .withPath('test.js')47 .withReporter('json')48 .build();49const option3 = optionBuilder()50 .withMaxDepth(2)51 .withMaxShrinkDepth(1)52 .withMaxDepthPerRun(1)53 .withMaxShrinkDepthPerRun(1)54 .withMaxSkipsPerRun(1)55 .withMaxSkips(1)56 .withMaxTries(1)57 .withMaxTriesPerRun(1)58 .withNoShrink()59 .withNoShrinkOnFailure()
Using AI Code Generation
1const {optionBuilder} = require('fast-check-monorepo');2const {option} = optionBuilder();3const {some, none} = require('fp-ts/lib/Option');4const arb = option(arbNumber);5fc.assert(6 fc.property(arb, value => {7 if (value.isSome()) {8 return typeof value.value === 'number';9 } else {10 return value.value === undefined;11 }12 })13);14{15 "scripts": {16 },17 "dependencies": {18 }19}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!