### Import TagScript (TypeScript) Source: https://tagscript.js.org/index Demonstrates how to import and use TagScript in a TypeScript project. Ensure TagScript is installed as a dependency. ```typescript import TagScript from "tagscript"; const tagscript = new TagScript(); const output = tagscript.parse("Hello, {user}!"); console.log(output); ``` -------------------------------- ### Import TagScript (CommonJS) Source: https://tagscript.js.org/index Shows how to import and utilize TagScript using the CommonJS module system, typically found in Node.js environments. This requires the 'tagscript' package to be installed. ```javascript const TagScript = require("tagscript"); const tagscript = new TagScript(); const output = tagscript.parse("Welcome, {name}. Your score is {score}."); console.log(output); ``` -------------------------------- ### Get OrdinalFormatParser Configuration as JSON Source: https://tagscript.js.org/api/tagscript/classes/OrdinalFormatParser Illustrates how to obtain the configuration of an OrdinalFormatParser instance in JSON format using the toJSON method. This includes acceptedNames, requiredParameter, and requiredPayload. ```typescript const jsonConfig = ordinalParser.toJSON(); // jsonConfig will be an object containing configuration details ``` -------------------------------- ### Lexer Class Constructor Source: https://tagscript.js.org/api/tagscript/classes/Lexer Initializes a new Lexer instance. The Lexer class represents a passed Tag. ```APIDOC ## new Lexer(input, limit, parenType) ### Description Initializes a new Lexer instance. The Lexer class represents a passed Tag. ### Method CONSTRUCTOR ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "input": "your input string", "limit": 2000, "parenType": "Both" } ``` ### Response #### Success Response (Instance) - **Lexer** (`Lexer`) - An instance of the Lexer class. #### Response Example ```json { "instance": "Lexer object" } ``` ``` -------------------------------- ### Node Class API Source: https://tagscript.js.org/api/tagscript/classes/Node Details about the Node class, including its constructor, properties, and methods. ```APIDOC ## Class: Node Defined in: Interpreter/Node.ts:6 A low-level object representing a bracketed tag. ### Constructors #### Constructor **new Node**(`coordinates`, `tag`): `Node` Defined in: Interpreter/Node.ts:13 ##### Parameters - **coordinates** (`number`, `number`) - Required - The coordinates of the node. - **tag** (`null` | `Lexer`) - Optional - The lexer associated with the tag. #### Returns - `Node` - A new Node object. ### Properties #### coordinates **coordinates** : [`number`, `number`] Defined in: Interpreter/Node.ts:7 #### output **output** : `null` | `string` Defined in: Interpreter/Node.ts:11 #### tag **tag** : `null` | `Lexer` Defined in: Interpreter/Node.ts:9 ### Methods #### toJSON() **toJSON**(): `object` Defined in: Interpreter/Node.ts:24 ##### Returns - `object` - An object representation of the Node. - **coordinates** (`number`, `number`) - The coordinates of the node. - **output** (`null` | `string`) - The output string of the node. - **tag** (`null` | `Lexer`) - The lexer associated with the tag. #### toString() **toString**(): `string` Defined in: Interpreter/Node.ts:19 ##### Returns - `string` - A string representation of the Node. ``` -------------------------------- ### Instantiate TagScript Context Source: https://tagscript.js.org/api/tagscript/classes/Context Demonstrates how to create a new Context object, which is used internally by the TagScript interpreter. It requires instances of Lexer, Response, Interpreter, and the original message string. ```typescript import { Context } from "Interpreter/Context"; import { Lexer } from "Parser/Lexer"; import { Response } from "Interpreter/Response"; import { Interpreter } from "Interpreter/Interpreter"; // Assuming you have instances of these classes: const lexerInstance: Lexer = new Lexer(""); const responseInstance: Response = new Response(); const interpreterInstance: Interpreter = new Interpreter(); const originalMessage: string = "@command arg1 arg2"; const context = new Context(lexerInstance, responseInstance, interpreterInstance, originalMessage); ``` -------------------------------- ### Instantiate Response Class in TypeScript Source: https://tagscript.js.org/api/tagscript/classes/Response Demonstrates how to create a new instance of the Response class. The constructor takes 'variables' and optional 'keyValues' as arguments. The 'variables' parameter is an object containing all variables accessible by parsers, and 'keyValues' is an optional object for key-value pairs, defaulting to an empty object. ```TypeScript import { Response } from "./Interpreter/Response"; // Example usage: const myVariables = { username: "JohnDoe", userId: 123 }; const myKeyValues = { source: "api" }; const response = new Response(myVariables, myKeyValues); ``` -------------------------------- ### StringFormatParser Constructor - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/StringFormatParser Initializes a new instance of the StringFormatParser class. This constructor is inherited from BaseParser. ```TypeScript new StringFormatParser(): StringFormatParser ``` -------------------------------- ### Lexer Class Methods Source: https://tagscript.js.org/api/tagscript/classes/Lexer Details the methods available on the Lexer class. ```APIDOC ## Lexer Methods ### Description Details the methods available on the Lexer class. ### Methods #### toJSON() - **Description**: Converts the Lexer instance to a JSON-serializable object. - **Returns**: `object` - **declaration** (`string` | `null`) - **parameter** (`string` | `null`) - **payload** (`string` | `null`) - **usedParenType** (`ParenType`) #### toString() - **Description**: Returns a string representation of the Lexer instance. - **Returns**: `string` ### Example Usage ```javascript const lexer = new Lexer("example"); const jsonRepresentation = lexer.toJSON(); console.log(jsonRepresentation); const stringRepresentation = lexer.toString(); console.log(stringRepresentation); ``` ``` -------------------------------- ### BaseParser Class Source: https://tagscript.js.org/api/tagscript/classes/BaseParser Documentation for the abstract BaseParser class, which serves as a base for all transformers in TagScript. ```APIDOC ## Class: `abstract` BaseParser ### Description A base class for all transformers. ### Extended by - `BreakParser` - `IfStatementParser` - `UnionStatementParser` - `IntersectionStatementParser` - `DefineParser` - `FiftyFiftyParser` - `StringFormatParser` - `OrdinalFormatParser` - `IncludesParser` - `JSONVarParser` - `RandomParser` - `RangeParser` - `ReplaceParser` - `SliceParser` - `StopParser` - `UrlEncodeParser` - `UrlDecodeParser` ### Constructors #### Constructor **new BaseParser**(`acceptedNames`, `requiredParameter`, `requiredPayload`): `BaseParser` ##### Parameters - **acceptedNames** (`string`[]) - Description not provided. - **requiredParameter** (`boolean`) - Optional, defaults to `false`. Description not provided. - **requiredPayload** (`boolean`) - Optional, defaults to `false`. Description not provided. ##### Returns `BaseParser` ### Properties - **acceptedNames** (`string`[]) - `protected`. Defined in Parsers/Base.ts:8. - **requiredParameter** (`boolean`) - `protected`. Defined in Parsers/Base.ts:10. - **requiredPayload** (`boolean`) - `protected`. Defined in Parsers/Base.ts:12. ### Methods #### toJSON() **toJSON**(): `object` ##### Returns `object` - **acceptedNames** (`string`[]) - Description not provided. - **requiredParameter** (`boolean`) - Description not provided. - **requiredPayload** (`boolean`) - Description not provided. #### willAccept() **willAccept**(`ctx`): `boolean` ##### Parameters - **ctx** (`Context`) - Description not provided. ##### Returns `boolean` ``` -------------------------------- ### FilesParser Constructor (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/FilesParser Initializes a new instance of the FilesParser class. This constructor is part of the TagScript Discord plugin and extends the BaseParser class. It does not take any parameters. ```typescript new FilesParser(): FilesParser ``` -------------------------------- ### DefineParser Constructor - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/DefineParser Initializes a new instance of the DefineParser class. This constructor is inherited from BaseParser and is used to set up the parser instance. ```typescript new DefineParser(): DefineParser ``` -------------------------------- ### IParser Interface willAccept() Method Signature Source: https://tagscript.js.org/api/tagscript/interfaces/IParser Details the signature of the 'willAccept' method in the IParser interface. This method accepts a context object and returns an awaitable boolean indicating if the parser can handle the tag. ```typescript willAccept : (ctx) => Awaitable ``` -------------------------------- ### Instantiate OrdinalFormatParser Class Source: https://tagscript.js.org/api/tagscript/classes/OrdinalFormatParser Demonstrates how to create a new instance of the OrdinalFormatParser class. This constructor does not take any arguments. ```typescript const ordinalParser = new OrdinalFormatParser(); ``` -------------------------------- ### Instantiate Lexer Class in TypeScript Source: https://tagscript.js.org/api/tagscript/classes/Lexer Creates a new instance of the Lexer class. It takes the input string, an optional limit for parsing, and an optional parenthesis type. The constructor initializes properties like declaration, parameter, and payload. ```typescript import { Lexer, ParenType } from "./Interpreter/Lexer"; const inputString = "[tag arg=value]payload[/tag]"; const lexer = new Lexer(inputString); const lexerWithLimit = new Lexer(inputString, 1000); const lexerWithCustomParen = new Lexer(inputString, 2000, ParenType.Round); ``` -------------------------------- ### RangeParser Class API Source: https://tagscript.js.org/api/tagscript/classes/RangeParser Details of the RangeParser class, including its purpose, constructors, properties, and methods. ```APIDOC ## Class: RangeParser ### Description The range tag picks a random number from a range of numbers separated by `-`. The number range is inclusive, so it can pick the starting/ending number as well. Using the rangef tag will pick a number to the tenth decimal place. ### Aliases - rangef ### Constructors #### Constructor **new RangeParser**(): `RangeParser` ##### Returns `RangeParser` ### Properties #### acceptedNames `protected` **acceptedNames** : `string`[] #### requiredParameter `protected` **requiredParameter** : `boolean` #### requiredPayload `protected` **requiredPayload** : `boolean` ### Methods #### parse() **parse**(`ctx`): `string` Parses the given tag. ##### Parameters - **ctx** (`Context`) - The context of the tag. ##### Returns `string` #### toJSON() **toJSON**(): `object` ##### Returns `object` ##### Fields - **acceptedNames** (`string`[]) - **requiredParameter** (`boolean`) - **requiredPayload** (`boolean`) #### willAccept() **willAccept**(`ctx`): `boolean` Whether the parser can handle the given tag. ##### Parameters - **ctx** (`Context`) - ##### Returns `boolean` ``` -------------------------------- ### BaseTransformer Class Documentation Source: https://tagscript.js.org/api/plugins/classes/BaseTransformer Documentation for the abstract BaseTransformer class, which serves as a base for transforming discord.js objects. ```APIDOC ## Class: `abstract` BaseTransformer ### Description Transformer for discord.js objects. ### Extended by * `GuildTransformer` * `MemberTransformer` * `ChannelTransformer` * `RoleTransformer` * `UserTransformer` * `InteractionTransformer` ### Type Parameters #### T `T` _extends_ `CommandInteraction` | `Guild` | `GuildChannel` | `GuildMember` | `Role` | `User` The base type. ### Implements * `ITransformer` ### Constructors #### Constructor **new BaseTransformer** <`T`>(`base`, `safeValues`): `BaseTransformer`<`T`> ##### Parameters - **base** (`T`) - The base object to transform. - **safeValues** (`SafeValues`<`T`>) - Optional initial safe values. Defaults to `{}`. ##### Returns `BaseTransformer`<`T`> ### Properties #### base `protected` **base** : `T` The base object provided during construction. #### safeValues `protected` **safeValues** : `SafeValues`<`T`> = `{}` An object containing safe values for transformations. ### Methods #### toJSON() **toJSON**(): `SafeValues`<`T`> ##### Returns `SafeValues`<`T`> - A copy of the current safe values. #### transform() **transform**(`tag`): `null` | `string` Transforms the given tag. ##### Parameters - **tag** (`Lexer`) - The tag that triggered the transformer. ##### Returns `null` | `string` - The transformed string or null if transformation fails. ##### Implementation of `ITransformer.transform` #### updateSafeValues() `protected` **updateSafeValues**(): `void` Updates the internal safe values. This method is intended for internal use. ##### Returns `void` ``` -------------------------------- ### DenyParser Constructor in TypeScript Source: https://tagscript.js.org/api/plugins/classes/DenyParser Initializes a new instance of the DenyParser class. This constructor is inherited from BaseParser and sets up the parser's basic properties. ```typescript new DenyParser(): DenyParser ``` -------------------------------- ### RangeParser Constructor Source: https://tagscript.js.org/api/tagscript/classes/RangeParser Initializes a new instance of the RangeParser class. This constructor is inherited from the BaseParser class and sets up the fundamental properties for parsing. ```typescript new RangeParser(): RangeParser ``` -------------------------------- ### JSONVarParser Constructor Source: https://tagscript.js.org/api/tagscript/classes/JSONVarParser Initializes a new instance of the JSONVarParser class. This constructor is inherited from the BaseParser class and does not take any arguments. ```typescript new JSONVarParser() ``` -------------------------------- ### ITransformer Interface Source: https://tagscript.js.org/api/tagscript/interfaces/ITransformer Documentation for the ITransformer interface, used for runtime value transformation based on tags. ```APIDOC ## Interface: ITransformer ### Description Transformers are used to transform a value based on the tag at runtime. ### Properties #### transform() - **transform** : (`tag`) => `null` | `string` Transforms the given tag. ### Parameters #### tag - **tag** (Lexer) - Required - The tag that triggered the transformer. ### Returns - **(null | string)** - The transformed value or null if no transformation occurs. ``` -------------------------------- ### Node Constructor - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/Node Initializes a new Node object with coordinates and a tag. The tag can be a Lexer instance or null. This constructor is fundamental for creating Node instances within the TagScript interpreter. ```typescript new Node(coordinates: [number, number], tag: null | Lexer): Node ``` -------------------------------- ### ReplaceParser Class Constructor (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/ReplaceParser Initializes a new instance of the ReplaceParser class. This constructor is inherited from the BaseParser class and sets up the parser's fundamental properties. ```typescript new ReplaceParser(): ReplaceParser ``` -------------------------------- ### Interpreter Class Constructor (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/Interpreter Initializes a new instance of the Interpreter class. It accepts an array of IParser objects to configure the parsing behavior. This constructor is fundamental for setting up the interpreter with specific parsing rules. ```typescript new Interpreter(...parsers: IParser[]): Interpreter ``` -------------------------------- ### Response Class Documentation Source: https://tagscript.js.org/api/tagscript/classes/Response Documentation for the Response class, which holds information about a completed TagScript process. ```APIDOC ## Class: Response ### Description An object containing information on a completed TagScript process. ### Constructor **new Response**(`variables`, `keyValues`): `Response` #### Parameters - **variables** (object) - - **keyValues** (IKeyValues, optional) - Defaults to `{}` ### Properties - **actions** (IActions) - An object containing information on a completed TagScript process. If you are creating a parser where you need to store info in actions, then you need to extend this interface. - **body** (null | string) - The cleaned message with all tags interpreted. - **keyValues** (IKeyValues) - - **raw** (string) - The raw string that was used to generate this response. - **variables** (object) - An object with all the variables that parsers such as the `LooseVarsParser` can access. - Index Signature: [`key`: string]: `ITransformer` ### Methods - **setValues**(`output`, `raw`): `Response` #### Parameters - **output** (string) - - **raw** (string) - - **toJSON**(): `object` - Returns an object containing all properties of the Response class: `actions`, `body`, `keyValues`, `raw`, `variables`. ``` -------------------------------- ### LooseVarsParser Constructor - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/LooseVarsParser Initializes a new instance of the LooseVarsParser class. This constructor does not take any parameters and returns an instance of LooseVarsParser. ```typescript new LooseVarsParser() ``` -------------------------------- ### RandomParser Constructor Source: https://tagscript.js.org/api/tagscript/classes/RandomParser The constructor for the RandomParser class. It initializes a new instance of RandomParser. This constructor overrides the one from the base class. ```typescript /** * Constructs a new instance of RandomParser. */ constructor() { super(); // Assuming BaseParser has a constructor to call } ``` -------------------------------- ### BaseTransformer Constructor Source: https://tagscript.js.org/api/plugins/classes/BaseTransformer Initializes a new BaseTransformer instance. It takes the base Discord object and an optional object of safe values as parameters. The base object is of a generic type T, which extends various discord.js entities. ```typescript new BaseTransformer(base: T, safeValues?: SafeValues = {}): BaseTransformer ``` -------------------------------- ### StrictVarsParser Constructor - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/StrictVarsParser Initializes a new instance of the StrictVarsParser. This constructor does not take any arguments and sets up the parser for strict variable handling. ```typescript new StrictVarsParser() ``` -------------------------------- ### IParser Interface parse() Method Signature Source: https://tagscript.js.org/api/tagscript/interfaces/IParser Describes the signature of the 'parse' method within the IParser interface. This method takes a context object and returns an awaitable value which can be null or a string. ```typescript parse : (ctx) => Awaitable ``` -------------------------------- ### split() Function Source: https://tagscript.js.org/api/tagscript/functions/split Documentation for the split() function in TagScript. ```APIDOC ## Function: split() ### Description Splits a string by `|`, but ignores escaped characters. If `extended` is true, it will also split by `~` and `,`. ### Method N/A (This is a function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters #### str - **str** (string) - Required - The string to split. #### extended - **extended** (boolean) - Optional (defaults to `false`) - If true, allows `~` or `,` as separators in addition to `|`. ### Request Example N/A (This is a function call, not an HTTP request) ### Response #### Success Response (200) N/A (This function returns a value, not an HTTP response) - **return value** (string[]) - An array of strings resulting from the split operation. #### Response Example ```javascript // Example usage: split("hello|world") // returns ["hello", "world"] split("a|b~c,d", true) // returns ["a", "b", "c", "d"] split("escaped\\|pipe") // returns ["escaped\\|pipe"] ``` ### Remarks If `extended` is true, the function will also split by `~` and `,`. ``` -------------------------------- ### BaseParser Constructor - TagScript Source: https://tagscript.js.org/api/tagscript/classes/BaseParser Defines the constructor for the abstract BaseParser class. It accepts an array of accepted names and optional boolean flags for required parameters and payloads. ```typescript constructor( acceptedNames: string[], requiredParameter: boolean = false, requiredPayload: boolean = false ): BaseParser ``` -------------------------------- ### UserTransformer Constructor Source: https://tagscript.js.org/api/plugins/classes/UserTransformer Initializes a new instance of the UserTransformer class. It requires a 'base' User object and optionally accepts 'safeValues'. This constructor inherits from the BaseTransformer. ```typescript new UserTransformer(base: User, safeValues?: SafeValues): UserTransformer ``` -------------------------------- ### FiftyFiftyParser Class Definition (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/FiftyFiftyParser Defines the FiftyFiftyParser class, which inherits from BaseParser and implements IParser. It features a constructor and a 'parse' method that returns a string or null based on a 50% probability. ```typescript class FiftyFiftyParser extends BaseParser implements IParser { constructor(); parse(ctx: Context): null | string; } ``` -------------------------------- ### Constructor for RequiredParser (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/RequiredParser This code illustrates the constructor for the RequiredParser class. It is defined in tagscript-plugin-discord/src/lib/Parsers/AllowDeny.ts and returns an instance of RequiredParser. This is a basic initialization for the parser. ```typescript new RequiredParser(): RequiredParser ``` -------------------------------- ### Interpreter Class Methods (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/Interpreter Provides methods for managing and executing TagScript code. 'addParsers' and 'setParsers' allow dynamic modification of the parser configuration, while 'run' is the primary method for processing TagScript messages. ```typescript addParsers(...parsers: IParser[]): void setParsers(...parsers: IParser[]): void ``` ```typescript run(message: string, seedVariables?: object, charLimit?: null | number, tagLimit?: number = 2_000, parenType?: ParenType = ParenType.Both, keyValues?: IKeyValues = {}): Promise ``` -------------------------------- ### DateFormatParser Constructor Source: https://tagscript.js.org/api/plugins/classes/DateFormatParser Initializes a new instance of the DateFormatParser class. This constructor is inherited from the BaseParser class. ```typescript new DateFormatParser(): DateFormatParser ``` -------------------------------- ### IfStatementParser Constructor - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/IfStatementParser Initializes a new instance of the IfStatementParser class. This constructor is inherited from BaseParser and sets up the parser's internal state. ```typescript new IfStatementParser() ``` -------------------------------- ### IParser Interface Source: https://tagscript.js.org/api/tagscript/interfaces/IParser The IParser interface defines the contract for creating parsers in TagScript. Parsers are responsible for interpreting tags and returning appropriate values or determining if they can handle a given tag. ```APIDOC ## Interface: IParser ### Description Parsers are used to parse a tag and return a value based on the tag. ### Properties #### `parse(ctx)` ##### Description Parses the given tag. ##### Method Signature `parse` : (`ctx`) => `Awaitable`<`null` | `string`> ##### Parameters - **ctx** (`Context`) - The context of the tag. ##### Returns `Awaitable`<`null` | `string`> - The parsed value or null. #### `willAccept(ctx)` ##### Description Determines whether the parser can handle the given tag. ##### Method Signature `willAccept` : (`ctx`) => `Awaitable`<`boolean`> ##### Parameters - **ctx** (`Context`) - The context of the tag. ##### Returns `Awaitable`<`boolean`> - True if the parser can accept the tag, false otherwise. ### Defined In `interfaces/index.ts:19` ``` -------------------------------- ### StopParser Constructor (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/StopParser Initializes a new instance of the StopParser class. This constructor is inherited from the BaseParser class and sets up the parser's properties. ```TypeScript new StopParser() ``` -------------------------------- ### Instantiate SafeObjectTransformer Source: https://tagscript.js.org/api/tagscript/classes/SafeObjectTransformer Creates a new instance of SafeObjectTransformer. It takes an object as input and returns a SafeObjectTransformer instance. The input object can be a string or a Record of unknown type. ```typescript new SafeObjectTransformer(obj: string | Record) ``` -------------------------------- ### SliceParser Constructor (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/SliceParser The constructor for the SliceParser class. It initializes a new instance of SliceParser, inheriting from the BaseParser constructor. ```typescript new SliceParser(): SliceParser ``` -------------------------------- ### GuildTransformer Constructor Source: https://tagscript.js.org/api/plugins/classes/GuildTransformer Initializes a new instance of the GuildTransformer class. It accepts base Guild object and optional safe values. Inherits from BaseTransformer. ```typescript new GuildTransformer(base: Guild, safeValues?: SafeValues): GuildTransformer ``` -------------------------------- ### UrlEncodeParser: Encode String to URL Format (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/UrlEncodeParser This class, UrlEncodeParser, encodes a given string into a properly formatted URL. Non-URL compliant characters are replaced. An option exists to replace spaces with '+' instead of '%20'. It extends BaseParser and implements IParser. ```TypeScript class UrlEncodeParser extends BaseParser implements IParser { // ... (constructor, properties, methods) parse(ctx: Context): string { // Implementation to encode string to URL format // Replace spaces with '+' if applicable return ""; // Placeholder } } ``` -------------------------------- ### mapOptions() Function Signature - TypeScript Source: https://tagscript.js.org/api/plugins/functions/mapOptions This snippet shows the TypeScript signature for the mapOptions() function. It takes options, transformers, and an optional prefix as arguments and returns void. The function is defined within the TagScript Discord plugin. ```typescript mapOptions(options: readonly CommandInteractionOption[], transformers: Record, prefix: string = ''): void; ``` -------------------------------- ### Lexer Class Properties Source: https://tagscript.js.org/api/tagscript/classes/Lexer Provides access to the properties of a Lexer instance. ```APIDOC ## Lexer Properties ### Description Provides access to the properties of a Lexer instance. ### Properties #### declaration - **declaration** (`string` | `null`) - Represents the declaration part of the Tag. #### parameter - **parameter** (`string` | `null`) - Represents the parameter part of the Tag. #### payload - **payload** (`string` | `null`) - Represents the payload part of the Tag. ### Example Usage ```javascript const lexer = new Lexer("example"); console.log(lexer.declaration); console.log(lexer.parameter); console.log(lexer.payload); ``` ``` -------------------------------- ### ChannelTransformer Constructor (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/ChannelTransformer Initializes a new ChannelTransformer instance. It takes a base GuildChannel object and optional safe values for transformation. This constructor is inherited from the BaseTransformer class. ```typescript new ChannelTransformer(base: GuildChannel, safeValues?: SafeValues = {}) ``` -------------------------------- ### IncludesParser Constructor Source: https://tagscript.js.org/api/tagscript/classes/IncludesParser Initializes a new instance of the IncludesParser class. This constructor is inherited from the BaseParser class. ```typescript new IncludesParser(): IncludesParser ``` -------------------------------- ### IfStatementParser Usage (CommonJS) Source: https://tagscript.js.org/tagscript/parsers/if-statement Illustrates the usage of the IfStatementParser within a CommonJS module system. This is typical in Node.js environments where modules are required. ```javascript const IfStatementParser = require("./IfStatementParser") const parser = new IfStatementParser() const message = parser.parse("{if a == a|Hello|World}") console.log(message) // Output: Hello ``` -------------------------------- ### FiftyFiftyParser.parse() Method (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/FiftyFiftyParser The parse method for FiftyFiftyParser, responsible for processing the tag context. It has a 50% chance of returning the payload and a 50% chance of returning an empty string. The return type is a string or null. ```typescript parse(ctx: Context): null | string { // Implementation details for 50% chance return return Math.random() < 0.5 ? ctx.payload : null; } ``` -------------------------------- ### FilesParser willAccept Method (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/FilesParser Determines if the FilesParser will accept the given context. This method is part of the IParser interface and is used to validate if a tag can be processed by this parser. It takes a context object and returns a boolean. ```typescript willAccept(ctx): boolean ``` -------------------------------- ### SilentParser Constructor in TypeScript Source: https://tagscript.js.org/api/plugins/classes/SilentParser Initializes a new instance of the SilentParser class. This constructor is inherited from the BaseParser class and is responsible for setting up the parser's internal state. ```typescript new SilentParser(): SilentParser ``` -------------------------------- ### UnionStatementParser Constructor (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/UnionStatementParser Initializes a new instance of the UnionStatementParser. This parser is designed to check if any of the provided expressions within a TagScript are true. It extends the BaseParser class and implements the IParser interface. ```TypeScript new UnionStatementParser(): UnionStatementParser ``` -------------------------------- ### IntegerTransformer Constructor - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/IntegerTransformer Initializes a new IntegerTransformer instance. It accepts an integer or bigint as input to set the initial value of the transformer. No external dependencies are required for this constructor. ```typescript new IntegerTransformer(int: number | bigint): IntegerTransformer ``` -------------------------------- ### StringTransformer Constructor (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/StringTransformer Initializes a new instance of the StringTransformer class. It takes the string to transform and an optional boolean to escape the string. Defaults to not escaping. ```typescript new StringTransformer(str: string, escape?: boolean): StringTransformer ``` -------------------------------- ### RequiredParser Class Definition and Methods (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/RequiredParser This snippet shows the TypeScript definition for the RequiredParser class, including its constructor, properties like acceptedNames, requiredParameter, and requiredPayload, and methods such as parse(), toJSON(), and willAccept(). It details the types and return values for each. ```typescript class RequiredParser implements IParser { protected acceptedNames: string[]; protected requiredParameter: boolean; protected requiredPayload: boolean; constructor(); parse(ctx: Context): null | ""; toJSON(): object; willAccept(ctx: Context): boolean; } ``` -------------------------------- ### LooseVarsParser.willAccept() Method - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/LooseVarsParser Checks if the parser can handle the given tag. This method returns a boolean value indicating acceptance. It is an implementation of the IParser.willAccept method. ```typescript willAccept(): boolean ``` -------------------------------- ### InteractionTransformer Constructor (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/InteractionTransformer Initializes a new instance of the InteractionTransformer class. It requires a base CommandInteraction object and optionally accepts safeValues for configuration. This constructor is inherited from the BaseTransformer class. ```typescript new InteractionTransformer(base: CommandInteraction, safeValues?: SafeValues>) ``` -------------------------------- ### FunctionTransformer Class Constructor Source: https://tagscript.js.org/api/tagscript/classes/FunctionTransformer Initializes a new instance of the FunctionTransformer class. It requires a TransformerFunction to define how values are transformed based on the tag at runtime. ```typescript new FunctionTransformer(fn: TransformerFunction): FunctionTransformer ``` -------------------------------- ### BreakParser willAccept() Method (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/BreakParser The willAccept method determines if the BreakParser can handle a given tag context. It's part of the IParser interface implementation. ```typescript /** * Checks if the parser can handle the given tag. * @param ctx The context of the tag. * @returns True if the parser accepts the tag, false otherwise. */ willAccept(ctx: Context): boolean { // Implementation to check tag acceptance // ... return false; // Placeholder return } ``` -------------------------------- ### DateFormatParser.willAccept() Method Source: https://tagscript.js.org/api/plugins/classes/DateFormatParser Determines if the DateFormatParser will accept the given context. This method implements the willAccept functionality from the IParser interface. ```typescript willAccept(ctx: Context): boolean ``` -------------------------------- ### IfStatementParser Usage (ESM) Source: https://tagscript.js.org/tagscript/parsers/if-statement Demonstrates how to use the IfStatementParser in an ECMAScript Module (ESM) environment. This involves importing the parser and utilizing it to conditionally render messages based on expressions. ```javascript import IfStatementParser from "./IfStatementParser" const parser = new IfStatementParser() const message = parser.parse("{if a == a|Hello|World}") console.log(message) // Output: Hello ``` -------------------------------- ### RoleTransformer Constructor Source: https://tagscript.js.org/api/plugins/classes/RoleTransformer Initializes a new instance of the RoleTransformer class. It requires a 'base' Role object and optionally accepts 'safeValues'. This constructor is inherited from the BaseTransformer class. ```typescript new RoleTransformer(base: Role, safeValues?: SafeValues = {}): RoleTransformer ``` -------------------------------- ### DeleteParser.willAccept() Method (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/DeleteParser The willAccept method checks if the DeleteParser can handle the given context. It returns a boolean value, indicating whether the parser should be used for the provided context. This is part of the IParser interface. ```typescript willAccept(ctx: Context): boolean; // Implementation details would be within the Delete.ts file. ``` -------------------------------- ### Node Properties - TypeScript Source: https://tagscript.js.org/api/tagscript/classes/Node Defines the properties of a Node object: 'coordinates' (a tuple of two numbers), 'output' (a string or null), and 'tag' (a Lexer instance or null). These properties hold the essential data associated with a bracketed tag. ```typescript coordinates: [number, number] output: null | string tag: null | Lexer ``` -------------------------------- ### EmbedParser: Parse Tag Context Source: https://tagscript.js.org/api/plugins/classes/EmbedParser The main parse method for the EmbedParser class. It takes a Context object as input and returns a Promise resolving to a string, which represents the parsed embed tag content. This method is part of the IParser interface implementation. ```typescript parse(ctx: Context): Promise ``` -------------------------------- ### Class: SilentParser Source: https://tagscript.js.org/api/plugins/classes/SilentParser The SilentParser class is used to silence the output of commands within the TagScript framework. It extends BaseParser and implements IParser. ```APIDOC ## Class: SilentParser ### Description Silence the used command outputs. Devs need to check for this property in Response.actions and if true, don't output of the command used. ### Extends * `BaseParser` ### Implements * `IParser` ## Constructors ### Constructor `new SilentParser()` #### Returns `SilentParser` #### Overrides `BaseParser.constructor` ## Properties ### acceptedNames `protected acceptedNames: string[]` Defined in: tagscript/dist/index.d.ts:381 #### Inherited from `BaseParser.acceptedNames` ### requiredParameter `protected requiredParameter: boolean` Defined in: tagscript/dist/index.d.ts:382 #### Inherited from `BaseParser.requiredParameter` ### requiredPayload `protected requiredPayload: boolean` Defined in: tagscript/dist/index.d.ts:383 #### Inherited from `BaseParser.requiredPayload` ## Methods ### parse() `parse(ctx): string` Parses the given tag. #### Parameters ##### ctx `Context` - The context of the tag. #### Returns `string` #### Implementation of `IParser.parse` ### toJSON() `toJSON(): object` #### Returns `object` * `acceptedNames` (string[]) * `requiredParameter` (boolean) * `requiredPayload` (boolean) #### Inherited from `BaseParser.toJSON` ### willAccept() `willAccept(ctx): boolean` #### Parameters ##### ctx `Context` #### Returns `boolean` #### Implementation of `IParser.willAccept` #### Inherited from `BaseParser.willAccept` ``` -------------------------------- ### Set Values for Response in TypeScript Source: https://tagscript.js.org/api/tagscript/classes/Response Illustrates the use of the `setValues` method on a Response object. This method updates the response with new 'output' and 'raw' string values. It returns the updated Response object, allowing for method chaining. ```TypeScript import { Response } from "./Interpreter/Response"; // Assume 'response' is an existing Response object let response = new Response({}, {}); const newOutput = "Processed message"; const newRaw = "[tag]original message[/tag]"; response = response.setValues(newOutput, newRaw); console.log(response.body); // "Processed message" console.log(response.raw); // "[tag]original message[/tag]" ``` -------------------------------- ### RandomParser Class Definition Source: https://tagscript.js.org/api/tagscript/classes/RandomParser Defines the RandomParser class, inheriting from BaseParser and implementing IParser. It is responsible for parsing tags that select a random item from a provided list. ```typescript class RandomParser implements IParser { /** * Pick a random item from a list of strings, split by either `~` or `,`. */ public parse(ctx: Context): string { // Implementation details for parsing... return ""; } public willAccept(ctx: Context): boolean { // Implementation details for acceptance... return false; } } ``` -------------------------------- ### RandomParser parse Method Source: https://tagscript.js.org/api/tagscript/classes/RandomParser The parse method of the RandomParser class. It takes a Context object and returns a string, representing the randomly selected item from the list provided in the tag. ```typescript /** * Parses the given tag to select a random item. * @param ctx The context of the tag. * @returns A randomly selected string from the list. */ parse(ctx: Context): string { // Logic to split the input string by '~' or ',' and pick a random element const items = ctx.content.split(/[~,]/); const randomIndex = Math.floor(Math.random() * items.length); return items[randomIndex]; } ``` -------------------------------- ### Convert Lexer to String in TypeScript Source: https://tagscript.js.org/api/tagscript/classes/Lexer Provides a string representation of the Lexer instance. This method reconstructs the original Tagscript string or a similar representation based on the parsed components. ```typescript import { Lexer } from "./Interpreter/Lexer"; const inputString = "[tag arg=value]payload[/tag]"; const lexer = new Lexer(inputString); const stringRepresentation = lexer.toString(); console.log(stringRepresentation); // Expected: "[tag arg=value]payload[/tag]" ``` -------------------------------- ### IntersectionStatementParser Constructor Source: https://tagscript.js.org/api/tagscript/classes/IntersectionStatementParser Initializes a new instance of the IntersectionStatementParser. This constructor is inherited from the BaseParser class. ```typescript new IntersectionStatementParser(): IntersectionStatementParser ``` -------------------------------- ### BreakParser parse() Method (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/BreakParser The parse method of BreakParser, which takes a context and returns a string. This method implements the core logic for handling break tags within TagScript. ```typescript /** * Parses the given tag. * @param ctx The context of the tag. * @returns The parsed string output. */ parse(ctx: Context): string { // Implementation details for parsing break tags // ... return ""; // Placeholder return } ``` -------------------------------- ### MemberTransformer Constructor - TypeScript Source: https://tagscript.js.org/api/plugins/classes/MemberTransformer Initializes a new instance of the MemberTransformer class. It requires a GuildMember object and optionally accepts safe values for transformation. This class is intended for use with the StrictVarsParser. ```TypeScript new MemberTransformer(base: GuildMember, safeValues?: SafeValues = {}): MemberTransformer ``` -------------------------------- ### Interpreter Class Source: https://tagscript.js.org/api/tagscript/classes/Interpreter Represents the TagScript interpreter, responsible for processing TagScript strings. ```APIDOC ## Class: Interpreter ### Description The TagScript interpreter. ### Constructor **new Interpreter**(...`parsers`): `Interpreter` #### Parameters * **parsers** (`IParser`[]) - The parsers to initialize the interpreter with. #### Returns `Interpreter` - An instance of the Interpreter class. ### Properties * **parsers** (`IParser`[]) - Protected property storing the configured parsers. ### Methods #### addParsers() **addParsers**(...`parsers`): `void` Add more parsers to the interpreter. ##### Parameters * **parsers** (`IParser`[]) - The parsers to add. ##### Returns `void` #### getAcceptors() `protected` **getAcceptors**(`ctx`): `Promise`<`IParser`[]> ##### Parameters * **ctx** (`Context`) - The context for fetching acceptors. ##### Returns `Promise`<`IParser`[]> - A promise that resolves to an array of IParser. #### run() **run**(`message`, `seedVariables`, `charLimit`, `tagLimit`, `parenType`, `keyValues`): `Promise`<`Response`> Processes a given TagScript string. ##### Parameters * **message** (`string`) - The TagScript string that to be processed. * **seedVariables** (object) - A object containing strings to transformer to provide context variables for processing. * **charLimit** (`null` | `number`) - The maximum characters to process. * **tagLimit** (`number` = `2_000`) - The maximum tags to process. * **parenType** (`ParenType` = `ParenType.Both`) - Whether the parameter should be followed after a '.' or use parenthesis or both. * **keyValues** (`IKeyValues` = `{}`) - Additional key value pairs that may be used by parsers during parsing. ##### Returns `Promise`<`Response`> - Response class containing the raw string, processed body, actions and variables. #### setParsers() **setParsers**(...`parsers`): `void` Set new parsers for the interpreter. ##### Parameters * **parsers** (`IParser`[]) - The parsers to set. ##### Returns `void` ``` -------------------------------- ### IParser Interface Definition in TypeScript Source: https://tagscript.js.org/api/tagscript/interfaces/IParser Defines the IParser interface in TypeScript, used for parsing tags within the TagScript system. It specifies the 'parse' and 'willAccept' methods that parsers must implement. ```typescript interface IParser { parse(ctx: Context): Awaitable; willAccept(ctx: Context): Awaitable; } ``` -------------------------------- ### DateFormatParser.parse() Method Source: https://tagscript.js.org/api/plugins/classes/DateFormatParser Parses the given tag within the provided context. This method implements the parse functionality from the IParser interface. ```typescript parse(ctx: Context): null | string ``` -------------------------------- ### Access Lexer Properties in TypeScript Source: https://tagscript.js.org/api/tagscript/classes/Lexer Retrieves the declaration, parameter, and payload from a Lexer instance. These properties represent different parts of the parsed Tagscript input. ```typescript import { Lexer } from "./Interpreter/Lexer"; const inputString = "[tag arg=value]payload[/tag]"; const lexer = new Lexer(inputString); console.log(lexer.declaration); // Expected: "tag" console.log(lexer.parameter); // Expected: "arg=value" console.log(lexer.payload); // Expected: "payload" ``` -------------------------------- ### CooldownParser.willAccept() Method (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/CooldownParser Determines if the CooldownParser should handle the given tag context. It returns a boolean indicating whether the parser is applicable to the current tag. ```typescript willAccept(ctx: Context): boolean; ``` -------------------------------- ### ChannelTransformer toJSON Method (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/ChannelTransformer Serializes the ChannelTransformer instance into a plain JavaScript object containing safe values. This method is inherited from the BaseTransformer class. ```typescript toJSON(): SafeValues ``` -------------------------------- ### FilesParser parse Method (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/FilesParser Parses the given tag context to process file information. This method is crucial for the FilesParser's functionality in the TagScript Discord plugin. It accepts a context object and returns a string. ```typescript parse(ctx): string ``` -------------------------------- ### SilentParser parse() Method in TypeScript Source: https://tagscript.js.org/api/plugins/classes/SilentParser Parses the given tag within the provided context. This method implements the IParser.parse() interface and returns a string representing the parsed output. ```typescript parse(ctx: Context): string ``` -------------------------------- ### Serialize TagScript Context to JSON Source: https://tagscript.js.org/api/tagscript/classes/Context Shows how to convert a TagScript Context object into a JSON-serializable object using the toJSON() method. This is useful for debugging or transmitting context data. ```typescript import { Context } from "Interpreter/Context"; // ... (assuming context is already instantiated as above) const contextJSON = context.toJSON(); console.log(contextJSON); /* Output might look like: { interpreter: Interpreter { ... }, originalMessage: "@command arg1 arg2", response: Response { ... }, tag: Lexer { ... } } */ ``` -------------------------------- ### SliceParser Class Definition (TypeScript) Source: https://tagscript.js.org/api/tagscript/classes/SliceParser Defines the SliceParser class, responsible for parsing the 'slice' tag. It extends BaseParser and implements IParser, providing functionality to extract substrings from a given context. The tag supports aliases like 'slice', 'substr', and 'substring'. ```typescript class SliceParser extends BaseParser implements IParser { protected acceptedNames: string[] = ['slice', 'substr', 'substring']; protected requiredParameter: boolean = true; protected requiredPayload: boolean = false; public parse(ctx: Context): string { // Implementation to parse the slice tag and return a substring // ... return ""; // Placeholder } public willAccept(ctx: Context): boolean { // Implementation to check if the parser accepts the given tag // ... return false; // Placeholder } public toJSON(): object { // Implementation to return JSON representation // ... return {}; // Placeholder } } ``` -------------------------------- ### CooldownParser Class Definition (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/CooldownParser Defines the CooldownParser class, which extends BaseParser and implements IParser. It handles the logic for setting and enforcing cooldowns on tags. Key properties include acceptedNames, requiredParameter, and requiredPayload. The parse method is central to its functionality. ```typescript class CooldownParser implements IParser { protected acceptedNames: string[]; protected requiredParameter: boolean; protected requiredPayload: boolean; constructor(); parse(ctx: Context): string; toJSON(): object; willAccept(ctx: Context): boolean; } ``` -------------------------------- ### DeleteParser.parse() Method (TypeScript) Source: https://tagscript.js.org/api/plugins/classes/DeleteParser The parse method for the DeleteParser class. It takes a Context object as input and is expected to return a string, likely indicating the result or status of the parse operation. This method is part of the IParser interface implementation. ```typescript parse(ctx: Context): string; // Implementation details would be within the Delete.ts file. ```